X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshutdownd%2Fshutdownd.c;fp=src%2Fshutdownd%2Fshutdownd.c;h=60a646878e501725459aa1fbe971dba37f9b3084;hp=701882b96d58da442077c825babb3d63e1c031ad;hb=1c8da044469acabcfc479ba3276954da53210830;hpb=6e646d22f6f9215de5ccb5e5edf450558c59fed1 diff --git a/src/shutdownd/shutdownd.c b/src/shutdownd/shutdownd.c index 701882b96..60a646878 100644 --- a/src/shutdownd/shutdownd.c +++ b/src/shutdownd/shutdownd.c @@ -70,12 +70,7 @@ static int read_packet(int fd, union shutdown_buffer *_b) { assert(_b); n = recvmsg(fd, &msghdr, MSG_DONTWAIT); - if (n <= 0) { - if (n == 0) { - log_error("Short read"); - return -EIO; - } - + if (n < 0) { if (errno == EAGAIN || errno == EINTR) return 0; @@ -83,6 +78,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 ||