]> git.proxmox.com Git - mirror_corosync-qdevice.git/commitdiff
qnetd: Add function to set log target
authorJan Friesse <jfriesse@redhat.com>
Mon, 12 Aug 2019 12:04:04 +0000 (14:04 +0200)
committerJan Friesse <jfriesse@redhat.com>
Mon, 12 Aug 2019 15:47:39 +0000 (17:47 +0200)
Signed-off-by: Jan Friesse <jfriesse@redhat.com>
qdevices/corosync-qnetd.c
qdevices/log.c
qdevices/log.h

index b9d29548b38bdabf74ad0cfe3e0ac1942ce01b17..379ae27169936c757d4acf2c4b7da3d335f6d946 100644 (file)
@@ -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");
        }
index 47ca167385e497fdda1402795a81a9379236bf06..e08790e6b8ca3f8356ee049734a17a34d1eb5be3 100644 (file)
@@ -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)
 {
index c376a70223bb8edd73cfe74da9f4469c05952e2a..dc43c9fb38e37337a4ecb4478f6266eadfcb6b81 100644 (file)
@@ -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