summaryrefslogtreecommitdiff
path: root/src/shutdownd
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-02-18 19:20:47 +0100
committerLennart Poettering <lennart@poettering.net>2015-02-18 19:42:24 +0100
commit1c8da044469acabcfc479ba3276954da53210830 (patch)
treea9252d87c59570ebec4f3004526e6f52637bb917 /src/shutdownd
parent6e646d22f6f9215de5ccb5e5edf450558c59fed1 (diff)
shared: introduce cmsg_close_all() call
The call iterates through cmsg list and closes all fds passed via SCM_RIGHTS. This patch also ensures the call is used wherever appropriate, where we might get spurious fds sent and we should better close them, then leave them lying around.
Diffstat (limited to 'src/shutdownd')
-rw-r--r--src/shutdownd/shutdownd.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/shutdownd/shutdownd.c b/src/shutdownd/shutdownd.c
index 701882b96d..60a646878e 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 ||