diff options
author | Daniel Mack <github@zonque.org> | 2015-06-10 20:06:43 +0200 |
---|---|---|
committer | Daniel Mack <github@zonque.org> | 2015-06-10 20:06:43 +0200 |
commit | a8467435a0c4962cab89574f65e7318ef389351f (patch) | |
tree | cea7229033673996d2d492ee29b171ef96096d6e /src/shared | |
parent | 1f8cc1284c586b06ddf2ba5e5d8c9f13f987a1c5 (diff) | |
parent | 2a1288ff89322a2f49c79f6d1832c8164c14a05c (diff) |
Merge pull request #147 from poettering/cmsg
util: introduce CMSG_FOREACH() macro and make use of it everywhere
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/macro.h | 3 | ||||
-rw-r--r-- | src/shared/util.c | 4 |
2 files changed, 5 insertions, 2 deletions
diff --git a/src/shared/macro.h b/src/shared/macro.h index 7ae1ed80b6..cc1c9e73c0 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -467,4 +467,7 @@ do { \ } \ struct __useless_struct_to_allow_trailing_semicolon__ +#define CMSG_FOREACH(cmsg, mh) \ + for ((cmsg) = CMSG_FIRSTHDR(mh); (cmsg); (cmsg) = CMSG_NXTHDR((mh), (cmsg))) + #include "log.h" diff --git a/src/shared/util.c b/src/shared/util.c index a20e7bb2ef..6f6906f877 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -5520,7 +5520,7 @@ int openpt_in_namespace(pid_t pid, int flags) { if (recvmsg(pair[0], &mh, MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) < 0) return -errno; - for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg)) + CMSG_FOREACH(cmsg, &mh) if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { int *fds; unsigned n_fds; @@ -5908,7 +5908,7 @@ void cmsg_close_all(struct msghdr *mh) { assert(mh); - for (cmsg = CMSG_FIRSTHDR(mh); cmsg; cmsg = CMSG_NXTHDR(mh, cmsg)) + CMSG_FOREACH(cmsg, mh) 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)); } |