Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Step:15-SP2
lvm2.17498
bug-1172597_7-daemon-better-error-path-handling...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File bug-1172597_7-daemon-better-error-path-handling-for-shutdown.patch of Package lvm2.17498
From e9b2148dab3a1f501637b628978c93be4d2be086 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac <zkabelac@redhat.com> Date: Fri, 8 Nov 2019 13:07:06 +0100 Subject: [PATCH] daemon: better error path handling for shutdown Report errors for open in better order. Ensure descriptors are not leaked. --- libdaemon/server/daemon-server.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c index 51e5866..aa9ff2a 100644 --- a/libdaemon/server/daemon-server.c +++ b/libdaemon/server/daemon-server.c @@ -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 (_shutdown_requested) { + ERROR(&s, "Shutdown requested."); + goto bad; } - if (fcntl(client.socket_fd, F_SETFD, FD_CLOEXEC)) + 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) -- 1.8.3.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor