diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-04-17 11:52:48 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2020-04-23 19:41:15 +0200 |
commit | 371d72e05b7e2c2b7850cb04d8d4c18be1e60421 (patch) | |
tree | c6b0f467bca7db6d1c5f2d2262199ca2256a8f01 /src/journal/journald-stream.c | |
parent | dac556fa7ba19846f787e560e7de8958891b6754 (diff) | |
download | systemd-371d72e05b7e2c2b7850cb04d8d4c18be1e60421.tar.gz |
socket-util: introduce type-safe, dereferencing wrapper CMSG_FIND_DATA around cmsg_find()
let's take this once step further, and add type-safety to cmsg_find(),
and imply the CMSG_DATA() macro for finding the cmsg payload.
Diffstat (limited to 'src/journal/journald-stream.c')
-rw-r--r-- | src/journal/journald-stream.c | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index ec6dad62e8..202ac3cda2 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -491,8 +491,7 @@ static int stdout_stream_scan(StdoutStream *s, bool force_flush) { static int stdout_stream_process(sd_event_source *es, int fd, uint32_t revents, void *userdata) { uint8_t buf[CMSG_SPACE(sizeof(struct ucred))]; StdoutStream *s = userdata; - struct ucred *ucred = NULL; - struct cmsghdr *cmsg; + struct ucred *ucred; struct iovec iovec; size_t limit; ssize_t l; @@ -541,25 +540,14 @@ static int stdout_stream_process(sd_event_source *es, int fd, uint32_t revents, goto terminate; } - CMSG_FOREACH(cmsg, &msghdr) - if (cmsg->cmsg_level == SOL_SOCKET && - cmsg->cmsg_type == SCM_CREDENTIALS && - cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred))) { - assert(!ucred); - ucred = (struct ucred *)CMSG_DATA(cmsg); - break; - } - - /* Invalidate the context if the pid of the sender changed. - * This happens when a forked process inherits stdout / stderr - * from a parent. In this case getpeercred returns the ucred - * of the parent, which can be invalid if the parent has exited - * in the meantime. + /* Invalidate the context if the pid of the sender changed. This happens when a forked process + * inherits stdout / stderr from a parent. In this case getpeercred returns the ucred of the parent, + * which can be invalid if the parent has exited in the meantime. */ + ucred = CMSG_FIND_DATA(&msghdr, SOL_SOCKET, SCM_CREDENTIALS, struct ucred); if (ucred && ucred->pid != s->ucred.pid) { - /* force out any previously half-written lines from a - * different process, before we switch to the new ucred - * structure for everything we just added */ + /* force out any previously half-written lines from a different process, before we switch to + * the new ucred structure for everything we just added */ r = stdout_stream_scan(s, true); if (r < 0) goto terminate; |