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>
1_26_stable
Denys Vlasenko 2016-07-03 17:58:54 +02:00
parent 5b8c89d1f2
commit aabb0a93e9
1 changed files with 25 additions and 20 deletions

View File

@ -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.