summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-06-10 19:10:47 +0200
committerLennart Poettering <lennart@poettering.net>2015-06-10 19:29:47 +0200
commit2a1288ff89322a2f49c79f6d1832c8164c14a05c (patch)
tree02cc41ade7b814d258b183c0ac88670163194913 /src/libsystemd/sd-bus
parent5410b2ed62289d8ab6575e64951ac7b6bda51d40 (diff)
util: introduce CMSG_FOREACH() macro and make use of it everywhere
It's only marginally shorter then the usual for() loop, but certainly more readable.
Diffstat (limited to 'src/libsystemd/sd-bus')
-rw-r--r--src/libsystemd/sd-bus/bus-container.c2
-rw-r--r--src/libsystemd/sd-bus/bus-socket.c16
2 files changed, 11 insertions, 7 deletions
diff --git a/src/libsystemd/sd-bus/bus-container.c b/src/libsystemd/sd-bus/bus-container.c
index f157c25bba..fa7a207448 100644
--- a/src/libsystemd/sd-bus/bus-container.c
+++ b/src/libsystemd/sd-bus/bus-container.c
@@ -222,7 +222,7 @@ int bus_container_connect_kernel(sd_bus *b) {
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;
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
index 9f3756f0c2..322d57ddbb 100644
--- a/src/libsystemd/sd-bus/bus-socket.c
+++ b/src/libsystemd/sd-bus/bus-socket.c
@@ -502,7 +502,6 @@ static int bus_socket_read_auth(sd_bus *b) {
struct cmsghdr cmsghdr;
uint8_t buf[CMSG_SPACE(sizeof(int) * BUS_FDS_MAX)];
} control;
- struct cmsghdr *cmsg;
bool handle_cmsg = false;
assert(b);
@@ -552,8 +551,10 @@ static int bus_socket_read_auth(sd_bus *b) {
b->rbuffer_size += k;
- if (handle_cmsg)
- for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg))
+ if (handle_cmsg) {
+ struct cmsghdr *cmsg;
+
+ CMSG_FOREACH(cmsg, &mh)
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_RIGHTS) {
int j;
@@ -567,6 +568,7 @@ static int bus_socket_read_auth(sd_bus *b) {
} else
log_debug("Got unexpected auxiliary data with level=%d and type=%d",
cmsg->cmsg_level, cmsg->cmsg_type);
+ }
r = bus_socket_auth_verify(b);
if (r != 0)
@@ -916,7 +918,6 @@ int bus_socket_read_message(sd_bus *bus) {
struct cmsghdr cmsghdr;
uint8_t buf[CMSG_SPACE(sizeof(int) * BUS_FDS_MAX)];
} control;
- struct cmsghdr *cmsg;
bool handle_cmsg = false;
assert(bus);
@@ -961,8 +962,10 @@ int bus_socket_read_message(sd_bus *bus) {
bus->rbuffer_size += k;
- if (handle_cmsg)
- for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg))
+ if (handle_cmsg) {
+ struct cmsghdr *cmsg;
+
+ CMSG_FOREACH(cmsg, &mh)
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_RIGHTS) {
int n, *f;
@@ -990,6 +993,7 @@ int bus_socket_read_message(sd_bus *bus) {
} else
log_debug("Got unexpected auxiliary data with level=%d and type=%d",
cmsg->cmsg_level, cmsg->cmsg_type);
+ }
r = bus_socket_read_message_need(bus, &need);
if (r < 0)