diff options
-rw-r--r-- | networking/ntpd.c | 45 |
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) | |||
2213 | 2213 | ||
2214 | // if (opts & OPT_x) /* disable stepping, only slew is allowed */ | 2214 | // if (opts & OPT_x) /* disable stepping, only slew is allowed */ |
2215 | // G.time_was_stepped = 1; | 2215 | // G.time_was_stepped = 1; |
2216 | |||
2217 | #if ENABLE_FEATURE_NTPD_SERVER | ||
2218 | G_listen_fd = -1; | ||
2219 | if (opts & OPT_l) { | ||
2220 | G_listen_fd = create_and_bind_dgram_or_die(NULL, 123); | ||
2221 | if (G.if_name) { | ||
2222 | if (setsockopt_bindtodevice(G_listen_fd, G.if_name)) | ||
2223 | xfunc_die(); | ||
2224 | } | ||
2225 | socket_want_pktinfo(G_listen_fd); | ||
2226 | setsockopt_int(G_listen_fd, IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY); | ||
2227 | } | ||
2228 | #endif | ||
2229 | /* I hesitate to set -20 prio. -15 should be high enough for timekeeping */ | ||
2230 | if (opts & OPT_N) | ||
2231 | setpriority(PRIO_PROCESS, 0, -15); | ||
2232 | |||
2233 | /* add_peers() calls can retry DNS resolution (possibly forever). | ||
2234 | * Daemonize before them, or else boot can stall forever. | ||
2235 | */ | ||
2236 | if (!(opts & OPT_n)) { | ||
2237 | bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO, argv); | ||
2238 | logmode = LOGMODE_NONE; | ||
2239 | } | ||
2240 | |||
2216 | if (peers) { | 2241 | if (peers) { |
2217 | while (peers) | 2242 | while (peers) |
2218 | add_peers(llist_pop(&peers)); | 2243 | add_peers(llist_pop(&peers)); |
@@ -2241,26 +2266,6 @@ static NOINLINE void ntp_init(char **argv) | |||
2241 | /* -l but no peers: "stratum 1 server" mode */ | 2266 | /* -l but no peers: "stratum 1 server" mode */ |
2242 | G.stratum = 1; | 2267 | G.stratum = 1; |
2243 | } | 2268 | } |
2244 | #if ENABLE_FEATURE_NTPD_SERVER | ||
2245 | G_listen_fd = -1; | ||
2246 | if (opts & OPT_l) { | ||
2247 | G_listen_fd = create_and_bind_dgram_or_die(NULL, 123); | ||
2248 | if (opts & OPT_I) { | ||
2249 | if (setsockopt_bindtodevice(G_listen_fd, G.if_name)) | ||
2250 | xfunc_die(); | ||
2251 | } | ||
2252 | socket_want_pktinfo(G_listen_fd); | ||
2253 | setsockopt_int(G_listen_fd, IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY); | ||
2254 | } | ||
2255 | #endif | ||
2256 | if (!(opts & OPT_n)) { | ||
2257 | bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO, argv); | ||
2258 | logmode = LOGMODE_NONE; | ||
2259 | } | ||
2260 | /* I hesitate to set -20 prio. -15 should be high enough for timekeeping */ | ||
2261 | if (opts & OPT_N) | ||
2262 | setpriority(PRIO_PROCESS, 0, -15); | ||
2263 | |||
2264 | /* If network is up, syncronization occurs in ~10 seconds. | 2269 | /* If network is up, syncronization occurs in ~10 seconds. |
2265 | * We give "ntpd -q" 10 seconds to get first reply, | 2270 | * We give "ntpd -q" 10 seconds to get first reply, |
2266 | * then another 50 seconds to finish syncing. | 2271 | * then another 50 seconds to finish syncing. |