aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-07-03 17:58:54 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-07-03 17:58:54 +0200
commitaabb0a93e947a2a3cd180b490ae6664396446f63 (patch)
treed78155400114c2e48cb03ca5463d655ebd20c93e
parent5b8c89d1f270909d1a0201478236de6ed89c8ca4 (diff)
downloadbusybox-w32-aabb0a93e947a2a3cd180b490ae6664396446f63.tar.gz
busybox-w32-aabb0a93e947a2a3cd180b490ae6664396446f63.tar.bz2
busybox-w32-aabb0a93e947a2a3cd180b490ae6664396446f63.zip
ntpd: daemonize before DNS resolution
This resolves the following use case problem: "I start ntpd by default from /etc/init.d There might be no working network connection (not configured properly for whatever reason, hardware problems, whatelse). With busybox 1.25 ntpd seems to loop forever if now NTP servers are found, blocking the boot process and I never get a login to solve a possible pb or to do a first time configuration." Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-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)
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.