]> sourceware.org Git - lvm2.git/commitdiff
libdaemon: Fix socket reuse error paths.
authorAlasdair G Kergon <agk@redhat.com>
Wed, 13 May 2015 12:42:09 +0000 (13:42 +0100)
committerAlasdair G Kergon <agk@redhat.com>
Wed, 13 May 2015 12:42:09 +0000 (13:42 +0100)
Invert S_ISSOCK validation.
Fail instead of replacing a symlink with a new socket.
After failure, skip calling fcntl with invalid socket_fd.

WHATS_NEW
libdaemon/server/daemon-server.c

index e1674e21fc4a7a92c01122db9f7ea425ec8d4c23..e92c01a2a904d72184b94e21d02eaa1eb14f5db4 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.120 -
 ===============================
+  Fix some libdaemon socket creation and reuse error paths.
   Daemons (libdaemon) support exit on idle also in non-systemd environment.
   Provide make dist and make rpm targets
   Configure lvm.conf for use_lvmetad and use_lvmpolld.
index 5b1aff1c55a8d8baa8b6a64082679cadef68ff84..e1a9da9c569994063becfdce34fbda5b35949826 100644 (file)
@@ -261,12 +261,12 @@ static int _open_socket(daemon_state s)
                }
 
                /* Socket already exists. If it's stale, remove it. */
-               if (stat(sockaddr.sun_path, &buf)) {
+               if (lstat(sockaddr.sun_path, &buf)) {
                        perror("stat failed");
                        goto error;
                }
 
-               if (S_ISSOCK(buf.st_mode)) {
+               if (!S_ISSOCK(buf.st_mode)) {
                        fprintf(stderr, "%s: not a socket\n", sockaddr.sun_path);
                        goto error;
                }
@@ -595,7 +595,7 @@ void daemon_start(daemon_state s)
        }
 
        /* Set Close-on-exec */
-       if (fcntl(s.socket_fd, F_SETFD, 1))
+       if (!failed && fcntl(s.socket_fd, F_SETFD, 1))
                fprintf(stderr, "setting CLOEXEC on socket fd %d failed: %s\n", s.socket_fd, strerror(errno));
 
        /* Signal parent, letting them know we are ready to go. */
This page took 0.044413 seconds and 5 git commands to generate.