]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
main: support configuration commands on command line
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 9 Apr 2014 13:12:53 +0000 (15:12 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 9 Apr 2014 13:16:35 +0000 (15:16 +0200)
If there are extra arguments on the chronyd command line, they will be
parsed as lines in a configuration file and the normal configuration file
will be ignored.

chrony.texi.in
chronyd.8.in
main.c

index 3928e8aadbbabea5762b5847e32da6d5e0375c9f..18fbf41b94911f757b9a70b16aa75aef87c5444a 100644 (file)
@@ -971,6 +971,10 @@ entering the command
 
 Information messages and warnings will be logged to syslog.
 
+If no configuration commands are specified on the command line,
+@code{chronyd} will read the commands from the configuration file
+(default @file{@SYSCONFDIR@/chrony.conf}).
+
 The command line options supported are as follows:
 
 @table @code
@@ -1106,6 +1110,10 @@ Each command in the configuration file is placed on a separate line.
 The following sections describe each of the commands in turn.  The
 directives can occur in any order in the file.
 
+The configuration commands can also be specified directly on the
+@code{chronyd} command line, each argument is parsed as a line and
+the configuration file is ignored.
+
 @menu
 * comments in config file::     How to write a comment
 * acquisitionport directive::   Set port to use for initial time probes
index 5d2e3c5d4fc1eb569f6b86e46a381bf594f55988..245388ace621af77aab9382f79e509bacd2f1c91 100644 (file)
@@ -4,7 +4,7 @@ chronyd \- chrony background daemon
 
 .SH SYNOPSIS
 .B chronyd
-[\fIOPTIONS\fR]
+[\fIOPTIONS\fR] [\fIconfiguration commands\fR]
 
 .SH DESCRIPTION
 \fIchrony\fR is a pair of programs for maintaining the accuracy of computer
@@ -31,6 +31,9 @@ command:
 
 Information messages and warnings will be logged to syslog.
 
+If no configuration commands are specified on the command line,
+\fBchronyd\fR will read the commands from the configuration file
+(default \fI@SYSCONFDIR@/chrony.conf\fR).
 
 .SH OPTIONS
 A summary of the options supported by \fBchronyd\fR is included below.
diff --git a/main.c b/main.c
index 6c6b3ee1af1cd3534c218a8247be7e26983fcd74..77d8d2dd27b3473b87dd2f6452640c792bf5f7a8 100644 (file)
--- a/main.c
+++ b/main.c
@@ -332,6 +332,7 @@ int main
   int other_pid;
   int lock_memory = 0, sched_priority = 0;
   int system_log = 1;
+  int config_args = 0;
 
   LOG_Initialise();
 
@@ -383,8 +384,12 @@ int main
       address_family = IPADDR_INET4;
     } else if (!strcmp("-6", *argv)) {
       address_family = IPADDR_INET6;
-    } else {
+    } else if (*argv[0] == '-') {
       LOG_FATAL(LOGF_Main, "Unrecognized command line option [%s]", *argv);
+    } else {
+      /* Process remaining arguments and configuration lines */
+      config_args = argc;
+      break;
     }
   }
 
@@ -410,7 +415,15 @@ int main
   DNS_SetAddressFamily(address_family);
 
   CNF_SetRestarted(restarted);
-  CNF_ReadFile(conf_file);
+
+  /* Parse the config file or the remaining command line arguments */
+  if (!config_args) {
+    CNF_ReadFile(conf_file);
+  } else {
+    do {
+      CNF_ParseLine(NULL, config_args - argc + 1, *argv);
+    } while (++argv, --argc);
+  }
 
   /* Check whether another chronyd may already be running.  Do this after
    * forking, so that message logging goes to the right place (i.e. syslog), in