[BACK]Return to rtclocaltime CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / etc / rc.d

File: [cvs.NetBSD.org] / src / etc / rc.d / rtclocaltime (download)

Revision 1.1, Sat Dec 27 00:23:22 2003 UTC (20 years, 3 months ago) by martin
Branch: MAIN
CVS Tags: netbsd-2-base, netbsd-2-1-RELEASE, netbsd-2-1-RC6, netbsd-2-1-RC5, netbsd-2-1-RC4, netbsd-2-1-RC3, netbsd-2-1-RC2, netbsd-2-1-RC1, netbsd-2-1, netbsd-2-0-base, netbsd-2-0-RELEASE, netbsd-2-0-RC5, netbsd-2-0-RC4, netbsd-2-0-RC3, netbsd-2-0-RC2, netbsd-2-0-RC1, netbsd-2-0-3-RELEASE, netbsd-2-0-2-RELEASE, netbsd-2-0-1-RELEASE, netbsd-2-0, netbsd-2

Add a new /etc/rc.conf option: rtclocaltime=YES adapts the RTC offset
at boot automatically, so a machine dual booting another OS that uses
the RTC at localtime and NetBSD agree on the current time even if daylight
saving started/ended (without recompiling a kernel twice per year).
Awk code by Matt Thomas.

#! /bin/sh

# PROVIDE: rtclocaltime
# REQUIRE: mountcritremote
# BEFORE:  ntpdate ntpd

. /etc/rc.subr

name="rtclocaltime"
rcvar=$name
start_cmd="rtclocaltime_start"
stop_cmd=":"

rtclocaltime_start()
{
	rtcoff=$(date '+%z' | awk '{
		offset = int($1);
		if (offset < 0) {
			sign = -1;
			offset = -offset;
		} else {
			sign = 1;
		}
		minutes = offset % 100;
		hours = offset / 100;
		offset = sign * (hours * 60 + minutes);
		print offset;
	}')
	sysctl -w kern.rtc_offset=$((-1 * $rtcoff))
}

load_rc_config $name
run_rc_command "$1"