From patchwork Wed Oct 24 04:00:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Weber X-Patchwork-Id: 988477 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rockwellcollins.com Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42fxPL2szpz9sCQ for ; Wed, 24 Oct 2018 15:00:37 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 5FACF30C16; Wed, 24 Oct 2018 04:00:34 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PtE6rSprYNzo; Wed, 24 Oct 2018 04:00:29 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id AAA7B30C07; Wed, 24 Oct 2018 04:00:29 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 818F91BF34D for ; Wed, 24 Oct 2018 04:00:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 7EE6987834 for ; Wed, 24 Oct 2018 04:00:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id W0CvQ6CRc8PG for ; Wed, 24 Oct 2018 04:00:27 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from da1vs04.rockwellcollins.com (da1vs04.rockwellcollins.com [205.175.227.52]) by whitealder.osuosl.org (Postfix) with ESMTPS id 837E887912 for ; Wed, 24 Oct 2018 04:00:27 +0000 (UTC) Received: from ofwda1n02.rockwellcollins.com (HELO ciulimr02.rockwellcollins.com) ([205.175.227.14]) by da1vs04.rockwellcollins.com with ESMTP; 23 Oct 2018 23:00:27 -0500 X-Received: from largo.rockwellcollins.com (unknown [192.168.140.76]) by ciulimr02.rockwellcollins.com (Postfix) with ESMTP id 7088520075; Tue, 23 Oct 2018 23:00:26 -0500 (CDT) From: Matt Weber To: buildroot@buildroot.org Date: Tue, 23 Oct 2018 23:00:25 -0500 Message-Id: <1540353625-36573-1-git-send-email-matthew.weber@rockwellcollins.com> X-Mailer: git-send-email 1.9.1 Subject: [Buildroot] [PATCH v2] package/ntp: use ntpd to set initial time X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Oscar Gomez Fuente MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" The ntpdate program has been in the process of being deprecated for some time. (http://support.ntp.org/bin/view/Dev/DeprecatingNtpdate) This patch updates the existing ntpd script to handle setting initial time using the new ntpd "one time set and exit" approach. http://lists.ntp.org/pipermail/questions/2011-July/030041.html The patch does not use the ntpd -w "wait for first time" option and instead makes sure the attempt at a one-shot setting of initial time has completed before starting the main ntpd service. Signed-off-by: Matthew Weber Signed-off-by: Oscar Gomez Fuente --- Changes v1 -> v2 [Arnout - Moved NTP_WAIT_DELAY above sourcing of configuration file - Switched to using unix time for current time check - Added comment on why redirection of stdout and stderr - Attempted to use the pid file but found it added more calls to the shell then using a variable, so switched back - Adjusted printout so the actual ntpd service start was aligned with the respecting Ok/Fail. - Dropped -g from the main service call as the "big" time jump should have already occurred with the one-shot ntpd -gq. v1 Based on Oscar's v1 patch to add a ntpdate startup script. http://patchwork.ozlabs.org/patch/986852/ --- package/ntp/Config.in | 5 +++++ package/ntp/S49ntp | 21 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/package/ntp/Config.in b/package/ntp/Config.in index efd47e1..5cc78ce 100644 --- a/package/ntp/Config.in +++ b/package/ntp/Config.in @@ -54,6 +54,11 @@ config BR2_PACKAGE_NTP_NTPDATE The ntpdate utility program is used to set the local date and time from an NTP server given as an argument. + This option is deprecated by upstream and replaced with the + -gq options of ntpd. The package/ntp/S49ntp script has an + example implementation. + (http://support.ntp.org/bin/view/Dev/DeprecatingNtpdate) + config BR2_PACKAGE_NTP_NTPDC bool "ntpdc" help diff --git a/package/ntp/S49ntp b/package/ntp/S49ntp index 35e5874..2675789 100755 --- a/package/ntp/S49ntp +++ b/package/ntp/S49ntp @@ -2,6 +2,7 @@ NAME=ntpd +NTP_WAIT_DELAY=15 #sec # Read config file if it is present. if [ -r /etc/default/$NAME ] then @@ -10,8 +11,26 @@ fi case "$1" in start) + CURRENT_UNIX_TIME="$(date +%s)" + if [ $CURRENT_UNIX_TIME -lt 1000000000 ]; then + printf "Checking for time" + # stderr redirected to hide output if IPv6 not enabled + /usr/sbin/ntpd -g -q > /dev/null 2>&1 & + NTP_PID=$! + while [ ${NTP_WAIT_DELAY} -gt 0 ]; do + [ ! -e /proc/$NTP_PID ] && break + sleep 1 + printf "." + : $((NTP_WAIT_DELAY -= 1)) + done + # ntpd never returns if it can't access the NTP server(s) + # noted in /etc/ntp.conf. + kill $NTP_PID > /dev/null 2>&1 + [ $? = 0 ] && printf "(Not set)" + fi + echo " OK" printf "Starting $NAME: " - start-stop-daemon -S -q -x /usr/sbin/ntpd -- -g + start-stop-daemon -S -q -x /usr/sbin/ntpd -- [ $? = 0 ] && echo "OK" || echo "FAIL" ;; stop)