Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | #include "includes.h" | - |
18 | | - |
19 | #ifndef HAVE_CLOSEFROM | - |
20 | | - |
21 | #include <sys/types.h> | - |
22 | #include <sys/param.h> | - |
23 | #include <unistd.h> | - |
24 | #include <stdio.h> | - |
25 | #ifdef HAVE_FCNTL_H | - |
26 | # include <fcntl.h> | - |
27 | #endif | - |
28 | #include <limits.h> | - |
29 | #include <stdlib.h> | - |
30 | #include <stddef.h> | - |
31 | #include <string.h> | - |
32 | #include <unistd.h> | - |
33 | #ifdef HAVE_DIRENT_H | - |
34 | # include <dirent.h> | - |
35 | # define NAMLEN(dirent) strlen((dirent)->d_name) | - |
36 | #else | - |
37 | # define dirent direct | - |
38 | # define NAMLEN(dirent) (dirent)->d_namlen | - |
39 | # ifdef HAVE_SYS_NDIR_H | - |
40 | # include <sys/ndir.h> | - |
41 | # endif | - |
42 | # ifdef HAVE_SYS_DIR_H | - |
43 | # include <sys/dir.h> | - |
44 | # endif | - |
45 | # ifdef HAVE_NDIR_H | - |
46 | # include <ndir.h> | - |
47 | # endif | - |
48 | #endif | - |
49 | | - |
50 | #ifndef OPEN_MAX | - |
51 | # define OPEN_MAX 256 | - |
52 | #endif | - |
53 | | - |
54 | #if 0 | - |
55 | __unused static const char rcsid[] = "$Sudo: closefrom.c,v 1.11 2006/08/17 15:26:54 millert Exp $"; | - |
56 | #endif /* lint */ | - |
57 | | - |
58 | | - |
59 | | - |
60 | | - |
61 | #ifdef HAVE_FCNTL_CLOSEM | - |
62 | void | - |
63 | closefrom(int lowfd) | - |
64 | { | - |
65 | (void) fcntl(lowfd, F_CLOSEM, 0); | - |
66 | } | - |
67 | #else | - |
68 | void | - |
69 | closefrom(int lowfd) | - |
70 | { | - |
71 | long fd, maxfd; | - |
72 | #if defined(HAVE_DIRFD) && defined(HAVE_PROC_PID) | - |
73 | char fdpath[PATH_MAX], *endp; | - |
74 | struct dirent *dent; | - |
75 | DIR *dirp; | - |
76 | int len; | - |
77 | | - |
78 | | - |
79 | len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid()); | - |
80 | if (len > 0 && (size_t)len < sizeof(fdpath) && (dirp = opendir(fdpath))) {TRUE | evaluated 2 times by 1 test | FALSE | never evaluated |
TRUE | evaluated 2 times by 1 test | FALSE | never evaluated |
TRUE | evaluated 2 times by 1 test | FALSE | never evaluated |
| 0-2 |
81 | while ((dent = readdir(dirp)) != NULL) {TRUE | evaluated 12 times by 1 test | FALSE | evaluated 2 times by 1 test |
| 2-12 |
82 | fd = strtol(dent->d_name, &endp, 10); | - |
83 | if (dent->d_name != endp && *endp == '\0' &&TRUE | evaluated 8 times by 1 test | FALSE | evaluated 4 times by 1 test |
TRUE | evaluated 8 times by 1 test | FALSE | never evaluated |
| 0-8 |
84 | fd >= 0 && fd < INT_MAX && fd >= lowfd && fd != dirfd(dirp))TRUE | evaluated 8 times by 1 test | FALSE | never evaluated |
TRUE | evaluated 8 times by 1 test | FALSE | never evaluated |
TRUE | evaluated 2 times by 1 test | FALSE | evaluated 6 times by 1 test |
TRUE | never evaluated | FALSE | evaluated 2 times by 1 test |
| 0-8 |
85 | (void) close((int) fd); never executed: (void) close((int) fd); | 0 |
86 | }executed 12 times by 1 test: end of block | 12 |
87 | (void) closedir(dirp); | - |
88 | } elseexecuted 2 times by 1 test: end of block | 2 |
89 | #endif | - |
90 | { | - |
91 | | - |
92 | | - |
93 | | - |
94 | | - |
95 | | - |
96 | #ifdef HAVE_SYSCONF | - |
97 | maxfd = sysconf(_SC_OPEN_MAX); | - |
98 | #else | - |
99 | maxfd = getdtablesize(); | - |
100 | #endif /* HAVE_SYSCONF */ | - |
101 | if (maxfd < 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
102 | maxfd = OPEN_MAX; never executed: maxfd = 256; | 0 |
103 | | - |
104 | for (fd = lowfd; fd < maxfd; fd++)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
105 | (void) close((int) fd); never executed: (void) close((int) fd); | 0 |
106 | } never executed: end of block | 0 |
107 | } | - |
108 | #endif /* !HAVE_FCNTL_CLOSEM */ | - |
109 | #endif /* HAVE_CLOSEFROM */ | - |
| | |