On Thu, 18 Aug 2011 09:32:36 PDT, Matthew Dempsky wrote:
> I think cron or crontab had some code that could be similarly
> cleaned up too.
Yup.
- todd
Index: usr.sbin/vipw/vipw.c
===================================================================
RCS file: /home/cvs/openbsd/src/usr.sbin/vipw/vipw.c,v
retrieving revision 1.15
diff -u -p -u -r1.15 vipw.c
--- usr.sbin/vipw/vipw.c 27 Oct 2009 23:59:57 -0000 1.15
+++ usr.sbin/vipw/vipw.c 18 Aug 2011 19:04:44 -0000
@@ -95,7 +95,7 @@ copyfile(int from, int to, struct stat *
{
int nr, nw, off;
char buf[8*1024];
- struct timeval tv[2];
+ struct timespec ts[2];
if (fstat(from, sb) == -1)
pw_error(_PATH_MASTERPASSWD, 1, 1);
@@ -106,12 +106,9 @@ copyfile(int from, int to, struct stat *
if (nr < 0)
pw_error(_PATH_MASTERPASSWD, 1, 1);
- TIMESPEC_TO_TIMEVAL(&tv[0], &sb->st_atimespec);
- TIMESPEC_TO_TIMEVAL(&tv[1], &sb->st_mtimespec);
- (void)futimes(to, tv);
-
- /* Make tv_nsec the same precision as tv_usec so it compares OK. */
- TIMEVAL_TO_TIMESPEC(&tv[1], &sb->st_mtimespec);
+ ts[0] = sb->st_atim;
+ ts[1] = sb->st_mtim;
+ (void)futimens(to, ts);
}
void
Index: usr.sbin/cron/crontab.c
===================================================================
RCS file: /home/cvs/openbsd/src/usr.sbin/cron/crontab.c,v
retrieving revision 1.62
diff -u -p -u -r1.62 crontab.c
--- usr.sbin/cron/crontab.c 19 May 2011 15:00:17 -0000 1.62
+++ usr.sbin/cron/crontab.c 18 Aug 2011 19:06:09 -0000
@@ -286,8 +286,7 @@ edit_cmd(void) {
FILE *f;
int t;
struct stat statbuf, xstatbuf;
- struct timespec mtimespec;
- struct timeval tv[2];
+ struct timespec ts[2];
log_it(RealUser, Pid, "BEGIN EDIT", User);
if (snprintf(n, sizeof n, "%s/%s", SPOOL_DIR, User) >= sizeof(n)) {
@@ -311,13 +310,8 @@ edit_cmd(void) {
perror("fstat");
goto fatal;
}
- /*
- * Note that timespec has higher precision than timeval so we
- * store mtimespec using timeval precision so we can compare later.
- */
- TIMESPEC_TO_TIMEVAL(&tv[0], &statbuf.st_atimespec);
- TIMESPEC_TO_TIMEVAL(&tv[1], &statbuf.st_mtimespec);
- TIMEVAL_TO_TIMESPEC(&tv[1], &mtimespec);
+ ts[0] = statbuf.st_atim;
+ ts[1] = statbuf.st_mtim;
/* Turn off signals. */
(void)signal(SIGHUP, SIG_IGN);
@@ -395,7 +389,7 @@ edit_cmd(void) {
perror("fstat");
goto fatal;
}
- if (timespeccmp(&mtimespec, &statbuf.st_mtimespec, -) == 0) {
+ if (timespeccmp(&ts[1], &statbuf.st_mtim, -) == 0) {
if (swap_gids() < OK) {
perror("swapping gids");
exit(ERROR_EXIT);