Przeglądaj źródła

Make threaded log work

Previous two log releated patches tried to solve few problems with
threaded libqb, but introduced regressions when running in daemon mode.

This patch takes bigger hammer and hopefully solves all problems.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Fabio M. Di Nitto <fdinitto@redhat.com>
Jan Friesse 13 lat temu
rodzic
commit
bd30fe3dcd
3 zmienionych plików z 34 dodań i 6 usunięć
  1. 28 5
      exec/logsys.c
  2. 4 1
      exec/main.c
  3. 2 0
      include/corosync/logsys.h

+ 28 - 5
exec/logsys.c

@@ -117,6 +117,8 @@ static void logsys_file_format_get(char* file_format, int buf_len);
 
 
 static char *format_buffer=NULL;
 static char *format_buffer=NULL;
 
 
+static int logsys_thread_started = 0;
+
 static int _logsys_config_subsys_get_unlocked (const char *subsys)
 static int _logsys_config_subsys_get_unlocked (const char *subsys)
 {
 {
 	unsigned int i;
 	unsigned int i;
@@ -230,7 +232,9 @@ static int logsys_config_file_set_unlocked (
 	qb_log_ctl(logsys_loggers[subsysid].target_id,
 	qb_log_ctl(logsys_loggers[subsysid].target_id,
 		   QB_LOG_CONF_ENABLED,
 		   QB_LOG_CONF_ENABLED,
 		   (logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_FILE));
 		   (logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_FILE));
-	qb_log_ctl(logsys_loggers[subsysid].target_id, QB_LOG_CONF_THREADED, QB_TRUE);
+	if (logsys_thread_started) {
+		qb_log_ctl(logsys_loggers[subsysid].target_id, QB_LOG_CONF_THREADED, QB_TRUE);
+	}
 
 
 	return (0);
 	return (0);
 }
 }
@@ -292,7 +296,6 @@ int _logsys_system_setup(
 	int i;
 	int i;
 	int32_t fidx;
 	int32_t fidx;
 	char tempsubsys[LOGSYS_MAX_SUBSYS_NAMELEN];
 	char tempsubsys[LOGSYS_MAX_SUBSYS_NAMELEN];
-	int res;
 
 
 	if ((mainsystem == NULL) ||
 	if ((mainsystem == NULL) ||
 	    (strlen(mainsystem) >= LOGSYS_MAX_SUBSYS_NAMELEN)) {
 	    (strlen(mainsystem) >= LOGSYS_MAX_SUBSYS_NAMELEN)) {
@@ -357,7 +360,6 @@ int _logsys_system_setup(
 	} else {
 	} else {
 		qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
 		qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
 	}
 	}
-	qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_THREADED, QB_TRUE);
 	qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_PRIORITY_BUMP, LOG_INFO - LOG_DEBUG);
 	qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_PRIORITY_BUMP, LOG_INFO - LOG_DEBUG);
 
 
 	qb_log_filter_ctl(QB_LOG_BLACKBOX, QB_LOG_FILTER_ADD,
 	qb_log_filter_ctl(QB_LOG_BLACKBOX, QB_LOG_FILTER_ADD,
@@ -386,11 +388,10 @@ int _logsys_system_setup(
 			_logsys_config_apply_per_subsys(i);
 			_logsys_config_apply_per_subsys(i);
 		}
 		}
 	}
 	}
-	res = qb_log_thread_start();
 
 
 	pthread_mutex_unlock (&logsys_config_mutex);
 	pthread_mutex_unlock (&logsys_config_mutex);
 
 
-	return (res);
+	return (0);
 }
 }
 
 
 
 
@@ -791,3 +792,25 @@ int logsys_priority_id_get (const char *name)
 	}
 	}
 	return (-1);
 	return (-1);
 }
 }
+
+int logsys_thread_start (void)
+{
+	int i;
+	int err;
+
+	err = qb_log_thread_start();
+	if (err != 0) {
+		return (err);
+	}
+
+	qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_THREADED, QB_TRUE);
+	for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
+		if (logsys_loggers[i].target_id > 0) {
+			qb_log_ctl(logsys_loggers[i].target_id, QB_LOG_CONF_THREADED, QB_TRUE);
+		}
+	}
+
+	logsys_thread_started = 1;
+
+	return (0);
+}

+ 4 - 1
exec/main.c

@@ -1172,7 +1172,10 @@ int main (int argc, char **argv, char **envp)
 	if (background) {
 	if (background) {
 		corosync_tty_detach ();
 		corosync_tty_detach ();
 	}
 	}
-	qb_log_thread_start();
+	if (logsys_thread_start() != 0) {
+		log_printf (LOGSYS_LEVEL_ERROR, "Can't initialize log thread");
+		corosync_exit_error (COROSYNC_DONE_LOGCONFIGREAD);
+	}
 
 
 	if ((flock_err = corosync_flock (corosync_lock_file, getpid ())) != COROSYNC_DONE_EXIT) {
 	if ((flock_err = corosync_flock (corosync_lock_file, getpid ())) != COROSYNC_DONE_EXIT) {
 		corosync_exit_error (flock_err);
 		corosync_exit_error (flock_err);

+ 2 - 0
include/corosync/logsys.h

@@ -165,6 +165,8 @@ extern int _logsys_config_subsys_get (
 
 
 extern int _logsys_subsys_create (const char *subsys, const char *filename);
 extern int _logsys_subsys_create (const char *subsys, const char *filename);
 
 
+extern int logsys_thread_start (void);
+
 static int logsys_subsys_id __attribute__((unused)) = LOGSYS_MAX_SUBSYS_COUNT;
 static int logsys_subsys_id __attribute__((unused)) = LOGSYS_MAX_SUBSYS_COUNT;
 
 
 #define LOGSYS_DECLARE_SYSTEM(name,mode,syslog_facility,syslog_priority)\
 #define LOGSYS_DECLARE_SYSTEM(name,mode,syslog_facility,syslog_priority)\