main: add option to specify log file

Add -l option to log to a file instead of syslog or terminal.
This commit is contained in:
Miroslav Lichvar 2017-05-24 16:03:39 +02:00
parent 6cbeb107db
commit a1cbd4eb82
2 changed files with 11 additions and 2 deletions

View file

@ -66,6 +66,10 @@ and all messages will be sent to the terminal instead of to syslog. When
*chronyd* was compiled with debugging support, this option can be used twice to
print also debugging messages.
*-l* _file_::
This option specifies a file which should be used for logging instead of syslog
or terminal.
*-q*::
When run in this mode, *chronyd* will set the system clock once and exit. It
will not detach from the terminal.

9
main.c
View file

@ -370,7 +370,7 @@ int main
{
const char *conf_file = DEFAULT_CONF_FILE;
const char *progname = argv[0];
char *user = NULL;
char *user = NULL, *log_file = NULL;
struct passwd *pw;
int debug = 0, nofork = 0, address_family = IPADDR_UNSPEC;
int do_init_rtc = 0, restarted = 0, timeout = 0;
@ -417,6 +417,9 @@ int main
/* This write to the terminal is OK, it comes before we turn into a daemon */
printf("chronyd (chrony) version %s (%s)\n", CHRONY_VERSION, CHRONYD_FEATURES);
return 0;
} else if (!strcmp("-l", *argv)) {
++argv, --argc;
log_file = *argv;
} else if (!strcmp("-n", *argv)) {
nofork = 1;
} else if (!strcmp("-d", *argv)) {
@ -463,7 +466,9 @@ int main
go_daemon();
}
if (system_log) {
if (log_file) {
LOG_OpenFileLog(log_file);
} else if (system_log) {
LOG_OpenSystemLog();
}