summaryrefslogtreecommitdiff
path: root/usr.sbin/vipw
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-08-19 18:30:39 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-08-19 18:30:39 +0000
commitd0eae1b3c9b6b0068e9e2920f5ab4c32f58af829 (patch)
tree8f96f8b466cdb8003f15e18c8b785366bf4bee34 /usr.sbin/vipw
parent71fd3643a55f28fd036318d785605467bc355b1c (diff)
Better file change detection:
o when copying to temp file set utimes on temp file equal to original o use st_mtimespec instead of st_mtime for better granularity
Diffstat (limited to 'usr.sbin/vipw')
-rw-r--r--usr.sbin/vipw/vipw.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/usr.sbin/vipw/vipw.c b/usr.sbin/vipw/vipw.c
index 6a2d07b228a..9d32fa659dc 100644
--- a/usr.sbin/vipw/vipw.c
+++ b/usr.sbin/vipw/vipw.c
@@ -43,7 +43,7 @@ static char copyright[] =
static char sccsid[] = "@(#)vipw.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
-#include <sys/types.h>
+#include <sys/time.h>
#include <sys/stat.h>
#include <err.h>
@@ -96,7 +96,7 @@ main(argc, argv)
pw_edit(0, NULL);
if (stat(_PATH_MASTERPASSWD_LOCK, &end))
pw_error(_PATH_MASTERPASSWD_LOCK, 1, 1);
- if (begin.st_mtime == end.st_mtime &&
+ if (!timespeccmp(&begin.st_mtimespec, &end.st_mtimespec, -) &&
begin.st_size == end.st_size) {
warnx("no changes made");
pw_error((char *)NULL, 0, 0);
@@ -114,19 +114,28 @@ copyfile(from, to)
{
int nr, nw, off;
char buf[8*1024];
+ struct stat sb;
+ struct timeval tv[2];
+ if (fstat(from, &sb) == -1)
+ pw_error(_PATH_MASTERPASSWD, 1, 1);
while ((nr = read(from, buf, sizeof(buf))) > 0)
for (off = 0; off < nr; nr -= nw, off += nw)
if ((nw = write(to, buf + off, nr)) < 0)
pw_error(_PATH_MASTERPASSWD_LOCK, 1, 1);
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);
}
void
usage()
{
+ extern char *__progname;
- (void)fprintf(stderr, "usage: vipw\n");
+ (void)fprintf(stderr, "usage: %s\n", __progname);
exit(1);
}