]> Dogcows Code - chaz/tar/commitdiff
tar: another --atime-preserve race fix
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 16 Sep 2010 17:46:27 +0000 (10:46 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 16 Sep 2010 17:47:07 +0000 (10:47 -0700)
* src/common.h (set_file_atime): Add parentfd arg.
* src/compare.c (diff_file): Use it.
* src/create.c (dump_file0): Likewise.  This closes yet another
race condition with symbolic links.
* src/misc.c (set_file_atime): Add parentfd arg.

src/common.h
src/compare.c
src/create.c
src/misc.c

index 8bd86407dbfda3c8b24a726a7f76724fc0b517dd..e0d8eb7a8aa90280620f82d7960e6ee89c88f614 100644 (file)
@@ -638,8 +638,8 @@ pid_t xfork (void);
 void xpipe (int fd[2]);
 
 void *page_aligned_alloc (void **ptr, size_t size);
-int set_file_atime (int fd, char const *file, struct timespec atime,
-                   int atflag);
+int set_file_atime (int fd, int parentfd, char const *file,
+                   struct timespec atime, int atflag);
 
 /* Module names.c.  */
 
index 6a873d7b131949bbc05fcb9634e78f90179fef5f..204c5dc16dd38f204bea980e84bc4045e78387c5 100644 (file)
@@ -244,7 +244,9 @@ diff_file (void)
              if (atime_preserve_option == replace_atime_preserve)
                {
                  struct timespec atime = get_stat_atime (&stat_data);
-                 if (set_file_atime (diff_handle, file_name, atime, 0) != 0)
+                 if (set_file_atime (diff_handle, AT_FDCWD, file_name,
+                                     atime, 0)
+                     != 0)
                    utime_error (file_name);
                }
 
index 6eedb2efc6e1dafb668311d8ffe01cbd45287e40..0d22e9601d07164ebbef67923a6090b738d5ffe6 100644 (file)
@@ -1793,7 +1793,9 @@ dump_file0 (struct tar_stat_info *st, char const *name, char const *p)
              set_exit_status (TAREXIT_DIFFERS);
            }
          else if (atime_preserve_option == replace_atime_preserve
-                  && set_file_atime (fd, p, st->atime, fstatat_flags) != 0)
+                  && (set_file_atime (fd, parentfd, name,
+                                      st->atime, fstatat_flags)
+                      != 0))
            utime_error (p);
        }
 
index 1cf0c3b666054da93446f44ae94dff1ae53dc3c0..64b1b2b3ea8b4104cff3a85d4d3ba14312b33a4b 100644 (file)
@@ -628,15 +628,17 @@ fd_utimensat (int fd, int parentfd, char const *file,
   return utimensat (parentfd, file, ts, atflag);
 }
 
-/* Set FD's (i.e., FILE's) access time to ATIME.
-   ATFLAG controls symbolic-link following, in the style of openat.  */
+/* Set FD's (i.e., assuming the working directory is PARENTFD, FILE's)
+   access time to ATIME.  ATFLAG controls symbolic-link following, in
+   the style of openat.  */
 int
-set_file_atime (int fd, char const *file, struct timespec atime, int atflag)
+set_file_atime (int fd, int parentfd, char const *file, struct timespec atime,
+               int atflag)
 {
   struct timespec ts[2];
   ts[0] = atime;
   ts[1].tv_nsec = UTIME_OMIT;
-  return fd_utimensat (fd, AT_FDCWD, file, ts, atflag);
+  return fd_utimensat (fd, parentfd, file, ts, atflag);
 }
 
 /* A description of a working directory.  */
This page took 0.022984 seconds and 4 git commands to generate.