order backend cmd options; open syslog only if syslog is enabled

This commit is contained in:
Olof Hagsand 2018-08-01 07:13:33 +00:00
parent 0355942740
commit 656800cdd3
2 changed files with 18 additions and 15 deletions

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:a:P:1s:c:g:l:y:x:" /* substitute s: for IRCc:r */ #define BACKEND_OPTS "hD:f:l:d:b:Fza:u:P:1s:c:g:y:x:" /* substitute s: for IRCc:r */
#define BACKEND_LOGFILE "/usr/local/var/clixon_backend.log" #define BACKEND_LOGFILE "/usr/local/var/clixon_backend.log"
@ -132,19 +132,20 @@ usage(clicon_handle h,
"where options are\n" "where options are\n"
" -h\t\tHelp\n" " -h\t\tHelp\n"
" -D <level>\tDebug level\n" " -D <level>\tDebug level\n"
" -f <file>\tCLICON config file (mandatory)\n" " -f <file>\tCLICON config file\n"
" -l <s|e|o|f<file>> \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"
" -d <dir>\tSpecify backend plugin directory (default: %s)\n" " -d <dir>\tSpecify backend plugin directory (default: %s)\n"
" -b <dir>\tSpecify XMLDB database directory\n" " -b <dir>\tSpecify XMLDB database directory\n"
" -z\t\tKill other config daemon and exit\n"
" -F\t\tRun in foreground, do not run as daemon\n" " -F\t\tRun in foreground, do not run as daemon\n"
" -1\t\tRun once and then quit (dont wait for events)\n" " -z\t\tKill other config daemon and exit\n"
" -a UNIX|IPv4|IPv6\tInternal backend socket family\n" " -a UNIX|IPv4|IPv6\tInternal backend socket family\n"
" -u <path|addr>\tInternal socket domain path or IP addr (see -a)(default: %s)\n" " -u <path|addr>\tInternal socket domain path or IP addr (see -a)(default: %s)\n"
" -P <file>\tPid filename (default: %s)\n" " -P <file>\tPid filename (default: %s)\n"
" -1\t\tRun once and then quit (dont wait for events)\n"
" -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|f<file>> \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,
@ -577,7 +578,6 @@ main(int argc,
optind = 1; optind = 1;
while ((c = getopt(argc, argv, BACKEND_OPTS)) != -1) while ((c = getopt(argc, argv, BACKEND_OPTS)) != -1)
switch (c) { switch (c) {
case '?':
case 'h': case 'h':
/* Defer the call to usage() to later. Reason is that for helpful /* Defer the call to usage() to later. Reason is that for helpful
text messages, default dirs, etc, are not set until later. text messages, default dirs, etc, are not set until later.
@ -631,8 +631,10 @@ main(int argc,
optind = 1; optind = 1;
while ((c = getopt(argc, argv, BACKEND_OPTS)) != -1) while ((c = getopt(argc, argv, BACKEND_OPTS)) != -1)
switch (c) { switch (c) {
case 'h' : /* help */
case 'D' : /* debug */ case 'D' : /* debug */
case 'f': /* config file */ case 'f': /* config file */
case 'l' :
break; /* see above */ break; /* see above */
case 'd': /* Plugin directory */ case 'd': /* Plugin directory */
if (!strlen(optarg)) if (!strlen(optarg))
@ -647,9 +649,6 @@ main(int argc,
case 'F' : /* foreground */ case 'F' : /* foreground */
foreground = 1; foreground = 1;
break; break;
case '1' : /* Quit after reading database once - dont wait for events */
once = 1;
break;
case 'z': /* Zap other process */ case 'z': /* Zap other process */
zap++; zap++;
break; break;
@ -664,6 +663,9 @@ main(int argc,
case 'P': /* pidfile */ case 'P': /* pidfile */
clicon_option_str_set(h, "CLICON_BACKEND_PIDFILE", optarg); clicon_option_str_set(h, "CLICON_BACKEND_PIDFILE", optarg);
break; break;
case '1' : /* Quit after reading database once - dont wait for events */
once = 1;
break;
case 's' : /* startup mode */ case 's' : /* startup mode */
clicon_option_str_set(h, "CLICON_STARTUP_MODE", optarg); clicon_option_str_set(h, "CLICON_STARTUP_MODE", optarg);
if (clicon_startup_mode(h) < 0){ if (clicon_startup_mode(h) < 0){
@ -685,8 +687,6 @@ 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;

View file

@ -89,11 +89,14 @@ clicon_log_init(char *ident,
int upto, int upto,
int flags) int flags)
{ {
if (setlogmask(LOG_UPTO(upto)) < 0)
/* Cant syslog here */
fprintf(stderr, "%s: setlogmask: %s\n", __FUNCTION__, strerror(errno));
_logflags = flags; _logflags = flags;
openlog(ident, LOG_PID, LOG_USER); /* LOG_PUSER is achieved by direct stderr logs in clicon_log */ if (flags & CLICON_LOG_SYSLOG){
if (setlogmask(LOG_UPTO(upto)) < 0)
/* Cant syslog here */
fprintf(stderr, "%s: setlogmask: %s\n", __FUNCTION__, strerror(errno));
openlog(ident, LOG_PID, LOG_USER); /* LOG_PUSER is achieved by direct stderr logs in clicon_log */
}
return 0; return 0;
} }