summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-03-01 14:11:30 -0500
committerAnthony G. Basile <blueness@gentoo.org>2015-03-01 14:11:30 -0500
commitd80d6e858f7e308f0144c5d01e3eca21b09292d9 (patch)
tree904930d7113eae1cbe541fd17fbe00f6e242b18c /src/shared/util.c
parent1d1660eb1c3721fc6e1061a8d17d89c76e56fcdc (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. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 0eca4f8562..dc05001a28 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -1696,3 +1696,13 @@ int execute_command(const char *command, char *const argv[]) {
}
}
+
+void cmsg_close_all(struct msghdr *mh) {
+ struct cmsghdr *cmsg;
+
+ assert(mh);
+
+ for (cmsg = CMSG_FIRSTHDR(mh); cmsg; cmsg = CMSG_NXTHDR(mh, cmsg))
+ if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
+ close_many((int*) CMSG_DATA(cmsg), (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int));
+}