chiark / gitweb /
fsckd: the error code is actually returned in 'fd'
[elogind.git] / src / shutdownd / shutdownd.c
index 6eb522bcfceed559d67f7d5da297044aaa6cf5ab..6e4511ecea718e7a97a274e8039210891ffe12c5 100644 (file)
 ***/
 
 #include <sys/socket.h>
-#include <sys/poll.h>
-#include <sys/types.h>
+#include <poll.h>
 #include <sys/timerfd.h>
-#include <assert.h>
-#include <string.h>
 #include <errno.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <stddef.h>
 
 #include "systemd/sd-daemon.h"
@@ -69,13 +65,8 @@ static int read_packet(int fd, union shutdown_buffer *_b) {
         assert(fd >= 0);
         assert(_b);
 
-        n = recvmsg(fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC);
-        if (n <= 0) {
-                if (n == 0) {
-                        log_error("Short read");
-                        return -EIO;
-                }
-
+        n = recvmsg(fd, &msghdr, MSG_DONTWAIT);
+        if (n < 0) {
                 if (errno == EAGAIN || errno == EINTR)
                         return 0;
 
@@ -83,6 +74,13 @@ static int read_packet(int fd, union shutdown_buffer *_b) {
                 return -errno;
         }
 
+        cmsg_close_all(&msghdr);
+
+        if (n == 0) {
+                log_error("Short read");
+                return -EIO;
+        }
+
         if (msghdr.msg_controllen < CMSG_LEN(sizeof(struct ucred)) ||
             control.cmsghdr.cmsg_level != SOL_SOCKET ||
             control.cmsghdr.cmsg_type != SCM_CREDENTIALS ||