syslogd: Close open UNIX and inet sockets on SIGTERM
When creating Inet sockets we may get multiple struct addrinfo records. With this patch we support up to 16 records per Internet peer. When closing we iterate over all peers and all records. Refactor socket_close() to clean up any lingering socket path when closing UNIX socket. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
19
src/socket.c
19
src/socket.c
@ -186,18 +186,23 @@ err: close(sd);
|
||||
|
||||
int socket_close(int sd)
|
||||
{
|
||||
struct sockaddr_un *sun;
|
||||
struct sock *entry, *tmp;
|
||||
|
||||
LIST_FOREACH_SAFE(entry, &sl, link, tmp) {
|
||||
if (entry->sd == sd) {
|
||||
LIST_REMOVE(entry, link);
|
||||
close(entry->sd);
|
||||
if (entry->ai.ai_family == AF_UNIX)
|
||||
free(entry->ai.ai_addr);
|
||||
free(entry);
|
||||
if (entry->sd != sd)
|
||||
continue;
|
||||
|
||||
return 0;
|
||||
LIST_REMOVE(entry, link);
|
||||
close(entry->sd);
|
||||
if (entry->ai.ai_family == AF_UNIX) {
|
||||
sun = (struct sockaddr_un *)entry->ai.ai_addr;
|
||||
(void)unlink(sun->sun_path);
|
||||
}
|
||||
free(entry->ai.ai_addr);
|
||||
free(entry);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
errno = ENOENT;
|
||||
|
Reference in New Issue
Block a user