aboutsummaryrefslogtreecommitdiff
path: root/initd
diff options
context:
space:
mode:
Diffstat (limited to 'initd')
-rw-r--r--initd/runsvc.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/initd/runsvc.c b/initd/runsvc.c
index c45f8ab..1963a09 100644
--- a/initd/runsvc.c
+++ b/initd/runsvc.c
@@ -53,24 +53,37 @@ static int setup_env(void)
static int close_all_files(void)
{
struct dirent *ent;
+ int fd, n;
DIR *dir;
- int fd;
dir = opendir(PROCFDDIR);
+
if (dir == NULL) {
- perror(PROCFDDIR);
- return -1;
- }
+ if (errno != ENOENT) {
+ perror(PROCFDDIR);
+ return -1;
+ }
- while ((ent = readdir(dir)) != NULL) {
- if (!isdigit(ent->d_name[0]))
- continue;
+ n = sysconf(_SC_OPEN_MAX);
+ if (n < 0) {
+ perror("getting maximum file descriptor count");
+ return -1;
+ }
+
+ for (fd = 0; fd < n; ++fd)
+ close(fd);
+ } else {
+ while ((ent = readdir(dir)) != NULL) {
+ if (!isdigit(ent->d_name[0]))
+ continue;
+
+ fd = atoi(ent->d_name);
+ close(fd);
+ }
- fd = atoi(ent->d_name);
- close(fd);
+ closedir(dir);
}
- closedir(dir);
return 0;
}