There's no reason for the kernel to track the system's timezone
anymore. This is handled in userspace by the TZ environment variable,
and POSIX doesn't even define what happens if you pass a non-NULL
pointer as the 'struct timezone *' argument to gettimeofday() (and
settimeofday() has never been in POSIX).
The diff below:
- eliminates tz
- adds a compile-time check to detect configs with non-0 timezone
- changes settimeofday() to return EINVAL when given a non-0 timezone
- eliminates the userconf code for changing/printing the timezone
- removes clock and msdosfs code that looks at the kernel timezone
After this, we'll be able to move gettimeofday() and settimeofday()
into libc as user-space wrappers around clock_gettime() and
clock_settime(), respectively.
Any objections?
Index: conf/param.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/conf/param.c,v
retrieving revision 1.34
diff -u -p -r1.34 param.c
--- conf/param.c 10 Apr 2012 15:50:52 -0000 1.34
+++ conf/param.c 23 Apr 2012 17:18:58 -0000
@@ -66,22 +66,19 @@
* the kernel; it should be modified there to suit local taste
* if necessary.
*
- * Compiled with -DHZ=xx -DTIMEZONE=x -DDST=x -DMAXUSERS=xx
+ * Compiled with -DHZ=xx -DMAXUSERS=xx
*/
-#ifndef TIMEZONE
-# define TIMEZONE 0
-#endif
-#ifndef DST
-# define DST 0
+#if (defined(TIMEZONE) && TIMEZONE != 0) || (defined(DST) && DST != 0)
+#error Kernels cannot be configured with custom timezone settings anymore
#endif
+
#ifndef HZ
#define HZ 100
#endif
int hz = HZ;
int tick = 1000000 / HZ;
int tickadj = 240000 / (60 * HZ); /* can adjust 240ms in 60s */
-struct timezone tz = { TIMEZONE, DST };
#define NPROCESS (30 + 16 * MAXUSERS)
#define NTEXT (80 + NPROCESS / 8) /* actually the object
cache */
#define NVNODE (NPROCESS * 2 + NTEXT + 100)
Index: kern/kern_time.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/kern/kern_time.c,v
retrieving revision 1.74
diff -u -p -r1.74 kern_time.c
--- kern/kern_time.c 23 Mar 2012 15:51:26 -0000 1.74
+++ kern/kern_time.c 23 Apr 2012 17:15:20 -0000
@@ -391,8 +391,10 @@ sys_gettimeofday(struct proc *p, void *v
}
#endif
}
- if (tzp)
+ if (tzp) {
+ const struct timezone tz = { 0 };
error = copyout(&tz, tzp, sizeof (tz));
+ }
return (error);
}
@@ -415,20 +417,22 @@ sys_settimeofday(struct proc *p, void *v
if ((error = suser(p, 0)))
return (error);
- /* Verify all parameters before changing time. */
- if (tv && (error = copyin(tv, &atv, sizeof(atv))))
- return (error);
- if (tzp && (error = copyin(tzp, &atz, sizeof(atz))))
- return (error);
+ if (tzp) {
+ if ((error = copyin(tzp, &atz, sizeof(atz))) != 0)
+ return (error);
+ if (atz.tz_minuteswest != 0 || atz.tz_dsttime != 0)
+ return (EINVAL);
+ }
if (tv) {
struct timespec ts;
+ if ((error = copyin(tv, &atv, sizeof(atv))) != 0)
+ return (error);
+
TIMEVAL_TO_TIMESPEC(&atv, &ts);
if ((error = settime(&ts)) != 0)
return (error);
}
- if (tzp)
- tz = atz;
return (0);
}
Index: kern/subr_userconf.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/kern/subr_userconf.c,v
retrieving revision 1.37
diff -u -p -r1.37 subr_userconf.c
--- kern/subr_userconf.c 1 Jun 2011 04:35:22 -0000 1.37
+++ kern/subr_userconf.c 23 Apr 2012 17:15:53 -0000
@@ -40,7 +40,6 @@ extern short cfroots[];
extern int cfroots_size;
extern int pv_size;
extern short pv[];
-extern struct timezone tz;
extern char *pdevnames[];
extern int pdevnames_size;
extern struct pdevinit pdevinit[];
@@ -1306,28 +1305,6 @@ userconf_parse(char *cmd)
userconf_show();
else
userconf_show_attr(c);
- break;
- case 't':
- if (*c == '\0' || userconf_number(c, &a) == 0) {
- if (*c != '\0') {
- tz.tz_minuteswest = a;
- while (*c != '\n' && *c != '\t' &&
- *c != ' ' && *c != '\0')
- c++;
- while (*c == '\t' || *c == ' ')
- c++;
- if (*c != '\0' &&
- userconf_number(c, &a) == 0)
- tz.tz_dsttime = a;
- userconf_hist_cmd('t');
- userconf_hist_int(tz.tz_minuteswest);
- userconf_hist_int(tz.tz_dsttime);
- userconf_hist_eoc();
- }
- printf("timezone = %d, dst = %d\n",
- tz.tz_minuteswest, tz.tz_dsttime);
- } else
- printf("Unknown argument\n");
break;
case 'v':
autoconf_verbose = !autoconf_verbose;
Index: sys/kernel.h
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/sys/kernel.h,v
retrieving revision 1.12
diff -u -p -r1.12 kernel.h
--- sys/kernel.h 16 May 2007 17:27:30 -0000 1.12
+++ sys/kernel.h 23 Apr 2012 17:15:42 -0000
@@ -52,7 +52,6 @@ extern struct timeval boottime;
extern volatile struct timeval mono_time;
extern volatile struct timeval time;
#endif
-extern struct timezone tz; /* XXX */
extern int tick; /* usec per tick (1000000 / hz) */
extern int tickfix; /* periodic tick adj. tick not integral */
Index: arch/amd64/isa/clock.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/arch/amd64/isa/clock.c,v
retrieving revision 1.19
diff -u -p -r1.19 clock.c
--- arch/amd64/isa/clock.c 5 Jul 2011 17:11:07 -0000 1.19
+++ arch/amd64/isa/clock.c 23 Apr 2012 17:16:30 -0000
@@ -529,9 +529,7 @@ inittodr(time_t base)
}
}
- ts.tv_sec = clock_ymdhms_to_secs(&dt) + tz.tz_minuteswest * 60;
- if (tz.tz_dsttime)
- ts.tv_sec -= 3600;
+ ts.tv_sec = clock_ymdhms_to_secs(&dt);
if (base != 0 && base < ts.tv_sec - 5*SECYR)
printf("WARNING: file system time much less than clock time\n");
@@ -560,7 +558,7 @@ resettodr(void)
{
mc_todregs rtclk;
struct clock_ymdhms dt;
- int century, diff, s;
+ int century, s;
/*
* We might have been called by boot() due to a crash early
@@ -574,10 +572,7 @@ resettodr(void)
memset(&rtclk, 0, sizeof(rtclk));
splx(s);
- diff = tz.tz_minuteswest * 60;
- if (tz.tz_dsttime)
- diff -= 3600;
- clock_secs_to_ymdhms(time_second - diff, &dt);
+ clock_secs_to_ymdhms(time_second, &dt);
rtclk[MC_SEC] = bintobcd(dt.dt_sec);
rtclk[MC_MIN] = bintobcd(dt.dt_min);
Index: arch/i386/isa/clock.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/arch/i386/isa/clock.c,v
retrieving revision 1.46
diff -u -p -r1.46 clock.c
--- arch/i386/isa/clock.c 5 Jul 2011 17:11:07 -0000 1.46
+++ arch/i386/isa/clock.c 23 Apr 2012 17:16:48 -0000
@@ -599,9 +599,7 @@ inittodr(time_t base)
}
}
- ts.tv_sec = clock_ymdhms_to_secs(&dt) + tz.tz_minuteswest * 60;
- if (tz.tz_dsttime)
- ts.tv_sec -= 3600;
+ ts.tv_sec = clock_ymdhms_to_secs(&dt);
if (base < ts.tv_sec - 5*SECYR)
printf("WARNING: file system time much less than clock time\n");
@@ -630,7 +628,6 @@ resettodr(void)
{
mc_todregs rtclk;
struct clock_ymdhms dt;
- int diff;
int century;
int s;
@@ -646,10 +643,7 @@ resettodr(void)
bzero(&rtclk, sizeof(rtclk));
splx(s);
- diff = tz.tz_minuteswest * 60;
- if (tz.tz_dsttime)
- diff -= 3600;
- clock_secs_to_ymdhms(time_second - diff, &dt);
+ clock_secs_to_ymdhms(time_second, &dt);
rtclk[MC_SEC] = dectohexdec(dt.dt_sec);
rtclk[MC_MIN] = dectohexdec(dt.dt_min);
Index: arch/mac68k/mac68k/clock.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/arch/mac68k/mac68k/clock.c,v
retrieving revision 1.24
diff -u -p -r1.24 clock.c
--- arch/mac68k/mac68k/clock.c 14 Jul 2007 19:06:48 -0000 1.24
+++ arch/mac68k/mac68k/clock.c 23 Apr 2012 17:17:35 -0000
@@ -222,9 +222,8 @@ ugmt_2_pramt(t)
u_long t;
{
/* don't know how to open a file properly. */
- /* assume compiled timezone is correct. */
- return (t + DIFF19041970 - 60 * tz.tz_minuteswest);
+ return (t + DIFF19041970);
}
/*
@@ -235,7 +234,7 @@ static u_long
pramt_2_ugmt(t)
u_long t;
{
- return (t - DIFF19041970 + 60 * tz.tz_minuteswest);
+ return (t - DIFF19041970);
}
/*
@@ -273,13 +272,13 @@ inittodr(base)
mac68k_trust_pram = 0;
} else {
timbuf = pramt_2_ugmt(pram_readtime());
- if ((timbuf - (macos_boottime + 60 * tz.tz_minuteswest)) >
+ if ((timbuf - macos_boottime) >
10 * 60) {
#ifdef DIAGNOSTIC
printf("PRAM time does not appear"
" to have been read correctly.\n");
printf("PRAM: 0x%lx, macos_boottime: 0x%lx.\n",
- timbuf, macos_boottime + 60 * tz.tz_minuteswest);
+ timbuf, macos_boottime);
#endif
timbuf = macos_boottime;
mac68k_trust_pram = 0;
Index: arch/macppc/macppc/clock.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/arch/macppc/macppc/clock.c,v
retrieving revision 1.32
diff -u -p -r1.32 clock.c
--- arch/macppc/macppc/clock.c 29 Aug 2011 20:21:44 -0000 1.32
+++ arch/macppc/macppc/clock.c 23 Apr 2012 17:17:59 -0000
@@ -125,10 +125,6 @@ inittodr(time_t base)
} else {
int deltat;
- tv.tv_sec += tz.tz_minuteswest * 60;
- if (tz.tz_dsttime)
- tv.tv_sec -= 3600;
-
deltat = tv.tv_sec - base;
if (deltat < 0)
@@ -169,10 +165,6 @@ resettodr(void)
microtime(&tv);
if (time_write != NULL) {
- tv.tv_sec -= tz.tz_minuteswest * 60;
- if (tz.tz_dsttime) {
- tv.tv_sec += 3600;
- }
(*time_write)(tv.tv_sec);
}
}
Index: arch/socppc/socppc/clock.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/arch/socppc/socppc/clock.c,v
retrieving revision 1.9
diff -u -p -r1.9 clock.c
--- arch/socppc/socppc/clock.c 29 Aug 2011 20:21:44 -0000 1.9
+++ arch/socppc/socppc/clock.c 23 Apr 2012 17:18:12 -0000
@@ -107,10 +107,6 @@ inittodr(time_t base)
} else {
int deltat;
- tv.tv_sec += tz.tz_minuteswest * 60;
- if (tz.tz_dsttime)
- tv.tv_sec -= 3600;
-
deltat = tv.tv_sec - base;
if (deltat < 0)
Index: msdosfs/msdosfs_conv.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/msdosfs/msdosfs_conv.c,v
retrieving revision 1.14
diff -u -p -r1.14 msdosfs_conv.c
--- msdosfs/msdosfs_conv.c 13 Aug 2009 22:34:29 -0000 1.14
+++ msdosfs/msdosfs_conv.c 23 Apr 2012 17:14:57 -0000
@@ -107,8 +107,7 @@ unix2dostime(struct timespec *tsp, u_int
* If the time from the last conversion is the same as now, then
* skip the computations and use the saved result.
*/
- t = tsp->tv_sec - (tz.tz_minuteswest * 60)
- /* +- daylight saving time correction */ ;
+ t = tsp->tv_sec;
t &= ~1;
if (lasttime != t) {
lasttime = t;
@@ -218,8 +217,7 @@ dos2unixtime(u_int dd, u_int dt, u_int d
days += ((dd & DD_DAY_MASK) >> DD_DAY_SHIFT) - 1;
lastseconds = (days * 24 * 60 * 60) + SECONDSTO1980;
}
- tsp->tv_sec = seconds + lastseconds + (tz.tz_minuteswest * 60)
- /* -+ daylight saving time correction */ ;
+ tsp->tv_sec = seconds + lastseconds;
tsp->tv_nsec = (dh % 100) * 10000000;
}