]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
main: add option to specify log file
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 24 May 2017 14:03:39 +0000 (16:03 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 26 May 2017 11:33:53 +0000 (13:33 +0200)
Add -l option to log to a file instead of syslog or terminal.

doc/chronyd.adoc
main.c

index 2ae5b17604f7f935c4aac4a1cb410e529be3befe..68f878276bf7831c0167526a77ad15abb7c832c9 100644 (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.
diff --git a/main.c b/main.c
index 29bc6beefeb46c84f182fce842cc0a80bc732b5e..dd07019c7a74c1c84509b583570173424f77de65 100644 (file)
--- a/main.c
+++ b/main.c
@@ -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();
   }