Add Apple-specific patches against sudo-1.7.10p7
[sudo-osx-update.git] / patches / 0009-Do-not-close-fds-on-OS-X.patch.txt
blob8a8fd5ca3b0db370588852d05ed04a589f22ca22
1 Subject: [PATCH] Do not close fds on OS X
3 The OS X version of sudo sets the close-on-exec flag for file descriptors
4 to be closed rather than actually closing them.  It uses an opendir to
5 /dev/fd instead of /proc/self/fd to enumerate the open fd values if
6 possible rather than blindly trying them all.
7 ---
8  closefrom.c | 12 ++++++++++--
9  1 file changed, 10 insertions(+), 2 deletions(-)
11 diff --git a/closefrom.c b/closefrom.c
12 index 68da392d..514311e5 100644
13 --- a/closefrom.c
14 +++ b/closefrom.c
15 @@ -79,7 +79,11 @@ closefrom_fallback(lowfd)
16         maxfd = OPEN_MAX;
18      for (fd = lowfd; fd < maxfd; fd++)
19 +#if 6497333
20 +       (void) fcntl((int) fd, F_SETFD, 1);
21 +#else
22         (void) close((int) fd);
23 +#endif
24  }
26  /*
27 @@ -105,13 +109,17 @@ closefrom(lowfd)
28      char *endp;
29      long fd;
31 -    /* Use /proc/self/fd directory if it exists. */
32 -    if ((dirp = opendir("/proc/self/fd")) != NULL) {
33 +    /* Use /dev/fd directory if it exists. */
34 +    if ((dirp = opendir("/dev/fd")) != NULL) {
35         while ((dent = readdir(dirp)) != NULL) {
36             fd = strtol(dent->d_name, &endp, 10);
37             if (dent->d_name != endp && *endp == '\0' &&
38                 fd >= 0 && fd < INT_MAX && fd >= lowfd && fd != dirfd(dirp))
39 +#if 6497333
40 +               (void) fcntl((int) fd, F_SETFD, 1);
41 +#else
42                 (void) close((int) fd);
43 +#endif
44         }
45         (void) closedir(dirp);
46      } else
47 -- 
48 1.8.3