From bc35b42bd23c95f4e795a7d668ba57f05b6c644c Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 28 Dec 2017 20:46:19 +0100 Subject: [PATCH] inet_stop(): Check argument and skip shutdown(), just close() socket MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Validate function argument - Skip¹ shutdown() when closing a TCP socket, not needed ___ ¹ also, shutdown() segfaults a late shutdown/reboot Signed-off-by: Joachim Nilsson --- src/inetd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/inetd.c b/src/inetd.c index b687d0e2..cb86890d 100644 --- a/src/inetd.c +++ b/src/inetd.c @@ -334,6 +334,11 @@ int inetd_start(inetd_t *inetd) void inetd_stop(inetd_t *inetd) { + if (!inetd || !inetd->svc) { + _e("Invalid inetd, cannot stop it..."); + return; + } + if (inetd->watcher.fd != -1) { _d("Stopping %s socket watcher ...", inetd->svc->cmd); uev_io_stop(&inetd->watcher); @@ -342,8 +347,6 @@ void inetd_stop(inetd_t *inetd) * and halt the watcher, so don't close the socket! */ if (!svc_is_busy(inetd->svc)) { _d("Shutting down inet socket %d ...", inetd->watcher.fd); - if (inetd->type == SOCK_STREAM) - shutdown(inetd->watcher.fd, SHUT_RDWR); close(inetd->watcher.fd); inetd->watcher.fd = -1; }