summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2011-08-19 20:53:37 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2011-08-19 20:53:37 +0000
commit3eaace369c2ea90ba6052926d153d7bf9f3d5015 (patch)
tree012256fab4a6b163de1b3159e3b142813fe1508b
parent486308bc13638e05017928340aab97fd9ee1adaf (diff)
Use futimens() instead of futimes() to avoid converting to/from
struct timeval. OK guenther@
-rw-r--r--usr.sbin/cron/crontab.c18
-rw-r--r--usr.sbin/vipw/vipw.c15
2 files changed, 12 insertions, 21 deletions
diff --git a/usr.sbin/cron/crontab.c b/usr.sbin/cron/crontab.c
index 5efef36124e..ed53b581e27 100644
--- a/usr.sbin/cron/crontab.c
+++ b/usr.sbin/cron/crontab.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crontab.c,v 1.62 2011/05/19 15:00:17 phessler Exp $ */
+/* $OpenBSD: crontab.c,v 1.63 2011/08/19 20:53:36 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
@@ -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);
@@ -360,7 +354,7 @@ edit_cmd(void) {
perror(Filename);
exit(ERROR_EXIT);
}
- (void)futimes(t, tv);
+ (void)futimens(t, ts);
again:
rewind(NewCrontab);
if (ferror(NewCrontab)) {
@@ -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, ==)) {
if (swap_gids() < OK) {
perror("swapping gids");
exit(ERROR_EXIT);
diff --git a/usr.sbin/vipw/vipw.c b/usr.sbin/vipw/vipw.c
index a20421e047c..d75d29411a3 100644
--- a/usr.sbin/vipw/vipw.c
+++ b/usr.sbin/vipw/vipw.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vipw.c,v 1.15 2009/10/27 23:59:57 deraadt Exp $ */
+/* $OpenBSD: vipw.c,v 1.16 2011/08/19 20:53:36 millert Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
@@ -78,7 +78,7 @@ main(int argc, char *argv[])
pw_edit(0, NULL);
if (stat(_PATH_MASTERPASSWD_LOCK, &end))
pw_error(_PATH_MASTERPASSWD_LOCK, 1, 1);
- if (!timespeccmp(&begin.st_mtimespec, &end.st_mtimespec, -) &&
+ if (timespeccmp(&begin.st_mtimespec, &end.st_mtimespec, ==) &&
begin.st_size == end.st_size) {
warnx("no changes made");
pw_error((char *)NULL, 0, 0);
@@ -95,7 +95,7 @@ copyfile(int from, int to, struct stat *sb)
{
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 *sb)
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