1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-22 06:50:52 +03:00

daemon: better error path handling for shutdown

Report errors for open in better order.
Ensure descriptors are not leaked.
This commit is contained in:
Zdenek Kabelac 2019-11-08 13:07:06 +01:00
parent 34bde8b6c7
commit e9b2148dab

View File

@ -513,20 +513,23 @@ static int _handle_connect(daemon_state s)
socklen_t sl = sizeof(sockaddr);
client.socket_fd = accept(s.socket_fd, (struct sockaddr *) &sockaddr, &sl);
if (client.socket_fd < 0 || _shutdown_requested) {
if (errno != EAGAIN || !_shutdown_requested)
if (client.socket_fd < 0) {
if (errno != EAGAIN)
ERROR(&s, "Failed to accept connection: %s.", strerror(errno));
return 0;
goto bad;
}
if (fcntl(client.socket_fd, F_SETFD, FD_CLOEXEC))
if (_shutdown_requested) {
ERROR(&s, "Shutdown requested.");
goto bad;
}
if (fcntl(client.socket_fd, F_SETFD, FD_CLOEXEC))
WARN(&s, "setting CLOEXEC on client socket fd %d failed", client.socket_fd);
if (!(ts = dm_malloc(sizeof(thread_state)))) {
if (close(client.socket_fd))
perror("close");
ERROR(&s, "Failed to allocate thread state");
return 0;
goto bad;
}
ts->next = s.threads->next;
@ -538,10 +541,16 @@ static int _handle_connect(daemon_state s)
if ((errno = pthread_create(&ts->client.thread_id, NULL, _client_thread, ts))) {
ERROR(&s, "Failed to create client thread: %s.", strerror(errno));
return 0;
ts->active = 0;
goto bad;
}
return 1;
bad:
if ((client.socket_fd >= 0) && close(client.socket_fd))
perror("close");
return 0;
}
static void _reap(daemon_state s, int waiting)