From patchwork Thu Dec 17 09:36:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Dickinson X-Patchwork-Id: 558153 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 D531D1402BF for ; Thu, 17 Dec 2015 20:36:29 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id C86DC280AD4; Thu, 17 Dec 2015 10:36:06 +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 6CCB828BBC9 for ; Thu, 17 Dec 2015 10:35:57 +0100 (CET) X-policyd-weight: using cached result; rate:hard: -8.5 Received: from s1.neomailbox.net (s1.neomailbox.net [5.148.176.57]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Thu, 17 Dec 2015 10:35:57 +0100 (CET) From: openwrt@daniel.thecshore.com To: openwrt-devel@lists.openwrt.org Date: Thu, 17 Dec 2015 04:36:05 -0500 Message-Id: <1450344965-96301-1-git-send-email-openwrt@daniel.thecshore.com> In-Reply-To: <1450305693-12193-1-git-send-email-openwrt@daniel.thecshore.com> References: <1450305693-12193-1-git-send-email-openwrt@daniel.thecshore.com> Subject: [OpenWrt-Devel] [PATCH] 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: , MIME-Version: 1.0 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). Signed-off-by: Daniel Dickinson --- package/base-files/files/etc/init.d/sysfixtime | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/package/base-files/files/etc/init.d/sysfixtime b/package/base-files/files/etc/init.d/sysfixtime index 4010e06..e1e6724 100755 --- a/package/base-files/files/etc/init.d/sysfixtime +++ b/package/base-files/files/etc/init.d/sysfixtime @@ -2,10 +2,27 @@ # Copyright (C) 2013-2014 OpenWrt.org START=00 +STOP=90 boot() { - local curtime="$(date +%s)" - local maxtime="$(find /etc -type f -exec date -r {} +%s \; | sort -nr | head -n1)" - [ $curtime -lt $maxtime ] && date -s @$maxtime + if [ ! -e /dev/rtc ]; then + local curtime="$(date +%s)" + local maxtime="$(find /etc -type f -exec date -r {} +%s \; | sort -nr | head -n1)" + [ $curtime -lt $maxtime ] && date -s @$maxtime + else + hwclock -s + fi +} + +start() { + if [ -e /dev/rtc ]; then + hwclock -s + fi +} + +stop() { + if [ -e /dev/rtc ]; then + hwclock -w + fi }