summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-01-06 19:41:49 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-01-06 19:41:49 +0000
commit80f1ebe9aaa1f5fb0ee796f005b0abda1628226d (patch)
tree23ddb10d18ba833a1028fba3e59ab0133520b733 /src
parent752fa538fad7a65a3c88383a843c1649355f9298 (diff)
downloads6-networking-80f1ebe9aaa1f5fb0ee796f005b0abda1628226d.tar.xz
Prevent failure of -1 option in ucspi servers when stdout is closed
Diffstat (limited to 'src')
-rw-r--r--src/conn-tools/s6-ipcserver.c10
-rw-r--r--src/conn-tools/s6-tcpserver4.c10
-rw-r--r--src/conn-tools/s6-tcpserver6.c10
3 files changed, 24 insertions, 6 deletions
diff --git a/src/conn-tools/s6-ipcserver.c b/src/conn-tools/s6-ipcserver.c
index 234127e..1210139 100644
--- a/src/conn-tools/s6-ipcserver.c
+++ b/src/conn-tools/s6-ipcserver.c
@@ -6,6 +6,7 @@
#include <sys/wait.h>
#include <errno.h>
#include <unistd.h>
+#include <fcntl.h>
#include <grp.h>
#include <limits.h>
#include <signal.h>
@@ -350,8 +351,13 @@ int main (int argc, char const *const *argv, char const *const *envp)
argc -= l.ind ; argv += l.ind ;
if (argc < 2) dieusage() ;
if (!*argv[0]) dieusage() ;
- fd_close(0) ;
- if (!flag1) fd_close(1) ;
+ close(0) ;
+ if (flag1)
+ {
+ if (fcntl(1, F_GETFD) < 0)
+ strerr_dief1sys(100, "called with option -1 but stdout said") ;
+ }
+ else close(1) ;
if (!maxconn) maxconn = 1 ;
if (maxconn > ABSOLUTE_MAXCONN) maxconn = ABSOLUTE_MAXCONN ;
if (!flaglookup || (localmaxconn > maxconn)) localmaxconn = maxconn ;
diff --git a/src/conn-tools/s6-tcpserver4.c b/src/conn-tools/s6-tcpserver4.c
index 77ecebd..e030b6d 100644
--- a/src/conn-tools/s6-tcpserver4.c
+++ b/src/conn-tools/s6-tcpserver4.c
@@ -6,6 +6,7 @@
#include <sys/wait.h>
#include <errno.h>
#include <unistd.h>
+#include <fcntl.h>
#include <limits.h>
#include <grp.h>
#include <signal.h>
@@ -327,8 +328,13 @@ int main (int argc, char const *const *argv, char const *const *envp)
argc -= l.ind ; argv += l.ind ;
if (argc < 3) dieusage() ;
if (!ip4_scan(argv[0], ip) || !uint160_scan(argv[1], &port)) dieusage() ;
- fd_close(0) ;
- if (!flag1) fd_close(1) ;
+ close(0) ;
+ if (flag1)
+ {
+ if (fcntl(1, F_GETFD) < 0)
+ strerr_dief1sys(100, "called with option -1 but stdout said") ;
+ }
+ else close(1) ;
if (!maxconn) maxconn = 1 ;
if (maxconn > ABSOLUTE_MAXCONN) maxconn = ABSOLUTE_MAXCONN ;
if (localmaxconn > maxconn) localmaxconn = maxconn ;
diff --git a/src/conn-tools/s6-tcpserver6.c b/src/conn-tools/s6-tcpserver6.c
index ef988d0..999a564 100644
--- a/src/conn-tools/s6-tcpserver6.c
+++ b/src/conn-tools/s6-tcpserver6.c
@@ -6,6 +6,7 @@
#include <sys/wait.h>
#include <errno.h>
#include <unistd.h>
+#include <fcntl.h>
#include <limits.h>
#include <grp.h>
#include <signal.h>
@@ -327,8 +328,13 @@ int main (int argc, char const *const *argv, char const *const *envp)
argc -= l.ind ; argv += l.ind ;
if (argc < 3) dieusage() ;
if (!ip6_scan(argv[0], ip) || !uint160_scan(argv[1], &port)) dieusage() ;
- fd_close(0) ;
- if (!flag1) fd_close(1) ;
+ close(0) ;
+ if (flag1)
+ {
+ if (fcntl(1, F_GETFD) < 0)
+ strerr_dief1sys(100, "called with option -1 but stdout said") ;
+ }
+ else close(1) ;
if (!maxconn) maxconn = 1 ;
if (maxconn > ABSOLUTE_MAXCONN) maxconn = ABSOLUTE_MAXCONN ;
if (localmaxconn > maxconn) localmaxconn = maxconn ;