I always forget about the special value shortcut for utimes(2) et al. This is equivalent/simpler/more portable.
ok? Index: receiver.c =================================================================== RCS file: /cvs/src/usr.bin/rsync/receiver.c,v retrieving revision 1.19 diff -u -p -r1.19 receiver.c --- receiver.c 18 Feb 2019 21:55:27 -0000 1.19 +++ receiver.c 22 Mar 2019 15:59:24 -0000 @@ -47,7 +47,7 @@ rsync_set_metadata(struct sess *sess, in { uid_t uid = (uid_t)-1; gid_t gid = (gid_t)-1; - struct timespec tv[2]; + struct timespec ts[2]; /* * Conditionally adjust identifiers. @@ -76,13 +76,10 @@ rsync_set_metadata(struct sess *sess, in /* Conditionally adjust file modification time. */ if (sess->opts->preserve_times) { - 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) { + ts[0].tv_nsec = UTIME_NOW; + ts[1].tv_sec = f->st.mtime; + ts[1].tv_nsec = 0; + if (futimens(fd, ts) == -1) { ERR(sess, "%s: futimens", path); return 0; } @@ -108,7 +105,7 @@ rsync_set_metadata_at(struct sess *sess, { uid_t uid = (uid_t)-1; gid_t gid = (gid_t)-1; - struct timespec tv[2]; + struct timespec ts[2]; /* * Conditionally adjust identifiers. @@ -138,13 +135,10 @@ rsync_set_metadata_at(struct sess *sess, /* Conditionally adjust file modification time. */ if (sess->opts->preserve_times) { - 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 (utimensat(rootfd, path, tv, AT_SYMLINK_NOFOLLOW) == -1) { + ts[0].tv_nsec = UTIME_NOW; + ts[1].tv_sec = f->st.mtime; + ts[1].tv_nsec = 0; + if (utimensat(rootfd, path, ts, AT_SYMLINK_NOFOLLOW) == -1) { ERR(sess, "%s: utimensat", path); return 0; }