chiark / gitweb /
systemd-stdio-bridge: make it socket-activatable and usable as kdbus bridge
[elogind.git] / src / activate / activate.c
index f0944aac5c846e9339f887b639a4a14109869581..5263969fcf572c1e1829fc59da8f87c849443a89 100644 (file)
@@ -58,7 +58,6 @@ static int add_epoll(int epoll_fd, int fd) {
 }
 
 static int make_socket_fd(const char* address, int flags) {
-        _cleanup_free_ char *p = NULL;
         SocketAddress a;
         int fd, r;
 
@@ -127,7 +126,7 @@ static int open_sockets(int *epoll_fd, bool accept) {
                 _cleanup_free_ char *name = NULL;
 
                 getsockname_pretty(fd, &name);
-                log_info("Listening on %s.", strna(name));
+                log_info("Listening on %s as %i.", strna(name), fd);
 
                 r = add_epoll(*epoll_fd, fd);
                 if (r < 0)
@@ -262,6 +261,8 @@ 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) {
+        PROTECT_ERRNO;
+
         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);
@@ -287,6 +288,8 @@ static int help(void) {
                "  -l --listen=ADDR     Listen for raw connections at ADDR\n"
                "  -a --accept          Spawn separate child for each connection\n"
                "  -h --help            Show this help and exit\n"
+               "  -E --environment=NAME[=VALUE]\n"
+               "                       Pass an environment variable to children\n"
                "  --version            Print version string and exit\n"
                "\n"
                "Note: file descriptors from sd_listen_fds() will be passed through.\n"
@@ -315,7 +318,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();
@@ -381,6 +384,10 @@ int main(int argc, char **argv, char **envp) {
         n = open_sockets(&epoll_fd, arg_accept);
         if (n < 0)
                 return EXIT_FAILURE;
+        if (n == 0) {
+                log_error("No sockets to listen on specified or passed in.");
+                return EXIT_FAILURE;
+        }
 
         for (;;) {
                 struct epoll_event event;
@@ -394,7 +401,7 @@ int main(int argc, char **argv, char **envp) {
                         return EXIT_FAILURE;
                 }
 
-                log_info("Communication attempt on fd:%d", event.data.fd);
+                log_info("Communication attempt on fd %i.", event.data.fd);
                 if (arg_accept) {
                         r = do_accept(argv[optind], argv + optind, envp,
                                       event.data.fd);