]> granicus.if.org Git - sudo/commitdiff
Use /dev/fd in closefrom() on FreeBSD < 8.0 and Mac OS X.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 28 Feb 2014 22:05:19 +0000 (15:05 -0700)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 28 Feb 2014 22:05:19 +0000 (15:05 -0700)
--HG--
branch : 1.7

closefrom.c

index 1438e9ef8abe95123ba3bd23ec2b09812df9923e..1d2d2ca5d1f188275a93811a1f16ae11fed72042 100644 (file)
@@ -125,13 +125,19 @@ void
 closefrom(lowfd)
     int lowfd;
 {
-    struct dirent *dent;
+    const char *path;
     DIR *dirp;
     char *endp;
     long fd;
 
-    /* Use /proc/self/fd directory if it exists. */
-    if ((dirp = opendir("/proc/self/fd")) != NULL) {
+    /* Use /proc/self/fd (or /dev/fd on FreeBSD) if it exists. */
+# if defined(__FreeBSD__) || defined(__APPLE__)
+    path = "/dev/fd";
+# else
+    path = "/proc/self/fd";
+# endif
+    if ((dirp = opendir(path)) != NULL) {
+       struct dirent *dent;
        while ((dent = readdir(dirp)) != NULL) {
            fd = strtol(dent->d_name, &endp, 10);
            if (dent->d_name != endp && *endp == '\0' &&