From da4000da5e0253b10d59fdc04baafdadd43ca4fd Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 10 Sep 2016 14:39:33 +0000 Subject: Allow s6-ipcserver-socketbinder to create SOCK_DGRAM sockets and to not listen() (suggested by Daniel Kahn Gillmor) --- src/conn-tools/s6-ipcserver-socketbinder.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') 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 #include +#include #include #include #include @@ -9,24 +10,27 @@ #include #include -#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]) ; -- cgit v1.2.3