Added -l option for clixon_backend for directing syslog to stderr or stdout i\

f running in foreground
This commit is contained in:
Olof Hagsand 2018-07-24 17:59:17 +02:00
parent f1f0dafcbc
commit 666d74bf1b
2 changed files with 24 additions and 2 deletions

View file

@ -8,6 +8,7 @@
### Minor changes ### Minor changes
* Obsoleted COMPAT_CLIV and COMPAT_XSL that were optional in 3.7 * Obsoleted COMPAT_CLIV and COMPAT_XSL that were optional in 3.7
* Added -l option for clixon_backend for directing syslog to stderr or stdout if running in foreground
### Corrected Bugs ### Corrected Bugs

View file

@ -73,7 +73,7 @@
#include "backend_handle.h" #include "backend_handle.h"
/* Command line options to be passed to getopt(3) */ /* Command line options to be passed to getopt(3) */
#define BACKEND_OPTS "hD:f:d:b:Fzu:P:1s:c:g:y:x:" /* substitute s: for IRCc:r */ #define BACKEND_OPTS "hD:f:d:b:Fzu:P:1s:c:g:l:y:x:" /* substitute s: for IRCc:r */
/*! Terminate. Cannot use h after this */ /*! Terminate. Cannot use h after this */
static int static int
@ -140,6 +140,7 @@ usage(clicon_handle h,
" -s <mode>\tSpecify backend startup mode: none|startup|running|init (replaces -IRCr\n" " -s <mode>\tSpecify backend startup mode: none|startup|running|init (replaces -IRCr\n"
" -c <file>\tLoad extra xml configuration, but don't commit.\n" " -c <file>\tLoad extra xml configuration, but don't commit.\n"
" -g <group>\tClient membership required to this group (default: %s)\n" " -g <group>\tClient membership required to this group (default: %s)\n"
" -l <s|e|o> \tLog on (s)yslog, std(e)rr or std(o)ut (stderr is default) Only valid if -F, if background syslog is on syslog.\n"
" -y <file>\tOverride yang spec file (dont include .yang suffix)\n" " -y <file>\tOverride yang spec file (dont include .yang suffix)\n"
" -x <plugin>\tXMLDB plugin\n", " -x <plugin>\tXMLDB plugin\n",
argv0, argv0,
@ -553,6 +554,7 @@ main(int argc,
int xml_pretty; int xml_pretty;
char *xml_format; char *xml_format;
char *nacm_mode; char *nacm_mode;
int logdst = CLICON_LOG_SYSLOG;
/* In the startup, logs to stderr & syslog and debug flag set later */ /* In the startup, logs to stderr & syslog and debug flag set later */
clicon_log_init(__PROGRAM__, LOG_INFO, CLICON_LOG_STDERR|CLICON_LOG_SYSLOG); clicon_log_init(__PROGRAM__, LOG_INFO, CLICON_LOG_STDERR|CLICON_LOG_SYSLOG);
@ -589,6 +591,21 @@ main(int argc,
usage(h, argv[0]); usage(h, argv[0]);
clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg); clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
break; break;
case 'l': /* Log destination: s|e|o */
switch (optarg[0]){
case 's':
logdst = CLICON_LOG_SYSLOG;
break;
case 'e':
logdst = CLICON_LOG_STDERR;
break;
case 'o':
logdst = CLICON_LOG_STDOUT;
break;
default:
usage(h, argv[0]);
}
break;
} }
/* /*
* Here we have the debug flag settings, use that. * Here we have the debug flag settings, use that.
@ -597,7 +614,7 @@ main(int argc,
* XXX: if started in a start-daemon script, there will be irritating * XXX: if started in a start-daemon script, there will be irritating
* double syslogs until fork below. * double syslogs until fork below.
*/ */
clicon_log_init(__PROGRAM__, debug?LOG_DEBUG:LOG_INFO, CLICON_LOG_SYSLOG); clicon_log_init(__PROGRAM__, debug?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(debug, NULL); clicon_debug_init(debug, NULL);
/* Find and read configfile */ /* Find and read configfile */
@ -668,6 +685,8 @@ main(int argc,
clicon_option_str_set(h, "CLICON_XMLDB_PLUGIN", optarg); clicon_option_str_set(h, "CLICON_XMLDB_PLUGIN", optarg);
break; break;
} }
case 'l' :
break;
default: default:
usage(h, argv[0]); usage(h, argv[0]);
break; break;
@ -676,6 +695,8 @@ main(int argc,
argc -= optind; argc -= optind;
argv += optind; argv += optind;
clicon_log_init(__PROGRAM__, debug?LOG_DEBUG:LOG_INFO, logdst);
/* Defer: Wait to the last minute to print help message */ /* Defer: Wait to the last minute to print help message */
if (help) if (help)
usage(h, argv[0]); usage(h, argv[0]);