diff options
author | Karel Zak | 2006-12-07 00:25:43 +0100 |
---|---|---|
committer | Karel Zak | 2006-12-07 00:25:43 +0100 |
commit | 22853e4a82c6ef7b336527529acb94b14a0b0fd8 (patch) | |
tree | ee28e4598c8c449d7e811711d8ce8eb17caecfb6 /clock | |
parent | Imported from util-linux-2.10f tarball. (diff) | |
download | kernel-qcow2-util-linux-22853e4a82c6ef7b336527529acb94b14a0b0fd8.tar.gz kernel-qcow2-util-linux-22853e4a82c6ef7b336527529acb94b14a0b0fd8.tar.xz kernel-qcow2-util-linux-22853e4a82c6ef7b336527529acb94b14a0b0fd8.zip |
Imported from util-linux-2.10m tarball.
Diffstat (limited to 'clock')
-rw-r--r-- | clock/Makefile | 5 | ||||
-rw-r--r-- | clock/clock.h | 1 | ||||
-rw-r--r-- | clock/cmos.c | 15 | ||||
-rw-r--r-- | clock/hwclock.8 | 60 | ||||
-rw-r--r-- | clock/hwclock.c | 82 | ||||
-rw-r--r-- | clock/kd.c | 3 | ||||
-rw-r--r-- | clock/shhopt.c | 2 |
7 files changed, 98 insertions, 70 deletions
diff --git a/clock/Makefile b/clock/Makefile index fd0522b38..10e96051a 100644 --- a/clock/Makefile +++ b/clock/Makefile @@ -20,6 +20,11 @@ hwclock.o: hwclock.c shhopt.h hwclock.o cmos.o rtc.o kd.o: clock.h hwclock: hwclock.o shhopt.o cmos.o rtc.o kd.o +CWFLAGS := $(subst -Wmissing-prototypes,,$(CFLAGS)) + +cmos.o: cmos.c + $(CC) $(CWFLAGS) -c $< -o $@ + install: all $(INSTALLDIR) $(SBINDIR) $(BINDIR) $(USRBINDIR) $(INSTALLBIN) $(SBIN) $(SBINDIR) diff --git a/clock/clock.h b/clock/clock.h index b57b499c0..fc91826ce 100644 --- a/clock/clock.h +++ b/clock/clock.h @@ -22,6 +22,7 @@ typedef int bool; /* hwclock.c */ extern char *progname; extern int debug; +extern int epoch_option; extern void outsyserr(char *msg); /* cmos.c */ diff --git a/clock/cmos.c b/clock/cmos.c index 827ec54a9..16705bf7f 100644 --- a/clock/cmos.c +++ b/clock/cmos.c @@ -63,7 +63,7 @@ int inb(int c){ return 0; } #define TM_EPOCH 1900 int cmos_epoch = 1900; /* 1980 for an alpha in ARC console time */ - /* One also sees 1952 (Digital Unix?) + /* One also sees 1952 (Digital Unix) and 1958 (ALPHA_PRE_V1_2_SRM_CONSOLE) */ /* Martin Ostermann writes: @@ -125,6 +125,11 @@ set_cmos_epoch(int ARCconsole, int SRM) { unsigned long epoch; /* Believe the user */ + if (epoch_option != -1) { + cmos_epoch = epoch_option; + return; + } + if (ARCconsole) cmos_epoch = 1980; @@ -138,6 +143,12 @@ set_cmos_epoch(int ARCconsole, int SRM) { return; } + /* The kernel source today says: read the year. If it is + in 11-43 then the epoch is 1980 (this covers 1991-2023). + Otherwise, if it is less than 96 then the epoch is 1952 + (this covers 1952-1962 and 1996-2047). Otherwise, the epoch + is 1900 (this covers 1996-1999, or rather 1996-2155). */ + /* See whether we are dealing with SRM or MILO, as they have different "epoch" ideas. */ @@ -395,7 +406,7 @@ hclock_set_time(const struct tm *tm) { } static inline int -cmos_clock_busy() { +cmos_clock_busy(void) { return #ifdef __alpha__ /* poll bit 4 (UF) of Control Register C */ diff --git a/clock/hwclock.8 b/clock/hwclock.8 index ddf0c7c3e..f34bfac00 100644 --- a/clock/hwclock.8 +++ b/clock/hwclock.8 @@ -1,30 +1,30 @@ -.TH CLOCK 8 "02 March 1998" +.TH HWCLOCK 8 "02 March 1998" .SH NAME -clock \- query and set the hardware clock (RTC) +hwclock \- query and set the hardware clock (RTC) .SH SYNOPSIS -.B "hwclock \-\-show" +.BR "hwclock \-r" " or " "hwclock \-\-show" .br -.B "hwclock \-\-set \-\-date=newdate" +.BR "hwclock \-w" " or " "hwclock \-\-systohc" .br -.B "hwclock \-\-systohc" +.BR "hwclock \-s" " or " "hwclock \-\-hctosys" .br -.B "hwclock \-\-hctosys" +.BR "hwclock \-a" " or " "hwclock \-\-adjust" .br -.B "hwclock \-\-getepoch" +.BR "hwclock \-v" " or " "hwclock \-\-version" .br -.B "hwclock \-\-setepoch \-\-epoch=year" +.B "hwclock \-\-set \-\-date=newdate" .br -.B "hwclock \-\-adjust" +.B "hwclock \-\-getepoch" .br -.B "hwclock \-\-version" +.B "hwclock \-\-setepoch \-\-epoch=year" .PP other options: .PP -.B "\-\-utc \-\-localtime \-\-directisa \-\-test \-\-debug" +.B "[\-u|\-\-utc] \-\-localtime \-\-directisa \-\-test \-\-debug" .PP and arcane options for DEC Alpha: .PP -.B "\-\-arc \-\-jensen \-\-srm \-\-funky-toy" +.B "[\-A|\-\-arc] [\-J|\-\-jensen] [\-S|\-\-srm] [\-F|\-\-funky-toy]" .PP Minimum unique abbreviations of all options are acceptable. .PP @@ -67,16 +67,15 @@ option. .B \-\-hctosys Set the System Time from the Hardware Clock. -Also set the kernel's timezone value to the local timezone as indicated by -the TZ environment variable and/or +Also set the kernel's timezone value to the local timezone +as indicated by the TZ environment variable and/or .IR /usr/lib/zoneinfo , as .BR tzset (3) -would interpret them. EXCEPT: always set the Daylight Savings Time part of -the kernel's timezone value to 0 ("not Daylight Savings Time"). If DST -is indicated, just add an hour to the base part. - -See the discussion of timezones below. +would interpret them. +The obsolete tz_dsttime field of the kernel's timezone value is set +to DST_NONE. (For details on what this field used to mean, see +.BR settimeofday (2).) This is a good option to use in one of the system startup scripts. .TP @@ -356,21 +355,14 @@ sets the kernel timezone to the value indicated by TZ and/or .B \-\-hctosys option. .PP -A complication is that the timezone value actually consists of two -parts: 1) how far from the Standard Meridian the locality is -geographically, and 2) whether or not a Daylight Savings Time (DST) -convention is in effect in the locality at the present time. In -practice, the DST part of the timezone value is almost never used, so -if the geographical part were to be set to its correct value, the -users of the timezone value would actually compute the wrong local -time. -.PP -Therefore, -.I hwclock -violates the definition of the kernel's timezone value and always sets -the DST part to zero. If DST is supposed to be in effect, -.I hwclock -simply adds an hour to the geographical part. +The timezone value actually consists of two parts: 1) a field +tz_minuteswest indicating how many minutes local time (not adjusted +for DST) lags behind UTC, and 2) a field tz_dsttime indicating +the type of Daylight Savings Time (DST) convention that is in effect +in the locality at the present time. +This second field is not used under Linux and is always zero. +(See also +.BR settimeofday (2).) .SH How hwclock Accesses the Hardware Clock .PP diff --git a/clock/hwclock.c b/clock/hwclock.c index 8c682380e..d45516b4b 100644 --- a/clock/hwclock.c +++ b/clock/hwclock.c @@ -19,6 +19,7 @@ * and Martin Ostermann <ost@coments.rwth-aachen.de>, aeb@cwi.nl, 990212. * * Fix for Award 2094 bug, Dave Coffin (dcoffin@shore.net) 11/12/98 + * Change of local time handling, Stefan Ring <e9725446@stud3.tuwien.ac.at> */ /* @@ -126,6 +127,9 @@ bool debug; bool badyear; /* Workaround for Award 4.50g BIOS bug: keep the year in a file. */ +int epoch_option = -1; + /* User-specified epoch, used when rtc fails to return epoch. */ + /* * Almost all Award BIOS's made between 04/26/94 and 05/31/95 * have a nasty bug limiting the RTC year byte to the range 94-99. @@ -136,7 +140,7 @@ bool badyear; * I recommend putting this command "hwclock --badyear" in the monthly * crontab, just to be safe. -- Dave Coffin 11/12/98 */ -void +static void write_date_to_file (struct tm *tm) { FILE *fp; @@ -148,7 +152,7 @@ write_date_to_file (struct tm *tm) { perror(LASTDATE); } -void +static void read_date_from_file (struct tm *tm) { int last_mday, last_mon, last_year; FILE *fp; @@ -378,18 +382,17 @@ mktime_tz(struct tm tm, const bool universal, *systime_p = 0; if (debug) printf(_("Invalid values in hardware clock: " - "%2d/%.2d/%.2d %.2d:%.2d:%.2d\n"), - tm.tm_year, tm.tm_mon+1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec - ); + "%4d/%.2d/%.2d %.2d:%.2d:%.2d\n"), + tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec); } else { *valid_p = TRUE; *systime_p = mktime_result; if (debug) - printf(_("Hw clock time : %2d/%.2d/%.2d %.2d:%.2d:%.2d = " - "%d seconds since 1969\n"), - tm.tm_year, tm.tm_mon+1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, (int) *systime_p); + printf(_("Hw clock time : %4d/%.2d/%.2d %.2d:%.2d:%.2d = " + "%ld seconds since 1969\n"), + tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec, (long) *systime_p); } /* now put back the original zone. */ if (zone) setenv("TZ", zone, TRUE); @@ -414,7 +417,8 @@ read_hardware_clock(const bool universal, bool *valid_p, time_t *systime_p){ read_date_from_file(&tm); if (debug) - printf (_("Time read from Hardware Clock: %02d:%02d:%02d\n"), + printf (_("Time read from Hardware Clock: %4d/%.2d/%.2d %02d:%02d:%02d\n"), + tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); mktime_tz(tm, universal, valid_p, systime_p); } @@ -596,8 +600,8 @@ interpret_date_string(const char *date_opt, time_t * const time_p) { int seconds_since_epoch; rc = sscanf(date_resp + sizeof(magic)-1, "%d", &seconds_since_epoch); if (rc < 1) { - fprintf(stderr, _("The date command issued by %s returned" - "something other than an integer where the converted" + fprintf(stderr, _("The date command issued by %s returned " + "something other than an integer where the converted " "time value was expected.\n" "The command was:\n %s\nThe response was:\n %s\n"), MYNAME, date_command, date_resp); @@ -643,29 +647,33 @@ set_system_clock(const bool hclock_valid, const time_t newtime, retcode = 1; } else { struct timeval tv; + struct tm *broken; + int minuteswest; int rc; tv.tv_sec = newtime; tv.tv_usec = 0; - tzset(); /* init timezone from TZ or ...zoneinfo/localtime */ + broken = localtime(&newtime); +#ifdef HAVE_tm_gmtoff + minuteswest = -broken->tm_gmtoff/60; /* GNU extension */ +#else + minuteswest = timezone/60; + if (broken->tm_isdst) + minuteswest -= 60; +#endif if (debug) { printf( _("Calling settimeofday:\n") ); printf( _("\ttv.tv_sec = %ld, tv.tv_usec = %ld\n"), (long) tv.tv_sec, (long) tv.tv_usec ); - printf( _("\ttz.tz_minuteswest = %ld\n"), timezone/60); + printf( _("\ttz.tz_minuteswest = %d\n"), minuteswest); } if (testing) { printf(_("Not setting system clock because running in test mode.\n")); retcode = 0; } else { - /* For documentation of settimeofday(), in addition to its man page, - see kernel/time.c in the Linux source code. - The code used to have `-60*daylight' here, but that is wrong. - The variable `daylight' does not specify whether it is DST now. */ - - const struct timezone tz = { timezone/60, 0 }; + const struct timezone tz = { minuteswest, 0 }; rc = settimeofday(&tv, &tz); if (rc != 0) { @@ -1149,7 +1157,6 @@ main(int argc, char **argv, char **envp) { bool ARCconsole, utc, testing, directisa, Jensen, SRM, funky_toy; bool local_opt; char *date_opt; - int epoch_opt; const optStruct option_def[] = { { 'h', (char *) "help", OPT_FLAG, &help, 0 }, @@ -1163,7 +1170,7 @@ main(int argc, char **argv, char **envp) { { 'v', (char *) "version", OPT_FLAG, &version, 0 }, { 'V', (char *) "version", OPT_FLAG, &version, 0 }, { 0, (char *) "date", OPT_STRING, &date_opt, 0 }, - { 0, (char *) "epoch", OPT_UINT, &epoch_opt, 0 }, + { 0, (char *) "epoch", OPT_UINT, &epoch_option,0 }, { 'u', (char *) "utc", OPT_FLAG, &utc, 0 }, { 0, (char *) "localtime", OPT_FLAG, &local_opt, 0 }, { 0, (char *) "badyear", OPT_FLAG, &badyear, 0 }, @@ -1183,7 +1190,9 @@ main(int argc, char **argv, char **envp) { gettimeofday(&startup_time, NULL); /* Remember what time we were invoked */ - setlocale(LC_ALL, ""); + /* not LC_ALL - the LC_NUMERIC part gives problems when + writing to /etc/adjtime - gqueri@mail.dotcom.fr */ + setlocale(LC_MESSAGES, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); @@ -1192,13 +1201,12 @@ main(int argc, char **argv, char **envp) { version = utc = local_opt = ARCconsole = SRM = funky_toy = directisa = badyear = Jensen = testing = debug = FALSE; date_opt = NULL; - epoch_opt = -1; argc_parse = argc; argv_parse = argv; optParseOptions(&argc_parse, argv_parse, option_def, 0); /* Uses and sets argc_parse, argv_parse. Sets show, systohc, hctosys, adjust, utc, local_opt, version, - testing, debug, set, date_opt, getepoch, setepoch, epoch_opt + testing, debug, set, date_opt, getepoch, setepoch, epoch_option */ /* This is an ugly routine - for example, if I give an incorrect option, it only says "unrecognized option" without telling @@ -1252,12 +1260,17 @@ main(int argc, char **argv, char **envp) { fprintf(stderr, _("Sorry, only the superuser can change the Hardware Clock.\n")); permitted = FALSE; + } else if (hctosys) { + fprintf(stderr, + _("Sorry, only the superuser can change the System Clock.\n")); + permitted = FALSE; } else if (setepoch) { fprintf(stderr, _("Sorry, only the superuser can change " "the Hardware Clock epoch in the kernel.\n")); permitted = FALSE; - } else permitted = TRUE; + } else + permitted = TRUE; } if (!permitted) retcode = 2; @@ -1266,16 +1279,19 @@ main(int argc, char **argv, char **envp) { if (version) { printf(MYNAME " " VERSION "/%s\n",util_linux_version); } else if (getepoch || setepoch) { - manipulate_epoch(getepoch, setepoch, epoch_opt, testing); + manipulate_epoch(getepoch, setepoch, epoch_option, testing); } else { if (debug) printf(MYNAME " " VERSION "/%s\n",util_linux_version); determine_clock_access_method(directisa); - if (!ur) - fprintf(stderr, _("Cannot access the Hardware Clock via any known " - "method. Use --debug option to see the details of our " - "search for an access method.\n")); - else + if (!ur) { + fprintf(stderr, + _("Cannot access the Hardware Clock via any known method.\n")); + if (!debug) + fprintf(stderr, + _("Use the --debug option to see the details of our " + "search for an access method.\n")); + } else manipulate_clock(show, adjust, set, set_time, hctosys, systohc, startup_time, utc, local_opt, testing, &rc); } diff --git a/clock/kd.c b/clock/kd.c index d1c4aca19..8fab619ff 100644 --- a/clock/kd.c +++ b/clock/kd.c @@ -158,7 +158,10 @@ probe_for_kd_clock() { } else ret = &kd; } else { + /* probably KDGHWCLK exists on m68k only */ +#ifdef __m68k__ outsyserr(_("Can't open /dev/tty1")); +#endif } return ret; } diff --git a/clock/shhopt.c b/clock/shhopt.c index e55a7293a..ac3412829 100644 --- a/clock/shhopt.c +++ b/clock/shhopt.c @@ -228,7 +228,7 @@ static void argvRemove(int *argc, char *argv[], int i) * RETURNS Nothing. Aborts in case of error. * */ -void optExecute(const optStruct *opt, char *arg, int lng) +static void optExecute(const optStruct *opt, char *arg, int lng) { switch (opt->type) { case OPT_FLAG: |