Просмотр исходного кода

logsys.h (logsys_format_set): Change return type, adjust param type.

* include/corosync/engine/logsys.h:
* exec/logsys.c (logsys_format_set): Return -1 upon strdup failure.
Change type of param to "const char *".
* exec/logsys.c (logsys_init): Adjust use.
* exec/mainconfig.c (corosync_main_config_read_logging): Adjust uses.

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2009 fd59a12c-fef9-0310-b244-a6a79926bd2f
Jim Meyering 17 лет назад
Родитель
Сommit
a549daedca
3 измененных файлов с 21 добавлено и 11 удалено
  1. 7 2
      exec/logsys.c
  2. 11 6
      exec/mainconfig.c
  3. 3 3
      include/corosync/engine/logsys.h

+ 7 - 2
exec/logsys.c

@@ -916,7 +916,7 @@ int logsys_config_file_set (const char **error_string, const char *file)
 	return (0);
 }
 
-void logsys_format_set (char *format)
+int logsys_format_set (const char *format)
 {
 	pthread_mutex_lock (&logsys_config_mutex);
 
@@ -930,8 +930,12 @@ void logsys_format_set (char *format)
 	} else {
 		format_buffer = strdup("[%6s] %b");
 	}
+	if (format_buffer == NULL) {
+		return -1;
+	}
 
 	pthread_mutex_unlock (&logsys_config_mutex);
+	return 0;
 }
 
 char *logsys_format_get (void)
@@ -1137,7 +1141,8 @@ int logsys_init (
 	logsys_config_mode_set (mode);
 	logsys_config_facility_set (name, facility);
 	logsys_config_file_set (&errstr, file);
-	logsys_format_set (format);
+	if (logsys_format_set (format))
+		return -1;
 	_logsys_rec_init (rec_size);
 	_logsys_wthread_create ();
 	return (0);

+ 11 - 6
exec/mainconfig.c

@@ -195,6 +195,7 @@ int corosync_main_config_read_logging (
 	hdb_handle_t object_find_handle;
 	hdb_handle_t object_find_logsys_handle;
 	char new_format_buffer[PATH_MAX];
+	int err = 0;
 
 	objdb->object_find_create (
 		OBJECT_PARENT_HANDLE,
@@ -236,12 +237,12 @@ int corosync_main_config_read_logging (
 				if (!insert_into_buffer(new_format_buffer,
 						sizeof(new_format_buffer),
 						" %f:%l", "s]")) {
-					logsys_format_set(new_format_buffer);
+					err = logsys_format_set(new_format_buffer);
 				} else
 				if (!insert_into_buffer(new_format_buffer,
 						sizeof(new_format_buffer),
 						"%f:%l", NULL)) {
-					logsys_format_set(new_format_buffer);
+					err = logsys_format_set(new_format_buffer);
 				}
 			} else
 			if (strcmp (value, "off") == 0) {
@@ -255,12 +256,12 @@ int corosync_main_config_read_logging (
 				if (!insert_into_buffer(new_format_buffer,
 						sizeof(new_format_buffer),
 						"%n:", "f:")) {
-					logsys_format_set(new_format_buffer);
+					err = logsys_format_set(new_format_buffer);
 				} else
 				if (!insert_into_buffer(new_format_buffer,
 						sizeof(new_format_buffer),
 						" %n", "s]")) {
-					logsys_format_set(new_format_buffer);
+					err = logsys_format_set(new_format_buffer);
 				}
 			} else
 			if (strcmp (value, "off") == 0) {
@@ -274,7 +275,7 @@ int corosync_main_config_read_logging (
 				if(!insert_into_buffer(new_format_buffer,
 						sizeof(new_format_buffer),
 						"%t ", NULL)) {
-					logsys_format_set(new_format_buffer);
+					err = logsys_format_set(new_format_buffer);
 				}
 			} else
 			if (strcmp (value, "off") == 0) {
@@ -283,6 +284,10 @@ int corosync_main_config_read_logging (
 				goto parse_error;
 			}
 		}
+		if (err) {
+			error_reason = "exhausted virtual memory";
+			goto parse_error;
+		}
 
 		/* free old string on reload */
 		if (main_config->logfile) {
@@ -365,7 +370,7 @@ int corosync_main_config_read_logging (
 				logsys_logger.subsys,
 				logsys_logger.tags,
 				logsys_logger.priority);
-			
+
 		}
 		objdb->object_find_destroy (object_find_logsys_handle);
 	}

+ 3 - 3
include/corosync/engine/logsys.h

@@ -94,8 +94,8 @@ extern void logsys_config_facility_set (
 	const char *name,
 	unsigned int facility);
 
-extern void logsys_format_set (
-	char *format);
+extern int logsys_format_set (
+	const char *format);
 
 extern char *logsys_format_get (void);
 
@@ -182,7 +182,7 @@ __attribute__ ((constructor)) static void logsys_system_init (void)	\
 	logsys_config_mode_set (mode);					\
 	logsys_config_file_set (&error_string, (file));			\
 	logsys_config_facility_set (name, (facility));			\
-	logsys_format_set (format);					\
+	logsys_format_set (format); /* FIXME: assert success? */	\
 	_logsys_rec_init (rec_size);					\
 	_logsys_wthread_create();					\
 }