Various cleanups I made while going through Erik Hovland's patch submissions,
[oweals/busybox.git] / networking / udhcp / signalpipe.c
index 4f3292b9db3dee523739f09c787bdc751e99cad9..e973ff6b2fc953767aa96d322a27354863c2a796 100644 (file)
@@ -1,8 +1,8 @@
 /* signalpipe.c
  *
- * Signal pipe infastructure. A reliable way of delivering signals.
+ * Signal pipe infrastructure. A reliable way of delivering signals.
  *
- * Russ Dill <Russ.Dill@asu.edu> Decemeber 2003
+ * Russ Dill <Russ.Dill@asu.edu> December 2003
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@
  */
 
 #include <unistd.h>
+#include <fcntl.h>
 #include <signal.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -43,6 +44,8 @@ static void signal_handler(int sig)
 void udhcp_sp_setup(void)
 {
        socketpair(AF_UNIX, SOCK_STREAM, 0, signal_pipe);
+       fcntl(signal_pipe[0], F_SETFD, FD_CLOEXEC);
+       fcntl(signal_pipe[1], F_SETFD, FD_CLOEXEC);
        signal(SIGUSR1, signal_handler);
        signal(SIGUSR2, signal_handler);
        signal(SIGTERM, signal_handler);
@@ -56,7 +59,10 @@ int udhcp_sp_fd_set(fd_set *rfds, int extra_fd)
 {
        FD_ZERO(rfds);
        FD_SET(signal_pipe[0], rfds);
-       if (extra_fd >= 0) FD_SET(extra_fd, rfds);
+       if (extra_fd >= 0) {
+               fcntl(extra_fd, F_SETFD, FD_CLOEXEC);
+               FD_SET(extra_fd, rfds);
+       }
        return signal_pipe[0] > extra_fd ? signal_pipe[0] : extra_fd;
 }