From 0444afa8cff9f9055419f0364fa0992f9081bc28 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Sat, 16 Feb 2019 05:30:29 +0000 Subject: use gettimeofday + TIMEVAL_TO_TIMESPEC to create timespec with better than 1 sec resolution ok benno --- usr.bin/rsync/receiver.c | 8 +++++--- usr.bin/rsync/uploader.c | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/usr.bin/rsync/receiver.c b/usr.bin/rsync/receiver.c index 2a33eb1fbf1..935432beb58 100644 --- a/usr.bin/rsync/receiver.c +++ b/usr.bin/rsync/receiver.c @@ -1,4 +1,4 @@ -/* $Id: receiver.c,v 1.10 2019/02/16 05:25:09 deraadt Exp $ */ +/* $Id: receiver.c,v 1.11 2019/02/16 05:30:28 deraadt Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons @@ -75,8 +75,10 @@ rsync_set_metadata(struct sess *sess, int newfile, /* Conditionally adjust file modification time. */ if (sess->opts->preserve_times) { - tv[0].tv_sec = time(NULL); - tv[0].tv_nsec = 0; + struct timeval now; + + gettimeofday(&now, NULL); + TIMEVAL_TO_TIMESPEC(&now, &tv[0]); tv[1].tv_sec = f->st.mtime; tv[1].tv_nsec = 0; if (futimens(fd, tv) == -1) { diff --git a/usr.bin/rsync/uploader.c b/usr.bin/rsync/uploader.c index 81c6fd88f64..7f2d52e3c17 100644 --- a/usr.bin/rsync/uploader.c +++ b/usr.bin/rsync/uploader.c @@ -1,4 +1,4 @@ -/* $Id: uploader.c,v 1.7 2019/02/16 05:06:30 deraadt Exp $ */ +/* $Id: uploader.c,v 1.8 2019/02/16 05:30:28 deraadt Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -242,8 +242,10 @@ pre_link(struct upload *p, struct sess *sess) */ if (sess->opts->preserve_times) { - tv[0].tv_sec = time(NULL); - tv[0].tv_nsec = 0; + struct timeval now; + + gettimeofday(&now, NULL); + TIMEVAL_TO_TIMESPEC(&now, &tv[0]); tv[1].tv_sec = f->st.mtime; tv[1].tv_nsec = 0; rc = utimensat(p->rootfd, f->path, tv, AT_SYMLINK_NOFOLLOW); -- cgit v1.2.3