diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-07-26 14:56:34 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-08-07 08:49:11 +0200 |
commit | 4dc2ecd227453597c63548d043401eddef87b9cd (patch) | |
tree | b5744424fd6dd91698776e8c14c1b2bd09e8fa3a /src/basic/log.c | |
parent | Merge pull request #20375 from yuwata/network-bridge-vlan-issue-20373 (diff) | |
download | systemd-4dc2ecd227453597c63548d043401eddef87b9cd.tar.xz systemd-4dc2ecd227453597c63548d043401eddef87b9cd.zip |
basic/log: use structured initialization, drop unused initialization
We had 'msghdr' and 'mh' in various places. Now 'const struct msghdr msghdr' is
used consistently. With structured init the variable is only used in the call
to sendmsg(), so let's make it a bit more descriptive.
Diffstat (limited to 'src/basic/log.c')
-rw-r--r-- | src/basic/log.c | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/basic/log.c b/src/basic/log.c index 7602536691..59c74659eb 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -476,7 +476,7 @@ static int write_to_syslog( IOVEC_MAKE_STRING(header_pid), IOVEC_MAKE_STRING(buffer), }; - struct msghdr msghdr = { + const struct msghdr msghdr = { .msg_iov = iovec, .msg_iovlen = ELEMENTSOF(iovec), }; @@ -608,23 +608,24 @@ static int write_to_journal( const char *buffer) { char header[LINE_MAX]; - struct iovec iovec[4] = {}; - struct msghdr mh = {}; if (journal_fd < 0) return 0; log_do_header(header, sizeof(header), level, error, file, line, func, object_field, object, extra_field, extra); - iovec[0] = IOVEC_MAKE_STRING(header); - iovec[1] = IOVEC_MAKE_STRING("MESSAGE="); - iovec[2] = IOVEC_MAKE_STRING(buffer); - iovec[3] = IOVEC_MAKE_STRING("\n"); - - mh.msg_iov = iovec; - mh.msg_iovlen = ELEMENTSOF(iovec); + struct iovec iovec[4] = { + IOVEC_MAKE_STRING(header), + IOVEC_MAKE_STRING("MESSAGE="), + IOVEC_MAKE_STRING(buffer), + IOVEC_MAKE_STRING("\n"), + }; + const struct msghdr msghdr = { + .msg_iov = iovec, + .msg_iovlen = ELEMENTSOF(iovec), + }; - if (sendmsg(journal_fd, &mh, MSG_NOSIGNAL) < 0) + if (sendmsg(journal_fd, &msghdr, MSG_NOSIGNAL) < 0) return -errno; return 1; @@ -959,12 +960,9 @@ int log_struct_internal( if (journal_fd >= 0) { char header[LINE_MAX]; - struct iovec iovec[17] = {}; + struct iovec iovec[17]; size_t n = 0; int r; - struct msghdr mh = { - .msg_iov = iovec, - }; bool fallback = false; /* If the journal is available do structured logging. @@ -977,8 +975,12 @@ int log_struct_internal( if (r < 0) fallback = true; else { - mh.msg_iovlen = n; - (void) sendmsg(journal_fd, &mh, MSG_NOSIGNAL); + const struct msghdr msghdr = { + .msg_iov = iovec, + .msg_iovlen = n, + }; + + (void) sendmsg(journal_fd, &msghdr, MSG_NOSIGNAL); } va_end(ap); @@ -1052,22 +1054,22 @@ int log_struct_iovec_internal( LOG_TARGET_JOURNAL) && journal_fd >= 0) { - struct iovec iovec[1 + n_input_iovec*2]; char header[LINE_MAX]; - struct msghdr mh = { - .msg_iov = iovec, - .msg_iovlen = 1 + n_input_iovec*2, - }; - log_do_header(header, sizeof(header), level, error, file, line, func, NULL, NULL, NULL, NULL); - iovec[0] = IOVEC_MAKE_STRING(header); + struct iovec iovec[1 + n_input_iovec*2]; + iovec[0] = IOVEC_MAKE_STRING(header); for (i = 0; i < n_input_iovec; i++) { iovec[1+i*2] = input_iovec[i]; iovec[1+i*2+1] = IOVEC_MAKE_STRING("\n"); } - if (sendmsg(journal_fd, &mh, MSG_NOSIGNAL) >= 0) + const struct msghdr msghdr = { + .msg_iov = iovec, + .msg_iovlen = 1 + n_input_iovec*2, + }; + + if (sendmsg(journal_fd, &msghdr, MSG_NOSIGNAL) >= 0) return -ERRNO_VALUE(error); } |