diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2016-09-10 14:39:33 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2016-09-10 14:39:33 +0000 |
commit | da4000da5e0253b10d59fdc04baafdadd43ca4fd (patch) | |
tree | cb7a81b8f9ca4ca2b3ee0672d6714a9366c5560f /src/conn-tools | |
parent | 7afd50239da5420d0163621b12fdf5e3214ec297 (diff) | |
download | s6-da4000da5e0253b10d59fdc04baafdadd43ca4fd.tar.xz |
Allow s6-ipcserver-socketbinder to create SOCK_DGRAM sockets and to not listen() (suggested by Daniel Kahn Gillmor)
Diffstat (limited to 'src/conn-tools')
-rw-r--r-- | src/conn-tools/s6-ipcserver-socketbinder.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/conn-tools/s6-ipcserver-socketbinder.c b/src/conn-tools/s6-ipcserver-socketbinder.c index b5a32f3..523b118 100644 --- a/src/conn-tools/s6-ipcserver-socketbinder.c +++ b/src/conn-tools/s6-ipcserver-socketbinder.c @@ -2,6 +2,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <sys/socket.h> #include <unistd.h> #include <skalibs/uint.h> #include <skalibs/sgetopt.h> @@ -9,24 +10,27 @@ #include <skalibs/djbunix.h> #include <skalibs/webipc.h> -#define USAGE "s6-ipcserver-socketbinder [ -d | -D ] [ -b backlog ] path prog..." +#define USAGE "s6-ipcserver-socketbinder [ -d | -D ] [ -b backlog ] [ -M | -m ] path prog..." #define dieusage() strerr_dieusage(100, USAGE) int main (int argc, char const *const *argv, char const *const *envp) { - unsigned int backlog = 20 ; + unsigned int backlog = SOMAXCONN ; int flagreuse = 1 ; + int flagdgram = 0 ; PROG = "s6-ipcserver-socketbinder" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "Ddb:", &l) ; + register int opt = subgetopt_r(argc, argv, "DdMmb:", &l) ; if (opt == -1) break ; switch (opt) { case 'D' : flagreuse = 0 ; break ; case 'd' : flagreuse = 1 ; break ; + case 'M' : flagdgram = 0 ; break ; + case 'm' : flagdgram = 1 ; break ; case 'b' : if (!uint0_scan(l.arg, &backlog)) dieusage() ; break ; default : dieusage() ; } @@ -35,14 +39,15 @@ int main (int argc, char const *const *argv, char const *const *envp) } if (argc < 2) dieusage() ; close(0) ; - if (ipc_stream()) strerr_diefu1sys(111, "create socket") ; + if (flagdgram ? ipc_datagram() : ipc_stream()) strerr_diefu1sys(111, "create socket") ; { mode_t m = umask(0) ; if ((flagreuse ? ipc_bind_reuse(0, argv[0]) : ipc_bind(0, argv[0])) < 0) strerr_diefu2sys(111, "bind to ", argv[0]) ; umask(m) ; } - if (ipc_listen(0, backlog) < 0) strerr_diefu2sys(111, "listen to ", argv[0]) ; + if (backlog && ipc_listen(0, backlog) < 0) + strerr_diefu2sys(111, "listen to ", argv[0]) ; pathexec_run(argv[1], argv + 1, envp) ; strerr_dieexec(111, argv[1]) ; |