chiark / gitweb /
activate: get rid of redundant definiton of fd_cloexec()
[elogind.git] / src / activate / activate.c
index 87526d47cc8e5babdbb37873f6f83846f0fe4052..8b282bda7fa8b71ab1e7bbb1b2b7300220a96660 100644 (file)
@@ -55,26 +55,6 @@ static int add_epoll(int epoll_fd, int fd) {
         return r;
 }
 
-static int set_nocloexec(int fd) {
-        int flags;
-
-        flags = fcntl(fd, F_GETFD);
-        if (flags < 0) {
-                log_error("Querying flags for fd:%d: %m", fd);
-                return -errno;
-        }
-
-        if (!(flags & FD_CLOEXEC))
-                return 0;
-
-        if (fcntl(fd, F_SETFD, flags & ~FD_CLOEXEC) < 0) {
-                log_error("Settings flags for fd:%d: %m", fd);
-                return -errno;
-        }
-
-        return 0;
-}
-
 static int print_socket(const char* desc, int fd) {
         int r;
         SocketAddress addr = {
@@ -112,7 +92,7 @@ static int print_socket(const char* desc, int fd) {
 }
 
 static int open_sockets(int *epoll_fd, bool accept) {
-        int n, fd;
+        int n, fd, r;
         int count = 0;
         char **address;
 
@@ -128,11 +108,9 @@ static int open_sockets(int *epoll_fd, bool accept) {
                 log_debug("Received descriptor fd:%d", fd);
                 print_socket("Listening on", fd);
 
-                if (!arg_accept) {
-                        int r = set_nocloexec(fd);
-                        if (r < 0)
-                                return r;
-                }
+                r = fd_cloexec(fd, arg_accept);
+                if (r < 0)
+                        return r;
 
                 count ++;
         }
@@ -160,8 +138,9 @@ static int open_sockets(int *epoll_fd, bool accept) {
                 return -errno;
         }
 
+
         for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + count; fd++) {
-                int r = add_epoll(*epoll_fd, fd);
+                r = add_epoll(*epoll_fd, fd);
                 if (r < 0)
                         return r;
         }
@@ -290,16 +269,15 @@ static int do_accept(const char* name, char **argv, char **envp, int fd) {
 }
 
 /* SIGCHLD handler. */
-static void sigchld_hdl(int sig, siginfo_t *t, void *data)
-{
+static void sigchld_hdl(int sig, siginfo_t *t, void *data) {
         log_info("Child %d died with code %d", t->si_pid, t->si_status);
-       /* Wait for a dead child. */
-       waitpid(t->si_pid, NULL, 0);
+        /* Wait for a dead child. */
+        waitpid(t->si_pid, NULL, 0);
 }
 
 static int install_chld_handler(void) {
         int r;
-       struct sigaction act;
+        struct sigaction act;
         zero(act);
         act.sa_flags = SA_SIGINFO;
         act.sa_sigaction = sigchld_hdl;
@@ -337,7 +315,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "listen",       required_argument, NULL, 'l'           },
                 { "accept",       no_argument,       NULL, 'a'           },
                 { "environment",  required_argument, NULL, 'E'           },
-                { NULL,           0,                 NULL, 0             }
+                {}
         };
 
         int c;
@@ -348,8 +326,7 @@ static int parse_argv(int argc, char *argv[]) {
         while ((c = getopt_long(argc, argv, "+hl:saE:", options, NULL)) >= 0)
                 switch(c) {
                 case 'h':
-                        help();
-                        return 0 /* done */;
+                        return help();
 
                 case ARG_VERSION:
                         puts(PACKAGE_STRING);
@@ -380,8 +357,7 @@ static int parse_argv(int argc, char *argv[]) {
                         return -EINVAL;
 
                 default:
-                        log_error("Unknown option code %c", c);
-                        return -EINVAL;
+                        assert_not_reached("Unhandled option");
                 }
 
         if (optind == argc) {