Prechádzať zdrojové kódy

Fix coroparse to allow white chars before comment

- allows white characters before #
- new function to parse log destinations (remove code duplicity)
- clarify man page


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2642 fd59a12c-fef9-0310-b244-a6a79926bd2f
Jan Friesse 16 rokov pred
rodič
commit
99db356765
3 zmenil súbory, kde vykonal 78 pridanie a 91 odobranie
  1. 12 1
      exec/coroparse.c
  2. 59 81
      exec/mainconfig.c
  3. 7 9
      man/corosync.conf.5

+ 12 - 1
exec/coroparse.c

@@ -115,6 +115,7 @@ static int parse_section(FILE *fp,
 	char line[512];
 	char line[512];
 	int i;
 	int i;
 	char *loc;
 	char *loc;
+	int ignore_line;
 
 
 	while (fgets (line, sizeof (line), fp)) {
 	while (fgets (line, sizeof (line), fp)) {
 		if (strlen(line) > 0) {
 		if (strlen(line) > 0) {
@@ -133,10 +134,20 @@ static int parse_section(FILE *fp,
 				break;
 				break;
 			}
 			}
 		}
 		}
+
+		ignore_line = 1;
+		for (i = 0; i < strlen (line); i++) {
+			if (line[i] != '\t' && line[i] != ' ') {
+				if (line[i] != '#')
+					ignore_line = 0;
+
+				break;
+			}
+		}
 		/*
 		/*
 		 * Clear out comments and empty lines
 		 * Clear out comments and empty lines
 		 */
 		 */
-		if (line[0] == '#' || line[0] == '\0') {
+		if (ignore_line) {
 			continue;
 			continue;
 		}
 		}
 
 

+ 59 - 81
exec/mainconfig.c

@@ -255,6 +255,53 @@ parse_error:
 	return (-1);
 	return (-1);
 }
 }
 
 
