summaryrefslogtreecommitdiffstats
path: root/usr.sbin/vipw
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2001-08-19 18:30:38 +0000
committermillert <millert@openbsd.org>2001-08-19 18:30:38 +0000
commit610cf93a59fe06efe097d05bc8d4310874ff34d4 (patch)
tree951a7c43893643ebe518eba1e9afffa08be01ca8 /usr.sbin/vipw
parent$%&@#! (diff)
downloadwireguard-openbsd-610cf93a59fe06efe097d05bc8d4310874ff34d4.tar.xz
wireguard-openbsd-610cf93a59fe06efe097d05bc8d4310874ff34d4.zip
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);
}