Browse Source

qnetd: Add function to set log target

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Jan Friesse 6 years ago
parent
commit
6cc1388e06
3 changed files with 21 additions and 7 deletions
  1. 1 1
      qdevices/corosync-qnetd.c
  2. 17 5
      qdevices/log.c
  3. 3 1
      qdevices/log.h

+ 1 - 1
qdevices/corosync-qnetd.c

@@ -544,7 +544,7 @@ main(int argc, char * const argv[])
 		log_target |= LOG_TARGET_STDERR;
 	}
 
-	res = log_init(QNETD_PROGRAM_NAME, log_target);
+	res = log_init(QNETD_PROGRAM_NAME, log_target, LOG_DAEMON);
 	if (res == -1) {
 		errx(1, "Can't initialize logging");
 	}

+ 17 - 5
qdevices/log.c

@@ -43,6 +43,7 @@
 static int log_config_target = 0;
 static int log_config_debug = 0;
 static int log_config_priority_bump = 0;
+static int log_config_syslog_facility = 0;
 static char *log_config_ident = NULL;
 
 static const char log_month_str[][4] = {
@@ -67,19 +68,16 @@ static struct log_syslog_prio_to_str_item syslog_prio_to_str_array[] = {
     {-1, NULL}};
 
 int
-log_init(const char *ident, int target)
+log_init(const char *ident, int target, int syslog_facility)
 {
 
-	log_config_target = target;
 	log_config_ident = strdup(ident);
 
 	if (log_config_ident == NULL) {
 		return (-1);
 	}
 
-	if (log_config_target & LOG_TARGET_SYSLOG) {
-		openlog(QNETD_PROGRAM_NAME, LOG_PID, LOG_DAEMON);
-	}
+	log_set_target(target, syslog_facility);
 
 	return (0);
 }
@@ -168,6 +166,20 @@ log_set_priority_bump(int enabled)
 	log_config_priority_bump = enabled;
 }
 
+void
+log_set_target(int target, int syslog_facility)
+{
+
+	log_close();
+
+	log_config_target = target;
+	log_config_syslog_facility = syslog_facility;
+
+	if (log_config_target & LOG_TARGET_SYSLOG) {
+		openlog(log_config_ident, LOG_PID, log_config_syslog_facility);
+	}
+}
+
 void
 log_msg_decode_error(int ret)
 {

+ 3 - 1
qdevices/log.h

@@ -53,7 +53,7 @@ extern "C" {
 #define log_err(priority, str) log_printf(priority, "%s (%d): %s", \
     str, errno, strerror(errno))
 
-extern int		log_init(const char *ident, int target);
+extern int		log_init(const char *ident, int target, int syslog_facility);
 
 extern void		log_printf(int priority, const char *format, ...)
     __attribute__((__format__(__printf__, 2, 3)));
@@ -67,6 +67,8 @@ extern void		log_set_debug(int enabled);
 
 extern void		log_set_priority_bump(int enabled);
 
+extern void		log_set_target(int target, int syslog_facility);
+
 extern void		log_msg_decode_error(int ret);
 
 #ifdef __cplusplus