diff options
author | Darell Tan <darell.tan@gmail.com> | 2011-01-02 22:08:48 +0800 |
---|---|---|
committer | Darell Tan <darell.tan@gmail.com> | 2011-01-02 22:08:48 +0800 |
commit | 7076eac5b9e98e6565fe6777066b162b5ab52565 (patch) | |
tree | 8e3aa027b6c2b676703372860e9b08468a9b0f12 | |
parent | afe9bad84fb42082a340314db0fe51eb637b662e (diff) | |
download | mdns-repeater-7076eac5b9e98e6565fe6777066b162b5ab52565.tar.gz mdns-repeater-7076eac5b9e98e6565fe6777066b162b5ab52565.zip |
Replaced code to close() and re-open() fds.
-rw-r--r-- | mdns-repeater.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/mdns-repeater.c b/mdns-repeater.c index bc00bac..abce537 100644 --- a/mdns-repeater.c +++ b/mdns-repeater.c @@ -231,13 +231,15 @@ static void daemonize() { umask(0027); chdir("/"); - int i = getdtablesize(); - while (i--) + // close all std fd and reopen /dev/null for them + int i; + for (i = 0; i < 3; i++) { close(i); - - i = open("/dev/null", O_RDWR); - dup(i); - dup(i); + if (open("/dev/null", O_RDWR) != i) { + log_message(LOG_ERR, "unable to open /dev/null for fd %d", i); + exit(1); + } + } } static void show_help(const char *progname) { |