Diff for /embedaddon/sudo/compat/closefrom.c between versions 1.1.1.3 and 1.1.1.4

version 1.1.1.3, 2013/10/14 07:56:33 version 1.1.1.4, 2014/06/15 16:12:54
Line 31 Line 31
 # endif  # endif
 #endif /* STDC_HEADERS */  #endif /* STDC_HEADERS */
 #include <fcntl.h>  #include <fcntl.h>
   #include <limits.h>
 #ifdef HAVE_PSTAT_GETPROC  #ifdef HAVE_PSTAT_GETPROC
 # include <sys/param.h>  # include <sys/param.h>
 # include <sys/pstat.h>  # include <sys/pstat.h>
Line 55 Line 56
   
 #include "missing.h"  #include "missing.h"
   
#ifndef HAVE_FCNTL_CLOSEM#if defined(HAVE_FCNTL_CLOSEM) && !defined(HAVE_DIRFD)
# ifndef HAVE_DIRFD# define closefrom        closefrom_fallback
#   define closefrom_fallback      closefrom 
# endif 
 #endif  #endif
   
 /*  /*
  * Close all file descriptors greater than or equal to lowfd.   * Close all file descriptors greater than or equal to lowfd.
 * This is the expensive (ballback) method. * This is the expensive (fallback) method.
  */   */
 void  void
 closefrom_fallback(int lowfd)  closefrom_fallback(int lowfd)
Line 85  closefrom_fallback(int lowfd) Line 84  closefrom_fallback(int lowfd)
   
     for (fd = lowfd; fd < maxfd; fd++) {      for (fd = lowfd; fd < maxfd; fd++) {
 #ifdef __APPLE__  #ifdef __APPLE__
        /* Avoid potential crash with libdispatch when we close its fds. */        /* Avoid potential libdispatch crash when we close its fds. */
        (void) fcntl(fd, F_SETFD, FD_CLOEXEC);        (void) fcntl((int) fd, F_SETFD, FD_CLOEXEC);
 #else  #else
         (void) close((int) fd);          (void) close((int) fd);
 #endif  #endif
Line 122  closefrom(int lowfd) Line 121  closefrom(int lowfd)
 void  void
 closefrom(int lowfd)  closefrom(int lowfd)
 {  {
    struct dirent *dent;    const char *path;
     DIR *dirp;      DIR *dirp;
     char *endp;  
     long fd;  
   
    /* Use /proc/self/fd directory if it exists. */    /* Use /proc/self/fd (or /dev/fd on FreeBSD) if it exists. */
    if ((dirp = opendir("/proc/self/fd")) != NULL) {# 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) {          while ((dent = readdir(dirp)) != NULL) {
            fd = strtol(dent->d_name, &endp, 10);            const char *errstr;
            if (dent->d_name != endp && *endp == '\0' &&            int fd = strtonum(dent->d_name, lowfd, INT_MAX, &errstr);
                fd >= 0 && fd < INT_MAX && fd >= lowfd && fd != dirfd(dirp))            if (errstr == NULL && fd != dirfd(dirp)) {
                (void) close((int) fd);# ifdef __APPLE__
                 /* Avoid potential libdispatch crash when we close its fds. */
                 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
 # else
                 (void) close(fd);
 # endif
             }
         }          }
         (void) closedir(dirp);          (void) closedir(dirp);
     } else      } else

Removed from v.1.1.1.3  
changed lines
  Added in v.1.1.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>