aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/ntpd.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 98158a304..8e7175063 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -2213,6 +2213,31 @@ static NOINLINE void ntp_init(char **argv)
// if (opts & OPT_x) /* disable stepping, only slew is allowed */
// G.time_was_stepped = 1;
+
+#if ENABLE_FEATURE_NTPD_SERVER
+ G_listen_fd = -1;
+ if (opts & OPT_l) {
+ G_listen_fd = create_and_bind_dgram_or_die(NULL, 123);
+ if (G.if_name) {
+ if (setsockopt_bindtodevice(G_listen_fd, G.if_name))
+ xfunc_die();
+ }
+ socket_want_pktinfo(G_listen_fd);
+ setsockopt_int(G_listen_fd, IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY);
+ }
+#endif
+ /* I hesitate to set -20 prio. -15 should be high enough for timekeeping */
+ if (opts & OPT_N)
+ setpriority(PRIO_PROCESS, 0, -15);
+
+ /* add_peers() calls can retry DNS resolution (possibly forever).
+ * Daemonize before them, or else boot can stall forever.
+ */
+ if (!(opts & OPT_n)) {
+ bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO, argv);
+ logmode = LOGMODE_NONE;
+ }
+
if (peers) {
while (peers)
add_peers(llist_pop(&peers));
@@ -2241,26 +2266,6 @@ static NOINLINE void ntp_init(char **argv)
/* -l but no peers: "stratum 1 server" mode */
G.stratum = 1;
}
-#if ENABLE_FEATURE_NTPD_SERVER
- G_listen_fd = -1;
- if (opts & OPT_l) {
- G_listen_fd = create_and_bind_dgram_or_die(NULL, 123);
- if (opts & OPT_I) {
- if (setsockopt_bindtodevice(G_listen_fd, G.if_name))
- xfunc_die();
- }
- socket_want_pktinfo(G_listen_fd);
- setsockopt_int(G_listen_fd, IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY);
- }
-#endif
- if (!(opts & OPT_n)) {
- bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO, argv);
- logmode = LOGMODE_NONE;
- }
- /* I hesitate to set -20 prio. -15 should be high enough for timekeeping */
- if (opts & OPT_N)
- setpriority(PRIO_PROCESS, 0, -15);
-
/* If network is up, syncronization occurs in ~10 seconds.
* We give "ntpd -q" 10 seconds to get first reply,
* then another 50 seconds to finish syncing.