pkgsrc - initial commit
[pkgsrc.git] / archivers / gcpio / patches / patch-ao
1 $NetBSD: patch-ao,v 1.1 2005/11/03 19:38:50 adrianp Exp $
2
3 --- src/copypass.c.orig 2004-09-06 13:09:04.000000000 +0100
4 +++ src/copypass.c
5 @@ -181,19 +181,25 @@ process_copy_pass ()
6                 }
7               if (close (in_file_des) < 0)
8                 error (0, errno, "%s", input_name.ds_string);
9 -             if (close (out_file_des) < 0)
10 -               error (0, errno, "%s", output_name.ds_string);
11 -
12 +             /*
13 +              *  Avoid race condition.
14 +              *  Set chown and chmod before closing the file desc.
15 +              *  pvrabec@redhat.com
16 +              */
17               /* Set the attributes of the new file.  */
18               if (!no_chown_flag)
19 -               if ((chown (output_name.ds_string,
20 +               if ((fchown (out_file_des,
21                             set_owner_flag ? set_owner : in_file_stat.st_uid,
22                       set_group_flag ? set_group : in_file_stat.st_gid) < 0)
23                     && errno != EPERM)
24                   error (0, errno, "%s", output_name.ds_string);
25               /* chown may have turned off some permissions we wanted. */
26 -             if (chmod (output_name.ds_string, in_file_stat.st_mode) < 0)
27 +             if (fchmod (out_file_des, in_file_stat.st_mode) < 0)
28 +               error (0, errno, "%s", output_name.ds_string);
29 +               
30 +             if (close (out_file_des) < 0)
31                 error (0, errno, "%s", output_name.ds_string);
32 +
33               if (reset_time_flag)
34                 {
35                   times.actime = in_file_stat.st_atime;