summaryrefslogtreecommitdiff
path: root/openbsd-compat/bsd-closefrom.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2006-08-18 18:51:20 +1000
committerDarren Tucker <dtucker@zip.com.au>2006-08-18 18:51:20 +1000
commitd018b2e9c88f6669c68f3343dbbf53e6084e8ff7 (patch)
tree11a26d6f521581ed75a6c45d225690757dcd8ca3 /openbsd-compat/bsd-closefrom.c
parentc889ffdbc6329f21d2437b3c3d17eba0960969fc (diff)
- (dtucker) [configure.ac openbsd-compat/bsd-closefrom.c] Resync with
closefrom.c from sudo.
Diffstat (limited to 'openbsd-compat/bsd-closefrom.c')
-rw-r--r--openbsd-compat/bsd-closefrom.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/openbsd-compat/bsd-closefrom.c b/openbsd-compat/bsd-closefrom.c
index e7a521e43..4b72920d6 100644
--- a/openbsd-compat/bsd-closefrom.c
+++ b/openbsd-compat/bsd-closefrom.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2004 Todd C. Miller <Todd.Miller@courtesan.com> 2 * Copyright (c) 2004-2005 Todd C. Miller <Todd.Miller@courtesan.com>
3 * 3 *
4 * Permission to use, copy, modify, and distribute this software for any 4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above 5 * purpose with or without fee is hereby granted, provided that the above
@@ -52,12 +52,19 @@
52#endif 52#endif
53 53
54#ifndef lint 54#ifndef lint
55static const char sudorcsid[] = "$Sudo: closefrom.c,v 1.6 2004/06/01 20:51:56 millert Exp $"; 55__unused static const char rcsid[] = "$Sudo: closefrom.c,v 1.11 2006/08/17 15:26:54 millert Exp $";
56#endif /* lint */ 56#endif /* lint */
57 57
58/* 58/*
59 * Close all file descriptors greater than or equal to lowfd. 59 * Close all file descriptors greater than or equal to lowfd.
60 */ 60 */
61#ifdef HAVE_FCNTL_CLOSEM
62void
63closefrom(int lowfd)
64{
65 (void) fcntl(lowfd, F_CLOSEM, 0);
66}
67#else
61void 68void
62closefrom(int lowfd) 69closefrom(int lowfd)
63{ 70{
@@ -70,7 +77,7 @@ closefrom(int lowfd)
70 77
71 /* Check for a /proc/$$/fd directory. */ 78 /* Check for a /proc/$$/fd directory. */
72 len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid()); 79 len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid());
73 if (len >= 0 && (u_int)len <= sizeof(fdpath) && (dirp = opendir(fdpath))) { 80 if (len > 0 && (size_t)len <= sizeof(fdpath) && (dirp = opendir(fdpath))) {
74 while ((dent = readdir(dirp)) != NULL) { 81 while ((dent = readdir(dirp)) != NULL) {
75 fd = strtol(dent->d_name, &endp, 10); 82 fd = strtol(dent->d_name, &endp, 10);
76 if (dent->d_name != endp && *endp == '\0' && 83 if (dent->d_name != endp && *endp == '\0' &&
@@ -79,10 +86,6 @@ closefrom(int lowfd)
79 } 86 }
80 (void) closedir(dirp); 87 (void) closedir(dirp);
81 } else 88 } else
82#elif defined(USE_FCNTL_CLOSEM)
83 if (fcntl(lowfd, F_CLOSEM, 0) != -1) {
84 return;
85 } else
86#endif 89#endif
87 { 90 {
88 /* 91 /*
@@ -102,6 +105,5 @@ closefrom(int lowfd)
102 (void) close((int) fd); 105 (void) close((int) fd);
103 } 106 }
104} 107}
105 108#endif /* !HAVE_FCNTL_CLOSEM */
106#endif /* HAVE_CLOSEFROM */ 109#endif /* HAVE_CLOSEFROM */
107