getty: do not emit bogus error message on EOF
[oweals/busybox.git] / networking / ntpd.c
index aca79c95ad4d7013eb5e3f1f46fbbd12b8010ccd..6d9183a4bfa04264d665d12f1ad79f10e16c8dd2 100644 (file)
@@ -294,7 +294,6 @@ struct globals {
 #define G_precision_sec  (1.0 / (1 << (- G_precision_exp)))
        uint8_t  stratum;
        /* Bool. After set to 1, never goes back to 0: */
-       smallint adjtimex_was_done;
        smallint initial_poll_complete;
 
 #define STATE_NSET      0       /* initial state, "nothing is set" */
@@ -736,6 +735,13 @@ send_query_to_peer(peer_t *p)
 }
 
 
+/* Note that there is no provision to prevent several run_scripts
+ * to be done in quick succession. In fact, it happens rather often
+ * if initial syncronization results in a step.
+ * You will see "step" and then "stratum" script runs, sometimes
+ * as close as only 0.002 seconds apart.
+ * Script should be ready to deal with this.
+ */
 static void run_script(const char *action, double offset)
 {
        char *argv[3];
@@ -766,7 +772,7 @@ static void run_script(const char *action, double offset)
 
        /* Don't want to wait: it may run hwclock --systohc, and that
         * may take some time (seconds): */
-       /*wait4pid(spawn(argv));*/
+       /*spawn_and_wait(argv);*/
        spawn(argv);
 
        unsetenv("stratum");
@@ -813,6 +819,7 @@ step_time(double offset)
        /* Globals: */
        G.cur_time -= offset;
        G.last_update_recv_time -= offset;
+       G.last_script_run -= offset;
 }
 
 
@@ -1171,7 +1178,6 @@ static NOINLINE int
 update_local_clock(peer_t *p)
 {
        int rc;
-       long old_tmx_offset;
        struct timex tmx;
        /* Note: can use G.cluster_offset instead: */
        double offset = p->filter_offset;
@@ -1186,8 +1192,8 @@ update_local_clock(peer_t *p)
        abs_offset = fabs(offset);
 
 #if 0
-       /* If needed, -S script can detect this by looking at $offset
-        * env var and kill parent */
+       /* If needed, -S script can do it by looking at $offset
+        * env var and killing parent */
        /* If the offset is too large, give up and go home */
        if (abs_offset > PANIC_THRESHOLD) {
                bb_error_msg_and_die("offset %f far too big, exiting", offset);
@@ -1423,17 +1429,6 @@ update_local_clock(peer_t *p)
                                tmx.freq, tmx.offset, tmx.constant, tmx.status);
        }
 
-       old_tmx_offset = 0;
-       if (!G.adjtimex_was_done) {
-               G.adjtimex_was_done = 1;
-               /* When we use adjtimex for the very first time,
-                * we need to ADD to pre-existing tmx.offset - it may be !0
-                */
-               memset(&tmx, 0, sizeof(tmx));
-               if (adjtimex(&tmx) < 0)
-                       bb_perror_msg_and_die("adjtimex");
-               old_tmx_offset = tmx.offset;
-       }
        memset(&tmx, 0, sizeof(tmx));
 #if 0
 //doesn't work, offset remains 0 (!) in kernel:
@@ -1446,9 +1441,8 @@ update_local_clock(peer_t *p)
        tmx.offset = G.last_update_offset * 1000000; /* usec */
 #endif
        tmx.modes = ADJ_OFFSET | ADJ_STATUS | ADJ_TIMECONST;// | ADJ_MAXERROR | ADJ_ESTERROR;
-       tmx.offset = (G.last_update_offset * 1000000) /* usec */
+       tmx.offset = (G.last_update_offset * 1000000); /* usec */
                        /* + (G.last_update_offset < 0 ? -0.5 : 0.5) - too small to bother */
-                       + old_tmx_offset; /* almost always 0 */
        tmx.status = STA_PLL;
        if (G.ntp_status & LI_PLUSSEC)
                tmx.status |= STA_INS;
@@ -2020,9 +2014,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv)
                nfds = poll(pfd, i, timeout * 1000);
                gettime1900d(); /* sets G.cur_time */
                if (nfds <= 0) {
-                       if (G.adjtimex_was_done
-                        && G.cur_time - G.last_script_run > 11*60
-                       ) {
+                       if (G.script_name && G.cur_time - G.last_script_run > 11*60) {
                                /* Useful for updating battery-backed RTC and such */
                                run_script("periodic", G.last_update_offset);
                                gettime1900d(); /* sets G.cur_time */