From df1fbbc996cc96c4f67e1a9fa22a85230ee954de Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Tue, 26 Apr 2016 09:30:00 +0200 Subject: [PATCH] Handle type change from inetd to service When a service changes type from inetd to a regular daemon we must make sure to first deregister the currently running inetd service properly. Example: a system boots up with httpd.conf as an inetd service, so Finit opens a socket 0.0.0.0:80 pending connections to start `httpd -i`. After a while a user changes httpd.conf to be a regular service and calls `initctl reload`. Without this patch the socket will remain open and prevent httpd from opening and binding to the same port. Signed-off-by: Joachim Nilsson --- service.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/service.c b/service.c index f37305ab..c72fb184 100644 --- a/service.c +++ b/service.c @@ -616,6 +616,7 @@ int service_register(int type, char *line, time_t mtime, char *username) id = svc_next_id(cmd); } +recreate: #endif svc = svc_find(cmd, id); @@ -626,6 +627,13 @@ int service_register(int type, char *line, time_t mtime, char *username) _e("Out of memory, cannot register service %s", cmd); return errno = ENOMEM; } + } else { + if (svc_is_inetd(svc) && type != SVC_TYPE_INETD) { + _d("Service was previously inetd, deregistering ..."); + inetd_del(&svc->inetd); + svc_del(svc); + goto recreate; + } } if (desc)