patch to avoid race condition in rsync 2.5.6

Petter Reinholdtsen pere at hungry.com
Wed May 21 00:40:58 EST 2003


There is a small race condition in rsync 2.5.6.  When the transfer is
finished, and the file is moved into place, there is a short time
period where the new file is in place with the wrong permissions.
When using rsync on a busy email server to replace the exim config
file with a new file, exim will produce several complaints in that
short period.  This small patch fixes the problem, by making sure the
new file is given the correct permissions before it is moved into
place.

Please include this change in the next version of rsync.

diff -ur src-2.5.6/rsync.c src-2.5.6-local/rsync.c
--- src-2.5.6/rsync.c   2001-12-20 16:33:13.000000000 +0100
+++ src-2.5.6-local/rsync.c     2003-05-20 15:17:56.000000000 +0200
@@ -237,6 +237,9 @@
        if (make_backups && !make_backup(fname))
                return;

+       /* change permissions before putting the file in place */
+       set_perms(fnametmp,file,NULL,0);
+
        /* move tmp file over real file */
        if (robust_rename(fnametmp,fname) != 0) {
                if (errno == EXDEV) {
@@ -253,7 +256,5 @@
                                fnametmp,fname,strerror(errno));
                }
                do_unlink(fnametmp);
-       } else {
-               set_perms(fname,file,NULL,0);
        }
 }

The call to set_perms() inside the if-block is to make sure the
permissions are still correct even on strange (and to me known)
platforms where the permissions are reset when a file is renamed.  I'm
not sure if it is needed, but decied to keep it there just in case.



More information about the rsync mailing list