]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/vfscore: Correct behavior of utime(NULL)
authorAndrei Tatar <andrei@unikraft.io>
Mon, 24 Jul 2023 16:25:54 +0000 (18:25 +0200)
committerUnikraft <monkey@unikraft.io>
Mon, 7 Aug 2023 11:58:25 +0000 (11:58 +0000)
Previously, as a placeholder behavior, utime(NULL) would set the file
times to the epoch (1970-01-01 00:00 -0000) instead of the current time.
This change corrects this oversight, bringing the syscall in line with
expected and documented behavior.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #993

lib/vfscore/main.c

index ade7443206b6727c99b2f10e0886f3a0747252b4..721a1a39b799e458bc0a1c2f0c1d3c0fe768fcef 100644 (file)
@@ -2560,21 +2560,16 @@ int lutimes(const char *pathname, const struct timeval *times)
 UK_SYSCALL_R_DEFINE(int, utime, const char *, pathname,
                    const struct utimbuf *, t)
 {
-       struct timeval times[2];
-       times[0].tv_usec = 0;
-       times[1].tv_usec = 0;
-
-       if (!t) {
-               long int tsec = 0; /* FIXME: Use current time in seconds */
-               times[0].tv_sec = tsec;
-               times[1].tv_sec = tsec;
-       } else {
+       if (t) {
+               struct timeval times[2];
                times[0].tv_sec = t->actime;
+               times[0].tv_usec = 0;
                times[1].tv_sec = t->modtime;
+               times[1].tv_usec = 0;
+               return uk_syscall_r_utimes((long) pathname, (long) times);
+       } else {
+               return uk_syscall_r_utimes((long) pathname, (long) NULL);
        }
-
-       return uk_syscall_r_utimes((long) pathname,
-                                  (long) times);
 }
 
 UK_TRACEPOINT(trace_vfs_chmod, "\"%s\" 0%0o", const char*, mode_t);