diff options
-rw-r--r-- | support/nfs/closeall.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/support/nfs/closeall.c b/support/nfs/closeall.c index cc7fb3b..38fb162 100644 --- a/support/nfs/closeall.c +++ b/support/nfs/closeall.c @@ -7,19 +7,24 @@ #include <unistd.h> #include <stdlib.h> #include <dirent.h> +#include <errno.h> void closeall(int min) { + char *endp; + long n; DIR *dir = opendir("/proc/self/fd"); + if (dir != NULL) { int dfd = dirfd(dir); struct dirent *d; while ((d = readdir(dir)) != NULL) { - char *endp; - long n = strtol(d->d_name, &endp, 10); - if (*endp != '\0' && n >= min && n != dfd) + errno = 0; + n = strtol(d->d_name, &endp, 10); + if (!errno && *endp == '\0' && endp != d->d_name && + n >= min && n != dfd) (void) close(n); } closedir(dir); |