summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2018-04-11 14:58:04 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2018-04-11 14:58:04 +0000
commita9ac71ac2a874760466f673732610c2cc186797a (patch)
tree5c4496325563b0b83c106baf214beabb39fd312d
parent52369d0201cc941d9ae229960eb61a23c6282b99 (diff)
downloads6-a9ac71ac2a874760466f673732610c2cc186797a.tar.xz
Add -B option to s6-ipcserver-socketbinder for blocking sockets
-rw-r--r--doc/s6-ipcserver-socketbinder.html5
-rw-r--r--src/conn-tools/s6-ipcserver-socketbinder.c10
2 files changed, 10 insertions, 5 deletions
diff --git a/doc/s6-ipcserver-socketbinder.html b/doc/s6-ipcserver-socketbinder.html
index ce43d50..d4d120a 100644
--- a/doc/s6-ipcserver-socketbinder.html
+++ b/doc/s6-ipcserver-socketbinder.html
@@ -26,7 +26,7 @@ socket, then executes a program.
<h2> Interface </h2>
<pre>
- s6-ipcserver-socketbinder [ -d | -D ] [ -b <em>backlog</em> ] [ -M | -m ] [ -a <em>perms</em> ] <em>path</em> <em>prog...</em>
+ s6-ipcserver-socketbinder [ -d | -D ] [ -b <em>backlog</em> ] [ -M | -m ] [ -a <em>perms</em> ] [ -B ] <em>path</em> <em>prog...</em>
</pre>
<ul>
@@ -63,12 +63,13 @@ s6-ipcserver-socketbinder along with <tt>-m</tt>. </li>
permissions <em>perms</em>, which is an octal number from 0000 to 0777.
Default is 0777, meaning everyone can connect to it. 0700 means only processes having the
same uid as the s6-ipcserver-socketbinder process can connect to it. </li>
+ <li> <tt>-B</tt>&nbsp;: the socket will be blocking. The default is nonblocking. </li>
</ul>
<h2> Notes </h2>
<ul>
- <li> The socket is provided <strong>non-blocking</strong>. </li>
+ <li> The socket is provided <strong>non-blocking by default</strong>. </li>
<li> s6-ipcserver-socketbinder is part of a set of basic blocks used to
build a flexible Unix super-server. It normally should be given a
command line crafted to make it execute into
diff --git a/src/conn-tools/s6-ipcserver-socketbinder.c b/src/conn-tools/s6-ipcserver-socketbinder.c
index 3bc6b52..71c1c70 100644
--- a/src/conn-tools/s6-ipcserver-socketbinder.c
+++ b/src/conn-tools/s6-ipcserver-socketbinder.c
@@ -9,7 +9,7 @@
#include <skalibs/djbunix.h>
#include <skalibs/webipc.h>
-#define USAGE "s6-ipcserver-socketbinder [ -d | -D ] [ -b backlog ] [ -M | -m ] [ -a perms ] path prog..."
+#define USAGE "s6-ipcserver-socketbinder [ -d | -D ] [ -b backlog ] [ -M | -m ] [ -a perms ] [ -B ] path prog..."
#define dieusage() strerr_dieusage(100, USAGE)
int main (int argc, char const *const *argv, char const *const *envp)
@@ -17,13 +17,14 @@ int main (int argc, char const *const *argv, char const *const *envp)
unsigned int backlog = SOMAXCONN ;
int flagreuse = 1 ;
int flagdgram = 0 ;
+ int flagblocking = 0 ;
unsigned int perms = 0777 ;
PROG = "s6-ipcserver-socketbinder" ;
{
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "DdMmb:a:", &l) ;
+ int opt = subgetopt_r(argc, argv, "DdMmBb:a:", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -31,6 +32,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
case 'd' : flagreuse = 1 ; break ;
case 'M' : flagdgram = 0 ; break ;
case 'm' : flagdgram = 1 ; break ;
+ case 'B' : flagblocking = 1 ; break ;
case 'b' : if (!uint0_scan(l.arg, &backlog)) dieusage() ; break ;
case 'a' : if (!uint0_oscan(l.arg, &perms)) dieusage() ; break ;
default : dieusage() ;
@@ -40,7 +42,9 @@ int main (int argc, char const *const *argv, char const *const *envp)
}
if (argc < 2) dieusage() ;
close(0) ;
- if (flagdgram ? ipc_datagram() : ipc_stream()) strerr_diefu1sys(111, "create socket") ;
+ if (flagdgram ? ipc_datagram_internal(flagblocking ? 0 : DJBUNIX_FLAG_NB) : ipc_stream_internal(flagblocking ? 0 : DJBUNIX_FLAG_NB))
+ strerr_diefu1sys(111, "create socket") ;
+
{
mode_t m = umask(~perms & 0777) ;
if ((flagreuse ? ipc_bind_reuse(0, argv[0]) : ipc_bind(0, argv[0])) < 0)