diff options
author | Guillem Jover <guillem@debian.org> | 2008-01-21 04:25:33 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2008-01-21 04:25:33 +0200 |
commit | d9091a81b6dc449038821451696577ebbd270715 (patch) | |
tree | 8298687adda7ccdae07552d5100a8dfeb4baa395 /utils | |
parent | 4249b84f4de294ca6b7b2a39a888a43f9b73cb02 (diff) | |
download | dpkg-d9091a81b6dc449038821451696577ebbd270715.tar.gz |
s-s-d: Refactor max open fd into a new function and coalesce close loop
Diffstat (limited to 'utils')
-rw-r--r-- | utils/start-stop-daemon.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index d973cb007..cf34c6d5a 100644 --- a/utils/start-stop-daemon.c +++ b/utils/start-stop-daemon.c @@ -257,6 +257,15 @@ xgettimeofday(struct timeval *tv) if (gettimeofday(tv, NULL) != 0) fatal("gettimeofday failed: %s", strerror(errno)); } +static long +get_open_fd_max(void) +{ +#ifdef HAVE_GETDTABLESIZE + return getdtablesize(); +#else + return sysconf(_SC_OPEN_MAX); +#endif +} static void daemonize(void) @@ -1430,15 +1439,10 @@ main(int argc, char **argv) dup2(devnull_fd, 0); /* stdin */ dup2(devnull_fd, 1); /* stdout */ dup2(devnull_fd, 2); /* stderr */ -#if defined(OShpux) - /* Now close all extra fds */ - for (i = sysconf(_SC_OPEN_MAX) - 1; i >= 3; --i) - close(i); -#else + /* Now close all extra fds */ - for (i = getdtablesize() - 1; i >= 3; --i) + for (i = get_open_fd_max() - 1; i >= 3; --i) close(i); -#endif } execv(startas, argv); fatal("Unable to start %s: %s", startas, strerror(errno)); |