From patchwork Wed Jan 27 17:39:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 574093 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C865014032B for ; Thu, 28 Jan 2016 04:40:17 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 8C35B28C0A6; Wed, 27 Jan 2016 18:39:09 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00 autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id E8D2028C007 for ; Wed, 27 Jan 2016 18:38:59 +0100 (CET) X-policyd-weight: using cached result; rate: -6.6 Received: from mengele.ibawizard.net (ibawizard.net [82.208.49.253]) by arrakis.dune.hu (Postfix) with ESMTP for ; Wed, 27 Jan 2016 18:38:59 +0100 (CET) Received: from localhost.localdomain (localhost [127.0.0.1]) by mengele.ibawizard.net (Postfix) with ESMTP id 371841D3600C; Wed, 27 Jan 2016 18:39:40 +0100 (CET) From: =?UTF-8?q?Petr=20=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 27 Jan 2016 18:39:41 +0100 Message-Id: <1453916381-14496-1-git-send-email-ynezz@true.cz> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <56A86C4A.7040506@openwrt.org> References: <56A86C4A.7040506@openwrt.org> MIME-Version: 1.0 Subject: [OpenWrt-Devel] [PATCH v4] base-files: For sysfixtime use hwclock if RTC available X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" From: Daniel Dickinson On systems that have an RTC prefer it to the file-based time fixup (i.e. use hwclock when there is a permanent clock instead of the faked up time logic that is needed when there is not RTC). We can't rely on hctosys kernel feature either as we're usually using RTC as kernel modules which are usually being loaded after hctosys was run, leading in the following error: hctosys: unable to open rtc device (rtc0) Signed-off-by: Daniel Dickinson Signed-off-by: Petr Štetiar --- Changes in v4: * simplified with using start() in boot() (blogic) package/base-files/files/etc/init.d/sysfixtime | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/package/base-files/files/etc/init.d/sysfixtime b/package/base-files/files/etc/init.d/sysfixtime index 4010e06..ab946f6 100755 --- a/package/base-files/files/etc/init.d/sysfixtime +++ b/package/base-files/files/etc/init.d/sysfixtime @@ -2,10 +2,24 @@ # Copyright (C) 2013-2014 OpenWrt.org START=00 +STOP=90 + +RTC_DEV=/dev/rtc0 +HWCLOCK=/sbin/hwclock boot() { + start && exit 0 + local curtime="$(date +%s)" local maxtime="$(find /etc -type f -exec date -r {} +%s \; | sort -nr | head -n1)" [ $curtime -lt $maxtime ] && date -s @$maxtime } +start() { + [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -f $RTC_DEV +} + +stop() { + [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -w -f $RTC_DEV && \ + logger -t sysfixtime "saved '$(date)' to $RTC_DEV" +}