Quellcode durchsuchen

main: Replace COROSYNC_MAIN_CONFIG_FILE

COROSYNC_MAIN_CONFIG_FILE environment variable was quite well hidden
and it was never used by init script. It also makes quite hard to debug
possible problems.

Replace it by -c option.

Also patch makes use of configuration file path as a base for uidgid.d
directory, so it's no longer needed to keep uidgid.d in sysconfdir.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse vor 7 Jahren
Ursprung
Commit
2f9aaefbb7
5 geänderte Dateien mit 67 neuen und 19 gelöschten Zeilen
  1. 33 7
      exec/coroparse.c
  2. 23 3
      exec/main.c
  3. 4 2
      exec/main.h
  4. 7 1
      man/corosync.8
  5. 0 6
      man/corosync_overview.7

+ 33 - 7
exec/coroparse.c

@@ -49,6 +49,7 @@
 #include <errno.h>
 #include <string.h>
 #include <dirent.h>
+#include <libgen.h>
 #include <limits.h>
 #include <stddef.h>
 #include <grp.h>
@@ -1537,18 +1538,39 @@ static int read_uidgid_files_into_icmap(
 	icmap_map_t config_map)
 {
 	FILE *fp;
-	const char *dirname;
+	char *dirname_res;
 	DIR *dp;
 	struct dirent *dirent;
 	char filename[PATH_MAX + FILENAME_MAX + 1];
+	char uidgid_dirname[PATH_MAX + FILENAME_MAX + 1];
 	int res = 0;
 	struct stat stat_buf;
 	enum main_cp_cb_data_state state = MAIN_CP_CB_DATA_STATE_NORMAL;
 	char key_name[ICMAP_KEYNAME_MAXLEN];
 	int line_no;
 
-	dirname = COROSYSCONFDIR "/uidgid.d";
-	dp = opendir (dirname);
+	/*
+	 * Build uidgid directory based on corosync.conf file location
+	 */
+	res = snprintf(filename, sizeof(filename), "%s",
+	    corosync_get_config_file());
+	if (res >= sizeof(filename)) {
+		*error_string = "uidgid.d path too long";
+
+		return (-1);
+	}
+
+	dirname_res = dirname(filename);
+
+	res = snprintf(uidgid_dirname, sizeof(uidgid_dirname), "%s/%s",
+	    dirname_res, "uidgid.d");
+	if (res >= sizeof(uidgid_dirname)) {
+		*error_string = "uidgid.d path too long";
+
+		return (-1);
+	}
+
+	dp = opendir (uidgid_dirname);
 
 	if (dp == NULL)
 		return 0;
@@ -1557,7 +1579,13 @@ static int read_uidgid_files_into_icmap(
 		dirent != NULL;
 		dirent = readdir(dp)) {
 
-		snprintf(filename, sizeof (filename), "%s/%s", dirname, dirent->d_name);
+		res = snprintf(filename, sizeof (filename), "%s/%s", uidgid_dirname, dirent->d_name);
+		if (res >= sizeof(filename)) {
+			res = -1;
+			*error_string = "uidgid.d dirname path too long";
+
+			goto error_exit;
+		}
 		res = stat (filename, &stat_buf);
 		if (res == 0 && S_ISREG(stat_buf.st_mode)) {
 
@@ -1598,9 +1626,7 @@ static int read_config_file_into_icmap(
 	enum main_cp_cb_data_state state = MAIN_CP_CB_DATA_STATE_NORMAL;
 	int line_no;
 
-	filename = getenv ("COROSYNC_MAIN_CONFIG_FILE");
-	if (!filename)
-		filename = COROSYSCONFDIR "/corosync.conf";
+	filename = corosync_get_config_file();
 
 	fp = fopen (filename, "r");
 	if (fp == NULL) {

+ 23 - 3
exec/main.c

@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2002-2006 MontaVista Software, Inc.
- * Copyright (c) 2006-2017 Red Hat, Inc.
+ * Copyright (c) 2006-2018 Red Hat, Inc.
  *
  * All rights reserved.
  *
@@ -167,6 +167,8 @@ static const char *corosync_lock_file = LOCALSTATEDIR"/run/corosync.pid";
 
 static int ip_version = AF_INET;
 
+static char corosync_config_file[PATH_MAX + 1] = COROSYSCONFDIR "/corosync.conf";
+
 qb_loop_t *cs_poll_handle_get (void)
 {
 	return (corosync_poll_handle);
@@ -201,6 +203,12 @@ void corosync_state_dump (void)
 	}
 }
 
+const char *corosync_get_config_file(void)
+{
+
+	return (corosync_config_file);
+}
+
 static void corosync_blackbox_write_to_file (void)
 {
 	char fname[PATH_MAX];
@@ -1217,9 +1225,19 @@ int main (int argc, char **argv, char **envp)
 	background = 1;
 	testonly = 0;
 
-	while ((ch = getopt (argc, argv, "ftv")) != EOF) {
+	while ((ch = getopt (argc, argv, "c:ftv")) != EOF) {
 
 		switch (ch) {
+			case 'c':
+				res = snprintf(corosync_config_file, sizeof(corosync_config_file), "%s", optarg);
+				if (res >= sizeof(corosync_config_file)) {
+					fprintf (stderr, "Config file path too long.\n");
+					syslog (LOGSYS_LEVEL_ERROR, "Config file path too long.");
+
+					logsys_system_fini();
+					return EXIT_FAILURE;
+				}
+				break;
 			case 'f':
 				background = 0;
 				break;
@@ -1236,6 +1254,7 @@ int main (int argc, char **argv, char **envp)
 			default:
 				fprintf(stderr, \
 					"usage:\n"\
+					"        -c     : Corosync config file path.\n"\
 					"        -f     : Start application in foreground.\n"\
 					"        -t     : Test configuration and exit.\n"\
 					"        -v     : Display version and SVN revision of Corosync and exit.\n");
@@ -1255,7 +1274,8 @@ int main (int argc, char **argv, char **envp)
 #endif
 
 	if (icmap_init() != CS_OK) {
-		log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't initialize configuration component.");
+		fprintf (stderr, "Corosync Executive couldn't initialize configuration component.\n");
+		syslog (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't initialize configuration component.");
 		corosync_exit_error (COROSYNC_DONE_ICMAP);
 	}
 	set_icmap_ro_keys_flag();

+ 4 - 2
exec/main.h

@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2002-2006 MontaVista Software, Inc.
- * Copyright (c) 2006-2012 Red Hat, Inc.
+ * Copyright (c) 2006-2018 Red Hat, Inc.
  *
  * All rights reserved.
  *
@@ -122,6 +122,8 @@ extern void cs_ipc_refcnt_dec(void *conn);
 
 extern void cs_ipc_allow_connections(int32_t allow);
 
-int coroparse_configparse (icmap_map_t config_map, const char **error_string);
+extern int coroparse_configparse (icmap_map_t config_map, const char **error_string);
+
+extern const char *corosync_get_config_file(void);
 
 #endif /* MAIN_H_DEFINED */

+ 7 - 1
man/corosync.8

@@ -35,12 +35,18 @@
 .SH NAME
 corosync \- The Corosync Cluster Engine.
 .SH SYNOPSIS
-.B "corosync [\-f] [\-t] [\-v]"
+.B "corosync [\-c config_file] [\-f] [\-t] [\-v]"
 .SH DESCRIPTION
 .B corosync
 Corosync provides clustering infrastructure such as membership, messaging and quorum.
 .SH OPTIONS
 .TP
+.B -c
+This specifies the fully qualified path to the corosync configuration file. Also used
+as a base directory for uidgid files.
+
+The default is /etc/corosync/corosync.conf.
+.TP
 .B -f
 Start application in foreground.
 .TP

+ 0 - 6
man/corosync_overview.7

@@ -147,12 +147,6 @@ in a configuration together so they may communicate.
 The corosync executive process uses four environment variables during startup.
 If these environment variables are not set, defaults will be used.
 
-.TP
-COROSYNC_MAIN_CONFIG_FILE
-This specifies the fully qualified path to the corosync configuration file.
-
-The default is /etc/corosync/corosync.conf.
-
 .TP
 COROSYNC_TOTEM_AUTHKEY_FILE
 This specifies the fully qualified path to the shared key used to