+static int corosync_main_config_log_destination_set (
+	struct objdb_iface_ver0 *objdb,
+	hdb_handle_t object_handle,
+	const char *subsys,
+	const char **error_string,
+	const char *objdb_key,
+	unsigned int mode_mask,
+	char deprecated,
+	const char *replacement)
+{
+	static char formatted_error_reason[128];
+	char *value;
+	unsigned int mode;
+
+	if (!objdb_get_string (objdb, object_handle, objdb_key, &value)) {
+		if (deprecated) {
+			log_printf(LOGSYS_LEVEL_WARNING,
+			 "Warning: the %s config paramater has been obsoleted."
+			 " See corosync.conf man page %s directive.",
+			 objdb_key, replacement);
+		}
+
+		if (strcmp (value, "yes") == 0) {
+			mode |= mode_mask;
+			if (logsys_config_mode_set(subsys, mode) < 0) {
+				sprintf (formatted_error_reason, "unable to set mode %s", objdb_key);
+				*error_string = formatted_error_reason;
+				return -1;
+			}
+		} else
+		if (strcmp (value, "no") == 0) {
+			mode &= ~mode_mask;
+			if (logsys_config_mode_set(subsys, mode) < 0) {
+				sprintf (formatted_error_reason, "unable to unset mode %s", objdb_key);
+				*error_string = formatted_error_reason;
+				return -1;
+			}
+		} else {
+			sprintf (formatted_error_reason, "unknown value for %s", objdb_key);
+			*error_string = formatted_error_reason;
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
 static int corosync_main_config_set (
 static int corosync_main_config_set (
 	struct objdb_iface_ver0 *objdb,
 	struct objdb_iface_ver0 *objdb,
 	hdb_handle_t object_handle,
 	hdb_handle_t object_handle,
@@ -287,90 +334,21 @@ static int corosync_main_config_set (
 		goto parse_error;
 		goto parse_error;
 	}
 	}
 
 
-	if (!objdb_get_string (objdb,object_handle, "to_file", &value)) {
-
-		log_printf(LOGSYS_LEVEL_WARNING,
-		 "Warning: the to_file config paramater has been obsoleted."
-		 " See corosync.conf man page to_logfile directive.");
-
-		if (strcmp (value, "yes") == 0) {
-			mode |= LOGSYS_MODE_OUTPUT_FILE;
-			if (logsys_config_mode_set(subsys, mode) < 0) {
-				error_reason = "unable to set mode to_file";
-				goto parse_error;
-			}
-		} else
-		if (strcmp (value, "no") == 0) {
-			mode &= ~LOGSYS_MODE_OUTPUT_FILE;
-			if (logsys_config_mode_set(subsys, mode) < 0) {
-				error_reason = "unable to unset mode to_file";
-				goto parse_error;
-			}
-		} else {
-			error_reason = "unknown value for to_file";
-			goto parse_error;
-		}
-	}
+	if (corosync_main_config_log_destination_set (objdb, object_handle, subsys, &error_reason,
+	    "to_logfile", LOGSYS_MODE_OUTPUT_FILE, 0, NULL) != 0)
+		goto parse_error;
 
 
-	if (!objdb_get_string (objdb,object_handle, "to_logfile", &value)) {
-		if (strcmp (value, "yes") == 0) {
-			mode |= LOGSYS_MODE_OUTPUT_FILE;
-			if (logsys_config_mode_set(subsys, mode) < 0) {
-				error_reason = "unable to set mode to_logfile";
-				goto parse_error;
-			}
-		} else
-		if (strcmp (value, "no") == 0) {
-			mode &= ~LOGSYS_MODE_OUTPUT_FILE;
-			if (logsys_config_mode_set(subsys, mode) < 0) {
-				error_reason = "unable to unset mode to_logfile";
-				goto parse_error;
-			}
-		} else {
-			error_reason = "unknown value for to_logfile";
-			goto parse_error;
-		}
-	}
+	if (corosync_main_config_log_destination_set (objdb, object_handle, subsys, &error_reason,
+	    "to_stderr", LOGSYS_MODE_OUTPUT_STDERR, 0, NULL) != 0)
+		goto parse_error;
 
 
-	if (!objdb_get_string (objdb,object_handle, "to_syslog", &value)) {
-		if (strcmp (value, "yes") == 0) {
-			mode |= LOGSYS_MODE_OUTPUT_SYSLOG;
-			if (logsys_config_mode_set(subsys, mode) < 0) {
-				error_reason = "unable to set mode to_syslog";
-				goto parse_error;
-			}
-		} else
-		if (strcmp (value, "no") == 0) {
-			mode &= ~LOGSYS_MODE_OUTPUT_SYSLOG;
-			if (logsys_config_mode_set(subsys, mode) < 0) {
-				error_reason = "unable to unset mode to_syslog";
-				goto parse_error;
-			}
-		} else {
-			error_reason = "unknown value for to_syslog";
-			goto parse_error;
-		}
-	}
+	if (corosync_main_config_log_destination_set (objdb, object_handle, subsys, &error_reason,
+	    "to_syslog", LOGSYS_MODE_OUTPUT_SYSLOG, 0, NULL) != 0)
+		goto parse_error;
 
 
-	if (!objdb_get_string (objdb,object_handle, "to_stderr", &value)) {
-		if (strcmp (value, "yes") == 0) {
-			mode |= LOGSYS_MODE_OUTPUT_STDERR;
-			if (logsys_config_mode_set(subsys, mode) < 0) {
-				error_reason = "unable to set mode to_stderr";
-				goto parse_error;
-			}
-		} else
-		if (strcmp (value, "no") == 0) {
-			mode &= ~LOGSYS_MODE_OUTPUT_STDERR;
-			if (logsys_config_mode_set(subsys, mode) < 0) {
-				error_reason = "unable to unset mode to_stderr";
-				goto parse_error;
-			}
-		} else {
-			error_reason = "unknown value for to_syslog";
-			goto parse_error;
-		}
-	}
+	if (corosync_main_config_log_destination_set (objdb, object_handle, subsys, &error_reason,
+	    "to_file", LOGSYS_MODE_OUTPUT_FILE, 1, "to_logfile") != 0)
+		goto parse_error;
 
 
 	if (!objdb_get_string (objdb,object_handle, "syslog_facility", &value)) {
 	if (!objdb_get_string (objdb,object_handle, "syslog_facility", &value)) {
 		int syslog_facility;
 		int syslog_facility;

+ 7 - 9
man/corosync.conf.5

@@ -41,11 +41,9 @@ corosync.conf - corosync executive configuration file
 
 
 .SH DESCRIPTION
 .SH DESCRIPTION
 The corosync.conf instructs the corosync executive about various parameters
 The corosync.conf instructs the corosync executive about various parameters
-needed to control the corosync executive.  The configuration file consists of
-bracketed top level directives.  The possible directive choices are
-.IR "totem  { } , logging { }.  It is also possible to specify the top level
-parameter compatibility.
- These directives are described below.
+needed to control the corosync executive.  Empty lines and lines starting with
+# character are ignored.  The configuration file consists of bracketed top level
+directives.  The possible directive choices are:
 
 
 .TP
 .TP
 totem { }
 totem { }
@@ -59,12 +57,12 @@ This top level directive contains configuration options for the event service.
 
 
 .PP
 .PP
 .PP
 .PP
-The
-.B compatibility
-directive indicates the level of compatibility requested by the user.  The
+It is also possible to specify the top level parameter
+.B compatibility.
+This directive indicates the level of compatibility requested by the user.  The
 option whitetank can be specified to remain backward compatable with
 option whitetank can be specified to remain backward compatable with
 openais-0.80.z.  The option none can be specified to only be compatable
 openais-0.80.z.  The option none can be specified to only be compatable
-with corsoync-1.Y.Z.  Extra processing during configuration changes is
+with corosync-1.Y.Z.  Extra processing during configuration changes is
 required to remain backward compatable.
 required to remain backward compatable.
 
 
 The default is whitetank. (backwards compatibility)
 The default is whitetank. (backwards compatibility)