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 <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2016-04-26 09:30:00 +02:00
parent 448a9e1198
commit df1fbbc996
+8
View File
@@ -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)