X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=src%2Factivate%2Factivate.c;h=cf545d61f79092c85de99551a6a0ea3c5a707b14;hb=9fa3006323e86962ceaa3171b906cf2b1c2cf525;hp=537626d390c3e47d22c56a56f7ab02df281561a6;hpb=df49ccafc0d57c731a3da3014ad55d5bb9ed3e1b;p=elogind.git diff --git a/src/activate/activate.c b/src/activate/activate.c index 537626d39..cf545d61f 100644 --- a/src/activate/activate.c +++ b/src/activate/activate.c @@ -51,14 +51,15 @@ static int add_epoll(int epoll_fd, int fd) { ev.data.fd = fd; r = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev); - if (r < 0) - log_error("Failed to add event on epoll fd:%d for fd:%d: %m", - epoll_fd, fd); - return -errno; + if (r < 0) { + log_error("Failed to add event on epoll fd:%d for fd:%d: %m", epoll_fd, fd); + return -errno; + } + + return 0; } static int make_socket_fd(const char* address, int flags) { - _cleanup_free_ char *p = NULL; SocketAddress a; int fd, r; @@ -100,6 +101,17 @@ static int open_sockets(int *epoll_fd, bool accept) { } } + /* Close logging and all other descriptors */ + if (arg_listen) { + int except[3 + n]; + + for (fd = 0; fd < SD_LISTEN_FDS_START + n; fd++) + except[fd] = fd; + + log_close(); + close_all_fds(except, 3 + n); + } + /** Note: we leak some fd's on error here. I doesn't matter * much, since the program will exit immediately anyway, but * would be a pain to fix. @@ -109,6 +121,7 @@ static int open_sockets(int *epoll_fd, bool accept) { fd = make_socket_fd(*address, SOCK_STREAM | (arg_accept*SOCK_CLOEXEC)); if (fd < 0) { + log_open(); log_error("Failed to open '%s': %s", *address, strerror(-fd)); return fd; } @@ -117,6 +130,9 @@ static int open_sockets(int *epoll_fd, bool accept) { count ++; } + if (arg_listen) + log_open(); + *epoll_fd = epoll_create1(EPOLL_CLOEXEC); if (*epoll_fd < 0) { log_error("Failed to create epoll object: %m"); @@ -271,10 +287,10 @@ static void sigchld_hdl(int sig, siginfo_t *t, void *data) { static int install_chld_handler(void) { int r; - struct sigaction act; - zero(act); - act.sa_flags = SA_SIGINFO; - act.sa_sigaction = sigchld_hdl; + struct sigaction act = { + .sa_flags = SA_SIGINFO, + .sa_sigaction = sigchld_hdl, + }; r = sigaction(SIGCHLD, &act, 0); if (r < 0) @@ -319,7 +335,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "+hl:saE:", options, NULL)) >= 0) + while ((c = getopt_long(argc, argv, "+hl:aE:", options, NULL)) >= 0) switch(c) { case 'h': return help();