]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
main: add -q/-Q options to set clock/print offset once and exit
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 9 Apr 2014 10:12:12 +0000 (12:12 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 9 Apr 2014 10:15:07 +0000 (12:15 +0200)
chrony.texi.in
chronyd.8.in
main.c

index 255b15eb131278fbe0b0c434762c63f39003df28..3928e8aadbbabea5762b5847e32da6d5e0375c9f 100644 (file)
@@ -1026,6 +1026,12 @@ system clock last time the computer was on.
 @item -u <user>
 When this option is used, chronyd will drop root privileges to the specified
 user.  So far, it works only on Linux when compiled with capabilities support.
+@item -q
+When run in this mode, @code{chronyd} will set the system clock once
+and exit.  It will not detach from the terminal.
+@item -Q
+This option is similar to `-q', but it will only print the offset and
+not correct the clock.
 @item -v
 This option displays @code{chronyd's} version number to the terminal and
 exits.
index 63eaab84eb6ba186b61143965eb5c8fd04e08170..5d2e3c5d4fc1eb569f6b86e46a381bf594f55988 100644 (file)
@@ -103,6 +103,14 @@ computer was on.
 When this option is used, chronyd will drop root privileges to the specified
 user.  So far, it works only on Linux when compiled with capabilities support.
 .TP
+.B \-q
+When run in this mode, chronyd will set the system clock once
+and exit.  It will not detach from the terminal.
+.TP
+.B \-Q
+This option is similar to \fB\-q\fR, but it will only print the offset and
+not correct the clock.
+.TP
 .B \-v
 This option displays \fBchronyd\fR's version number to the terminal and exits
 .TP
diff --git a/main.c b/main.c
index 825c18bfd9998a4ed507b183c4cceac5aa0918c2..6c6b3ee1af1cd3534c218a8247be7e26983fcd74 100644 (file)
--- a/main.c
+++ b/main.c
@@ -148,6 +148,12 @@ post_init_ntp_hook(void *anything)
 
   RTC_StartMeasurements();
   RCL_StartRefclocks();
+
+  /* Special modes can end only when sources update their reachability.
+     Give up immediatelly if there are no sources. */
+  if (ref_mode != REF_ModeNormal && !SRC_ReadNumberOfSources()) {
+    REF_SetUnsynchronised();
+  }
 }
 
 /* ================================================== */
@@ -157,6 +163,8 @@ reference_mode_end(int result)
 {
   switch (ref_mode) {
     case REF_ModeNormal:
+    case REF_ModeUpdateOnce:
+    case REF_ModePrintOnce:
       exit_status = !result;
       SCH_QuitProgram();
       break;
@@ -363,6 +371,14 @@ int main
       debug++;
       nofork = 1;
       system_log = 0;
+    } else if (!strcmp("-q", *argv)) {
+      ref_mode = REF_ModeUpdateOnce;
+      nofork = 1;
+      system_log = 0;
+    } else if (!strcmp("-Q", *argv)) {
+      ref_mode = REF_ModePrintOnce;
+      nofork = 1;
+      system_log = 0;
     } else if (!strcmp("-4", *argv)) {
       address_family = IPADDR_INET4;
     } else if (!strcmp("-6", *argv)) {
@@ -455,7 +471,7 @@ int main
   /* From now on, it is safe to do finalisation on exit */
   initialised = 1;
 
-  if (CNF_GetInitSources() > 0) {
+  if (ref_mode == REF_ModeNormal && CNF_GetInitSources() > 0) {
     ref_mode = REF_ModeInitStepSlew;
   }