inet_stop(): Check argument and skip shutdown(), just close() socket

- Validate function argument
- Skip¹ shutdown() when closing a TCP socket, not needed

___
¹ also, shutdown() segfaults a late shutdown/reboot

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2017-12-28 20:46:19 +01:00
parent dcf8fbe235
commit bc35b42bd2
+5 -2
View File
@@ -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;
}