diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-04-24 07:45:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-24 07:45:07 +0200 |
commit | 11f93798663009d3a83b60ce899c778d9c1f5180 (patch) | |
tree | 0fd5e3d69f60033f54075e2ecd4d5a907f250abc /src/journal | |
parent | 41ab8c67ebfbbdc78cda473d81d392da912c17bc (diff) | |
parent | 371d72e05b7e2c2b7850cb04d8d4c18be1e60421 (diff) | |
download | systemd-11f93798663009d3a83b60ce899c778d9c1f5180.tar.gz |
Merge pull request #15570 from poettering/cmsg-find
CMSG_FIND_DATA() and cmsg_find() work
Diffstat (limited to 'src/journal')
-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; |