"Address: 127.0.0.1\n"
#define ntpd_trivial_usage \
- "[-dngl] [-p PEER]..."
+ "[-dngql] [-p PEER]..."
#define ntpd_full_usage "\n\n" \
"NTP client/server\n" \
"\nOptions:" \
"\n -d Verbose" \
"\n -n Do not daemonize" \
"\n -g Set system time even if offset is > 1000 sec" \
+ "\n -q Quit after clock is set" \
"\n -l Run as server on port 123" \
"\n -p PEER Obtain time from PEER (may be repeated)" \
uint8_t trustlevel;
} ntp_peer_t;
+enum {
+ OPT_n = (1 << 0),
+ OPT_g = (1 << 1),
+ OPT_q = (1 << 2),
+ /* Insert new options above this line. */
+ /* Non-compat options: */
+ OPT_p = (1 << 3),
+ OPT_l = (1 << 4),
+};
+
struct globals {
unsigned verbose;
uint8_t settime;
uint8_t firstadj;
smallint peer_cnt;
-
};
#define G (*ptr_to_globals)
char buf[80];
time_t tval;
-#if 0
if (!G.settime)
- return;
-#endif
+ goto bail;
+
+ G.settime = 0;
/* if the offset is small, don't call settimeofday */
if (offset < SETTIME_MIN_OFFSET && offset > -SETTIME_MIN_OFFSET)
- return;
+ goto bail;
gettimeofday(&curtime, NULL); /* never fails */
if (settimeofday(&curtime, NULL) == -1) {
bb_error_msg("settimeofday");
- return;
+ goto bail;
}
- G.settime = 0;
-
tval = curtime.tv_sec;
strftime(buf, sizeof(buf), "%a %b %e %H:%M:%S %Z %Y", localtime(&tval));
if (p->deadline)
p->deadline -= offset;
}
+
+ bail:
+ if (option_mask32 & OPT_q)
+ exit(0);
}
static void
offset->offset, offset->delay, (int) interval);
client_update(p);
- if (!G.settime)
- settime(offset->offset);
+ settime(offset->offset);
if (++p->shift >= OFFSET_ARRAY_SIZE)
p->shift = 0;
* Note: The kernel time discipline is disabled with this option.
*/
-enum {
- OPT_n = (1 << 0),
- OPT_g = (1 << 1),
- OPT_p = (1 << 2),
- OPT_l = (1 << 3),
-};
-
/* By doing init in a separate function we decrease stack usage
* in main loop.
*/
peers = NULL;
opt_complementary = "dd:p::"; /* d: counter, p: list */
opts = getopt32(argv,
- "ng" /* compat */
+ "ngq" /* compat */
"p:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */
"d" /* compat */
"46aAbLNx", /* compat, ignored */
int ntpd_main(int argc UNUSED_PARAM, char **argv)
{
struct globals g;
- unsigned new_cnt;
struct pollfd *pfd;
ntp_peer_t **idx2peer;
ntp_init(argv);
- new_cnt = g.peer_cnt;
- idx2peer = xzalloc(sizeof(void *) * new_cnt);
-#if ENABLE_FEATURE_NTPD_SERVER
- if (g.listen_fd != -1)
- new_cnt++;
-#endif
- pfd = xzalloc(sizeof(pfd[0]) * new_cnt);
+ {
+ unsigned new_cnt = g.peer_cnt;
+ idx2peer = xzalloc(sizeof(void *) * new_cnt);
+ /* if ENABLE_FEATURE_NTPD_SERVER, + 1 for listen_fd: */
+ pfd = xzalloc(sizeof(pfd[0]) * (new_cnt + ENABLE_FEATURE_NTPD_SERVER));
+ }
while (!bb_got_signal) {
llist_t *item;
}
}
- if (g.settime
- && ((trial_cnt > 0 && sent_cnt == 0) || g.peer_cnt == 0)
- ) {
+ if ((trial_cnt > 0 && sent_cnt == 0) || g.peer_cnt == 0)
settime(0); /* no good peers, don't wait */
- }
timeout = nextaction - time(NULL);
if (timeout < 0)