]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Save a few bytes by moving close_fds to bind where it's really used.
authorRoy Marples <roy@marples.name>
Wed, 5 Nov 2008 13:09:18 +0000 (13:09 +0000)
committerRoy Marples <roy@marples.name>
Wed, 5 Nov 2008 13:09:18 +0000 (13:09 +0000)
bind.c
common.c
common.h

diff --git a/bind.c b/bind.c
index f05439b82dfa4619c90461810d0c41bb7d608bab..b8c4f9134bd771f9f869dc1171edf615a424043e 100644 (file)
--- a/bind.c
+++ b/bind.c
  * SUCH DAMAGE.
  */
 
+#include <sys/param.h>
+#include <fcntl.h>
+#ifdef BSD
+#  include <paths.h>
+#endif
 #include <signal.h>
 #include <stdlib.h>
 #include <syslog.h>
 #include "net.h"
 #include "signals.h"
 
+#ifndef _PATH_DEVNULL
+#  define _PATH_DEVNULL "/dev/null"
+#endif
+
 #ifndef THERE_IS_NO_FORK
 pid_t
 daemonise(void)
@@ -49,7 +58,7 @@ daemonise(void)
        sigset_t full;
        sigset_t old;
        char buf = '\0';
-       int sidpipe[2];
+       int sidpipe[2], fd;
 
        if (options & DHCPCD_DAEMONISED || !(options & DHCPCD_DAEMONISE))
                return 0;
@@ -72,7 +81,7 @@ daemonise(void)
                        close(sidpipe[0]);
                        write(sidpipe[1], &buf, 1);
                        close(sidpipe[1]);
-                       close_fds();
+
                        break;
                default:
                        signal_reset();
@@ -80,6 +89,13 @@ daemonise(void)
                        close(sidpipe[1]);
                        read(sidpipe[0], &buf, 1);
                        close(sidpipe[0]);
+                       if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
+                               dup2(fd, STDIN_FILENO);
+                               dup2(fd, STDOUT_FILENO);
+                               dup2(fd, STDERR_FILENO);
+                               if (fd > STDERR_FILENO)
+                                       close(fd);
+                       }
                        break;
        }
        /* Done with the fd now */
index 47082cbbb7b61c66c51314fef61297c50d3fd63e..bfd0b9c7547c5cde24212937d70c8aea361783e1 100644 (file)
--- a/common.c
+++ b/common.c
@@ -138,23 +138,6 @@ closefrom(int fd)
 }
 #endif
 
-/* Close our fd's */
-int
-close_fds(void)
-{
-       int fd;
-
-       if ((fd = open(_PATH_DEVNULL, O_RDWR)) == -1)
-               return -1;
-
-       dup2(fd, fileno(stdin));
-       dup2(fd, fileno(stdout));
-       dup2(fd, fileno(stderr));
-       if (fd > 2)
-               close(fd);
-       return 0;
-}
-
 int
 set_cloexec(int fd)
 {
index 1685c19f87b492857cce6aeb96c3ce1f14c1ee64..453d6b77031c2c5857da6f1dc0e36a856cc26021 100644 (file)
--- a/common.h
+++ b/common.h
@@ -84,7 +84,6 @@ size_t strlcpy(char *, const char *, size_t);
 int closefrom(int);
 #endif
 
-int close_fds(void);
 int set_cloexec(int);
 int set_nonblock(int);
 ssize_t get_line(char **, size_t *, FILE *);