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-aabb0a93e947a2a3cd180b490ae6664396446f63.tar.gz
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)
// 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.