[git commit master 1/1] ntpd: with -q, exit after 60 seconds even if time is not synced.

Denys Vlasenko vda.linux at googlemail.com
Fri Aug 27 00:15:01 UTC 2010


commit: http://git.busybox.net/busybox/commit/?id=74c992af5c6b8cfe6214e705bc04f8c2f9d8a304
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 networking/ntpd.c |   25 ++++++++++++++++++++++---
 1 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/networking/ntpd.c b/networking/ntpd.c
index fb3ef2e..6707e9b 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -1920,9 +1920,28 @@ static NOINLINE void ntp_init(char **argv)
 	if (opts & OPT_N)
 		setpriority(PRIO_PROCESS, 0, -15);
 
-	bb_signals((1 << SIGTERM) | (1 << SIGINT), record_signo);
-	/* Removed SIGHUP here: */
-	bb_signals((1 << SIGPIPE) | (1 << SIGCHLD), SIG_IGN);
+	/* If network is up, syncronization occurs in ~10 seconds.
+	 * We give "ntpd -q" a full minute to finish, then we exit.
+	 *
+	 * I tested ntpd 4.2.6p1 and apparently it never exits
+	 * (will try forever), but it does not feel right.
+	 * The goal of -q is to act like ntpdate: set time
+	 * after a reasonably small period of polling, or fail.
+	 */
+	if (opts & OPT_q)
+		alarm(60);
+
+	bb_signals(0
+		| (1 << SIGTERM)
+		| (1 << SIGINT)
+		| (1 << SIGALRM)
+		, record_signo
+	);
+	bb_signals(0
+		| (1 << SIGPIPE)
+		| (1 << SIGCHLD)
+		, SIG_IGN
+	);
 }
 
 int ntpd_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE;
-- 
1.7.1



More information about the busybox-cvs mailing list