From ec9d636b370c5872f32b57ecfbb0d6b41a840902 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 19 Oct 2018 09:19:24 +0900 Subject: [PATCH 1/5] core: use ascii_toupper() instead of everytime judging whether it is the first message --- src/core/unit.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/core/unit.c b/src/core/unit.c index 1336bcc33a..c8f4c7ce0c 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2207,7 +2207,7 @@ static int unit_log_resources(Unit *u) { /* Format the CPU time for inclusion in the human language message string */ format_timespan(buf, sizeof(buf), nsec / NSEC_PER_USEC, USEC_PER_MSEC); - t = strjoin(n_message_parts > 0 ? "consumed " : "Consumed ", buf, " CPU time"); + t = strjoin("consumed ", buf, " CPU time"); if (!t) { r = log_oom(); goto finish; @@ -2239,18 +2239,14 @@ static int unit_log_resources(Unit *u) { * bytes counters (and not for the packets counters) */ if (m == CGROUP_IP_INGRESS_BYTES) { assert(!igress); - igress = strjoin(n_message_parts > 0 ? "received " : "Received ", - format_bytes(buf, sizeof(buf), value), - " IP traffic"); + igress = strjoin("received ", format_bytes(buf, sizeof(buf), value), " IP traffic"); if (!igress) { r = log_oom(); goto finish; } } else if (m == CGROUP_IP_EGRESS_BYTES) { assert(!egress); - egress = strjoin(igress || n_message_parts > 0 ? "sent " : "Sent ", - format_bytes(buf, sizeof(buf), value), - " IP traffic"); + egress = strjoin("sent ", format_bytes(buf, sizeof(buf), value), " IP traffic"); if (!egress) { r = log_oom(); goto finish; @@ -2266,7 +2262,7 @@ static int unit_log_resources(Unit *u) { } else { char *k; - k = strdup(n_message_parts > 0 ? "no IP traffic" : "No IP traffic"); + k = strdup("no IP traffic"); if (!k) { r = log_oom(); goto finish; @@ -2294,6 +2290,7 @@ static int unit_log_resources(Unit *u) { goto finish; } + joined[0] = ascii_toupper(joined[0]); t = strjoina("MESSAGE=", u->id, ": ", joined, "."); } From fd5ad16cfba6ba9c607480efb428aa97dc2b875a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 19 Oct 2018 09:37:08 +0900 Subject: [PATCH 2/5] reply-password: initialize 'length' variable Follow-up for 1fd2786161feba4276a81c3468cfbfb118f56517. This fixes the following warning when built by clang: ``` ../src/reply-password/reply-password.c:76:21 warning: variable 'length' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] ``` Fixes CID#1396281 and CID#1396277. --- src/reply-password/reply-password.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reply-password/reply-password.c b/src/reply-password/reply-password.c index 5794dfd535..d085da9f08 100644 --- a/src/reply-password/reply-password.c +++ b/src/reply-password/reply-password.c @@ -37,7 +37,7 @@ static int send_on_socket(int fd, const char *socket_name, const void *packet, s int main(int argc, char *argv[]) { _cleanup_free_ char *packet = NULL; _cleanup_close_ int fd = -1; - size_t length; + size_t length = 0; int r; log_set_target(LOG_TARGET_AUTO); From db8794c3a0aa3faa1796dc67d415357a86598172 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 20 Oct 2018 02:34:12 +0900 Subject: [PATCH 3/5] modules-load: return first error in the loop Follow-up for a889e206a7434afe28039a1698e5ecf6a3fb7a9b. Fixes CID#1396280. --- src/modules-load/modules-load.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c index 01d909ff19..68d91be296 100644 --- a/src/modules-load/modules-load.c +++ b/src/modules-load/modules-load.c @@ -81,10 +81,10 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent char *l; int k; - r = read_line(f, LONG_LINE_MAX, &line); - if (r < 0) - return log_error_errno(errno, "Failed to read file '%s': %m", path); - if (r == 0) + k = read_line(f, LONG_LINE_MAX, &line); + if (k < 0) + return log_error_errno(k, "Failed to read file '%s': %m", path); + if (k == 0) break; l = strstrip(line); @@ -94,7 +94,7 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent continue; k = module_load_and_warn(ctx, l, true); - if (k < 0 && r == 0) + if (k < 0 && r >= 0) r = k; } From a0570c1a8221ee770948b1794faea0d78f59ec3c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 20 Oct 2018 02:36:12 +0900 Subject: [PATCH 4/5] udevadm-monitor: initialize variable Fixes CID#1396278. --- src/udev/udevadm-monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c index 631f69ded4..ae8e06111e 100644 --- a/src/udev/udevadm-monitor.c +++ b/src/udev/udevadm-monitor.c @@ -200,7 +200,7 @@ static int parse_argv(int argc, char *argv[]) { int monitor_main(int argc, char *argv[], void *userdata) { _cleanup_(sd_device_monitor_unrefp) sd_device_monitor *kernel_monitor = NULL, *udev_monitor = NULL; - _cleanup_(sd_event_unrefp) sd_event *event; + _cleanup_(sd_event_unrefp) sd_event *event = NULL; int r; r = parse_argv(argc, argv); From 1cb7d29d680a7710926a6cdd02a7ae9bea54af63 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 20 Oct 2018 02:39:02 +0900 Subject: [PATCH 5/5] udevadm-info: fix memleak Fixes CID#1396276. --- src/udev/udevadm-info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c index 6c16b6f6b9..1894362828 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -331,8 +331,8 @@ int info_main(int argc, char *argv[], void *userdata) { break; case 'd': action = ACTION_DEVICE_ID_FILE; - name = strdup(optarg); - if (!name) + r = free_and_strdup(&name, optarg); + if (r < 0) return log_oom(); break; case 'a':