eb062e449facb59285b50b1fd418e9d00679ace2
[vuplus_openvuplus_3.0] / meta-openvuplus / recipes-connectivity / autofs / autofs-4.1.4 / 079_no_unlink_upstream.patch
1 #!/bin/sh /usr/share/dpatch/dpatch-run
2 ## 079_no_unlink_upstream.dpatch
3 ##
4 ## DP: No description.
5
6 @DPATCH@
7
8 diff -Naur .B/daemon/automount.c .A/daemon/automount.c
9 --- .B/daemon/automount.c       2007-01-07 21:36:36.000000000 +0000
10 +++ .A/daemon/automount.c       2007-01-07 21:36:37.000000000 +0000
11 @@ -232,16 +232,38 @@
12  static int rm_unwanted_fn(const char *file, const struct stat *st, int when, void *arg)
13  {
14         int rmsymlink = *(int *) arg;
15 +       struct stat newst;
16  
17         if (when == 0) {
18                 if (st->st_dev != ap.dev)
19                         return 0;
20 -       } else {
21 -               info("rm_unwanted: %s\n", file);
22 -               if (S_ISDIR(st->st_mode))
23 -                       rmdir(file);
24 -               else if (!S_ISLNK(st->st_mode) || rmsymlink)
25 -                       unlink(file);
26 +               return 1;
27 +       }
28 +
29 +       if (lstat(file, &newst)) {
30 +               crit ("rm_unwanted: unable to stat file, possible race "
31 +                     "condition.");
32 +               return 0;
33 +       }
34 +
35 +       if (newst.st_dev != ap.dev) {
36 +               crit ("rm_unwanted: file %s has the wrong device, possible "
37 +                     "race condition.",file);
38 +               return 0;
39 +       }
40 +
41 +       if (S_ISDIR(newst.st_mode)) {
42 +               if (rmdir(file)) {
43 +                       info ("rm_unwanted: unable to remove directory"
44 +                             " %s", file);
45 +                       return 0;
46 +               }
47 +       } else if (S_ISREG(newst.st_mode)) {
48 +               crit ("rm_unwanted: attempting to remove files from a mounted "
49 +                     "directory.");
50 +               return 0;
51 +       } else if (S_ISLNK(newst.st_mode) && rmsymlink) {
52 +               unlink(file);
53         }
54  
55         return 1;