From patchwork Thu Jan 21 08:39:53 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: 571099 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 4BD22140B0E for ; Thu, 21 Jan 2016 19:40:11 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 8A21428BF0A; Thu, 21 Jan 2016 09:39:25 +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 75B3028021B for ; Thu, 21 Jan 2016 09:39:19 +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 ; Thu, 21 Jan 2016 09:39:19 +0100 (CET) Received: from localhost.localdomain (localhost [127.0.0.1]) by mengele.ibawizard.net (Postfix) with ESMTP id 569511D36050; Thu, 21 Jan 2016 09:39:57 +0100 (CET) From: =?UTF-8?q?Petr=20=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 21 Jan 2016 09:39:53 +0100 Message-Id: <1453365593-4098-1-git-send-email-ynezz@true.cz> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <20160120091743.GT29110@medion.lan> References: <20160120091743.GT29110@medion.lan> MIME-Version: 1.0 Subject: [OpenWrt-Devel] [PATCH v3] 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 v3: * uppercased global variables package/base-files/files/etc/init.d/sysfixtime | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/package/base-files/files/etc/init.d/sysfixtime b/package/base-files/files/etc/init.d/sysfixtime index 4010e06..83e9ee4 100755 --- a/package/base-files/files/etc/init.d/sysfixtime +++ b/package/base-files/files/etc/init.d/sysfixtime @@ -2,10 +2,25 @@ # Copyright (C) 2013-2014 OpenWrt.org START=00 +STOP=90 + +RTC_DEV=/dev/rtc0 +HWCLOCK=/sbin/hwclock boot() { + [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -f $RTC_DEV && 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" +}