summaryrefslogtreecommitdiff
path: root/src/conn-tools
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-10-01 17:37:13 +0000
committerLaurent Bercot <ska@appnovation.com>2023-10-01 17:37:13 +0000
commite6c5053c71fe506c59e4717faa8a8aa3a2685ac7 (patch)
treec86a858cb34335ea48cbaa6e20207cb3056839a5 /src/conn-tools
parent95c2e7fb17f6baf37f1d2c5229ebb35938b64aa2 (diff)
downloads6-networking-e6c5053c71fe506c59e4717faa8a8aa3a2685ac7.tar.xz
Better iteration when sending signals in s6-tcpserverd
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/conn-tools')
-rw-r--r--src/conn-tools/s6-tcpserverd.c61
1 files changed, 33 insertions, 28 deletions
diff --git a/src/conn-tools/s6-tcpserverd.c b/src/conn-tools/s6-tcpserverd.c
index 9f540f9..7b42bcc 100644
--- a/src/conn-tools/s6-tcpserverd.c
+++ b/src/conn-tools/s6-tcpserverd.c
@@ -151,15 +151,30 @@ static inline void log_close (pid_t pid, char const *ip, int w, uint32_t num)
strerr_warni7x("end pid ", fmtpid, WIFSIGNALED(w) ? " signal " : " exitcode ", fmtw, " count ", fmtnum, fmtlocalmaxconn) ;
}
-static int killthem_iter (void *data, void *aux)
+static int send_termcont_iter (void *data, void *aux)
{
- kill(((pidi *)data)->pid, *(int *)aux) ;
+ (void)aux ;
+ pid_t pid = ((pidi *)data)->pid ;
+ kill(pid, SIGTERM) ;
+ kill(pid, SIGCONT) ;
return 1 ;
}
-static void killthem (int sig)
+static int send_kill_iter (void *data, void *aux)
{
- genset_iter(pidis, &killthem_iter, &sig) ;
+ (void)aux ;
+ kill(((pidi *)data)->pid, SIGKILL) ;
+ return 1 ;
+}
+
+static inline void send_termcont (void)
+{
+ genset_iter(pidis, &send_termcont_iter, 0) ;
+}
+
+static inline void send_kill (void)
+{
+ genset_iter(pidis, &send_kill_iter, 0) ;
}
static inline void end_connection (pid_t pid, int wstat)
@@ -207,21 +222,19 @@ static inline void handle_signals (void)
case SIGHUP :
if (verbosity >= 2)
strerr_warni5x("received ", "SIGHUP,", " sending ", "SIGTERM and SIGCONT", " to all connections") ;
- killthem(SIGTERM) ;
- killthem(SIGCONT) ;
+ send_termcont() ;
break ;
case SIGQUIT :
if (verbosity >= 2)
strerr_warni6x("received ", "SIGQUIT,", " sending ", "SIGTERM and SIGCONT", " to all connections", " and quitting") ;
cont = 0 ;
- killthem(SIGTERM) ;
- killthem(SIGCONT) ;
+ send_termcont() ;
break ;
case SIGABRT :
if (verbosity >= 2)
strerr_warni6x("received ", "SIGABRT,", " sending ", "SIGKILL", " to all connections", " and quitting") ;
cont = 0 ;
- killthem(SIGKILL) ;
+ send_kill() ;
break ;
default : X() ;
}
@@ -397,27 +410,19 @@ int main (int argc, char const *const *argv)
if (iopause_g(x, 1 + (numconn < maxconn), 0) == -1)
strerr_diefu1sys(111, "iopause") ;
- if (x[0].revents & IOPAUSE_EXCEPT) strerr_dief1x(111, "trouble with selfpipe") ;
- if (x[0].revents & IOPAUSE_READ)
- {
- handle_signals() ;
- continue ;
- }
- if (numconn < maxconn)
+ if (x[0].revents & (IOPAUSE_READ | IOPAUSE_EXCEPT)) { handle_signals() ; continue ; }
+ if (numconn >= maxconn) continue ;
+ if (x[1].revents & (IOPAUSE_READ | IOPAUSE_EXCEPT))
{
- if (x[1].revents & IOPAUSE_EXCEPT) strerr_dief1x(111, "trouble with socket") ;
- if (x[1].revents & IOPAUSE_READ)
+ int fd = is6 ? socket_accept6(x[1].fd, ip, &port) : socket_accept4(x[1].fd, ip, &port) ;
+ if (fd == -1)
+ {
+ if (verbosity) strerr_warnwu1sys("accept") ;
+ }
+ else
{
- int fd = is6 ? socket_accept6(x[1].fd, ip, &port) : socket_accept4(x[1].fd, ip, &port) ;
- if (fd == -1)
- {
- if (verbosity) strerr_warnwu1sys("accept") ;
- }
- else
- {
- new_connection(fd, ip, port, argv, (char const *const *)environ, modifs, m, envlen) ;
- fd_close(fd) ;
- }
+ new_connection(fd, ip, port, argv, (char const *const *)environ, modifs, m, envlen) ;
+ fd_close(fd) ;
}
}
}