From a1e58e8ee1c84b633d6d6d651d5328d4dd4eba5b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 8 Sep 2015 18:43:11 +0200 Subject: tree-wide: use coccinelle to patch a lot of code to use mfree() This replaces this: free(p); p = NULL; by this: p = mfree(p); Change generated using coccinelle. Semantic patch is added to the sources. --- src/journal-remote/journal-gatewayd.c | 3 +-- src/journal-remote/journal-remote-write.c | 3 +-- src/journal-remote/journal-upload-journal.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) (limited to 'src/journal-remote') diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index ebdd9edfc3..52078b1b37 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -338,8 +338,7 @@ static int request_parse_range( m->cursor[strcspn(m->cursor, WHITESPACE)] = 0; if (isempty(m->cursor)) { - free(m->cursor); - m->cursor = NULL; + m->cursor = mfree(m->cursor); } return 0; diff --git a/src/journal-remote/journal-remote-write.c b/src/journal-remote/journal-remote-write.c index 99820fa7b8..40f4ff8e58 100644 --- a/src/journal-remote/journal-remote-write.c +++ b/src/journal-remote/journal-remote-write.c @@ -30,8 +30,7 @@ int iovw_put(struct iovec_wrapper *iovw, void* data, size_t len) { } void iovw_free_contents(struct iovec_wrapper *iovw) { - free(iovw->iovec); - iovw->iovec = NULL; + iovw->iovec = mfree(iovw->iovec); iovw->size_bytes = iovw->count = 0; } diff --git a/src/journal-remote/journal-upload-journal.c b/src/journal-remote/journal-upload-journal.c index 5fd639a76a..3d2e52cacf 100644 --- a/src/journal-remote/journal-upload-journal.c +++ b/src/journal-remote/journal-upload-journal.c @@ -21,8 +21,7 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) { switch(u->entry_state) { case ENTRY_CURSOR: { - free(u->current_cursor); - u->current_cursor = NULL; + u->current_cursor = mfree(u->current_cursor); r = sd_journal_get_cursor(u->journal, &u->current_cursor); if (r < 0) -- cgit v1.2.3-54-g00ecf From 76ef789d264f9eb7d7624b994aa6eead1dacfac4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 8 Sep 2015 19:30:45 +0200 Subject: tree-wide: make use of log_error_errno() return value Turns this: r = -errno; log_error_errno(errno, "foo"); into this: r = log_error_errno(errno, "foo"); and this: r = log_error_errno(errno, "foo"); return r; into this: return log_error_errno(errno, "foo"); --- coccinelle/errno.cocci | 42 +++++++++++++++++++++++++++++++++++++ src/core/execute.c | 3 +-- src/core/namespace.c | 3 +-- src/core/shutdown.c | 3 +-- src/initctl/initctl.c | 4 ++-- src/journal-remote/journal-remote.c | 3 +-- src/journal/cat.c | 3 +-- src/journal/coredumpctl.c | 7 +++---- src/journal/journal-verify.c | 10 ++++----- src/journal/journalctl.c | 6 ++---- src/login/logind-button.c | 3 +-- src/resolve/resolved-manager.c | 3 +-- src/shared/ask-password-api.c | 19 +++++++---------- src/shared/pager.c | 3 +-- src/udev/udev-ctrl.c | 8 ++----- src/udev/udev-event.c | 6 ++---- src/update-utmp/update-utmp.c | 12 +++++------ src/user-sessions/user-sessions.c | 4 ++-- 18 files changed, 80 insertions(+), 62 deletions(-) create mode 100644 coccinelle/errno.cocci (limited to 'src/journal-remote') diff --git a/coccinelle/errno.cocci b/coccinelle/errno.cocci new file mode 100644 index 0000000000..073d905141 --- /dev/null +++ b/coccinelle/errno.cocci @@ -0,0 +1,42 @@ +@@ +identifier r; +expression t, e; +@@ +- r = -e; +- log_error_errno(e, t); ++ r = log_error_errno(e, t); +@@ +identifier r; +expression t, e; +@@ +- log_error_errno(e, t); +- r = -e; ++ r = log_error_errno(e, t); +@@ +identifier r; +expression t, e; +@@ +- r = log_error_errno(e, t); +- return r; ++ return log_error_errno(e, t); +@@ +identifier r; +expression t, e; +@@ +- r = -e; +- log_warning_errno(e, t); ++ r = log_warning_errno(e, t); +@@ +identifier r; +expression t, e; +@@ +- log_warning_errno(e, t); +- r = -e; ++ r = log_warning_errno(e, t); +@@ +identifier r; +expression t, e; +@@ +- r = log_warning_errno(e, t); +- return r; ++ return log_warning_errno(e, t); diff --git a/src/core/execute.c b/src/core/execute.c index 3e20130f0e..cd3592b847 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -928,8 +928,7 @@ fail: log_error("PAM failed: %s", pam_strerror(handle, pam_code)); err = -EPERM; /* PAM errors do not map to errno */ } else { - log_error_errno(errno, "PAM failed: %m"); - err = -errno; + err = log_error_errno(errno, "PAM failed: %m"); } if (handle) { diff --git a/src/core/namespace.c b/src/core/namespace.c index 045321e1d4..0b85b859fa 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -288,8 +288,7 @@ static int mount_kdbus(BindMount *m) { /* create a new /dev/null dev node copy so we have some fodder to * bind-mount the custom endpoint over. */ if (stat("/dev/null", &st) < 0) { - log_error_errno(errno, "Failed to stat /dev/null: %m"); - r = -errno; + r = log_error_errno(errno, "Failed to stat /dev/null: %m"); goto fail; } diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 8a6fd25f31..8cc6efc5b8 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -404,8 +404,7 @@ int main(int argc, char *argv[]) { exit(0); } - log_error_errno(errno, "Failed to invoke reboot(): %m"); - r = -errno; + r = log_error_errno(errno, "Failed to invoke reboot(): %m"); error: log_emergency_errno(r, "Critical error while doing system shutdown: %m"); diff --git a/src/initctl/initctl.c b/src/initctl/initctl.c index 087cc2f7d6..6d08db74ef 100644 --- a/src/initctl/initctl.c +++ b/src/initctl/initctl.c @@ -269,8 +269,8 @@ static int server_init(Server *s, unsigned n_sockets) { s->epoll_fd = epoll_create1(EPOLL_CLOEXEC); if (s->epoll_fd < 0) { - r = -errno; - log_error_errno(errno, "Failed to create epoll object: %m"); + r = log_error_errno(errno, + "Failed to create epoll object: %m"); goto fail; } diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index cdcda1cb52..bdf01f582c 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -88,8 +88,7 @@ static int spawn_child(const char* child, char** argv) { child_pid = fork(); if (child_pid < 0) { - r = -errno; - log_error_errno(errno, "Failed to fork: %m"); + r = log_error_errno(errno, "Failed to fork: %m"); safe_close_pair(fd); return r; } diff --git a/src/journal/cat.c b/src/journal/cat.c index 2e236f0004..be2c2e3354 100644 --- a/src/journal/cat.c +++ b/src/journal/cat.c @@ -142,8 +142,7 @@ int main(int argc, char *argv[]) { if (dup3(fd, STDOUT_FILENO, 0) < 0 || dup3(fd, STDERR_FILENO, 0) < 0) { - log_error_errno(errno, "Failed to duplicate fd: %m"); - r = -errno; + r = log_error_errno(errno, "Failed to duplicate fd: %m"); goto finish; } diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index 644ba91b0d..0fa427003b 100644 --- a/src/journal/coredumpctl.c +++ b/src/journal/coredumpctl.c @@ -631,8 +631,8 @@ static int save_core(sd_journal *j, int fd, char **path, bool *unlink_temp) { sz = write(fdt, data, len); if (sz < 0) { - log_error_errno(errno, "Failed to write temporary file: %m"); - r = -errno; + r = log_error_errno(errno, + "Failed to write temporary file: %m"); goto error; } if (sz != (ssize_t) len) { @@ -758,8 +758,7 @@ static int run_gdb(sd_journal *j) { pid = fork(); if (pid < 0) { - log_error_errno(errno, "Failed to fork(): %m"); - r = -errno; + r = log_error_errno(errno, "Failed to fork(): %m"); goto finish; } if (pid == 0) { diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c index eaf006db7a..00f70d3a53 100644 --- a/src/journal/journal-verify.c +++ b/src/journal/journal-verify.c @@ -839,22 +839,20 @@ int journal_file_verify( data_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC); if (data_fd < 0) { - log_error_errno(errno, "Failed to create data file: %m"); - r = -errno; + r = log_error_errno(errno, "Failed to create data file: %m"); goto fail; } entry_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC); if (entry_fd < 0) { - log_error_errno(errno, "Failed to create entry file: %m"); - r = -errno; + r = log_error_errno(errno, "Failed to create entry file: %m"); goto fail; } entry_array_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC); if (entry_array_fd < 0) { - log_error_errno(errno, "Failed to create entry array file: %m"); - r = -errno; + r = log_error_errno(errno, + "Failed to create entry array file: %m"); goto fail; } diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index ce2dd9da26..d31ab1c6d7 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1428,8 +1428,7 @@ static int setup_keys(void) { fd = open("/dev/random", O_RDONLY|O_CLOEXEC|O_NOCTTY); if (fd < 0) { - log_error_errno(errno, "Failed to open /dev/random: %m"); - r = -errno; + r = log_error_errno(errno, "Failed to open /dev/random: %m"); goto finish; } @@ -1488,8 +1487,7 @@ static int setup_keys(void) { } if (link(k, p) < 0) { - log_error_errno(errno, "Failed to link file: %m"); - r = -errno; + r = log_error_errno(errno, "Failed to link file: %m"); goto finish; } diff --git a/src/login/logind-button.c b/src/login/logind-button.c index 92c1b67951..cc98f5450e 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -248,8 +248,7 @@ int button_open(Button *b) { return log_warning_errno(errno, "Failed to open %s: %m", b->name); if (ioctl(b->fd, EVIOCGNAME(sizeof(name)), name) < 0) { - log_error_errno(errno, "Failed to get input name: %m"); - r = -errno; + r = log_error_errno(errno, "Failed to get input name: %m"); goto fail; } diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index 13852192c4..de924e3ed9 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -619,8 +619,7 @@ int manager_read_resolv_conf(Manager *m) { } if (fstat(fileno(f), &st) < 0) { - log_error_errno(errno, "Failed to stat open file: %m"); - r = -errno; + r = log_error_errno(errno, "Failed to stat open file: %m"); goto clear; } diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index ca4c24ebde..f5cff6fc56 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -331,8 +331,8 @@ int ask_password_agent( fd = mkostemp_safe(temp, O_WRONLY|O_CLOEXEC); if (fd < 0) { - log_error_errno(errno, "Failed to create password file: %m"); - r = -errno; + r = log_error_errno(errno, + "Failed to create password file: %m"); goto finish; } @@ -340,8 +340,7 @@ int ask_password_agent( f = fdopen(fd, "w"); if (!f) { - log_error_errno(errno, "Failed to allocate FILE: %m"); - r = -errno; + r = log_error_errno(errno, "Failed to allocate FILE: %m"); goto finish; } @@ -349,8 +348,7 @@ int ask_password_agent( signal_fd = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC); if (signal_fd < 0) { - log_error_errno(errno, "signalfd(): %m"); - r = -errno; + r = log_error_errno(errno, "signalfd(): %m"); goto finish; } @@ -395,8 +393,7 @@ int ask_password_agent( final[sizeof(final)-9] = 'k'; if (rename(temp, final) < 0) { - log_error_errno(errno, "Failed to rename query file: %m"); - r = -errno; + r = log_error_errno(errno, "Failed to rename query file: %m"); goto finish; } @@ -432,8 +429,7 @@ int ask_password_agent( if (errno == EINTR) continue; - log_error_errno(errno, "poll() failed: %m"); - r = -errno; + r = log_error_errno(errno, "poll() failed: %m"); goto finish; } @@ -471,8 +467,7 @@ int ask_password_agent( errno == EINTR) continue; - log_error_errno(errno, "recvmsg() failed: %m"); - r = -errno; + r = log_error_errno(errno, "recvmsg() failed: %m"); goto finish; } diff --git a/src/shared/pager.c b/src/shared/pager.c index 3992f9c837..55fd5cb79e 100644 --- a/src/shared/pager.c +++ b/src/shared/pager.c @@ -74,8 +74,7 @@ int pager_open(bool jump_to_end) { pager_pid = fork(); if (pager_pid < 0) { - r = -errno; - log_error_errno(errno, "Failed to fork pager: %m"); + r = log_error_errno(errno, "Failed to fork pager: %m"); safe_close_pair(fd); return r; } diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index ead7c92b27..12bc6029b3 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -122,16 +122,12 @@ int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl) { } if (err < 0) { - err = -errno; - log_error_errno(errno, "bind failed: %m"); - return err; + return log_error_errno(errno, "bind failed: %m"); } err = listen(uctrl->sock, 0); if (err < 0) { - err = -errno; - log_error_errno(errno, "listen failed: %m"); - return err; + return log_error_errno(errno, "listen failed: %m"); } uctrl->bound = true; diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index 8ba6aed00e..1e34cbc2f5 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -731,15 +731,13 @@ int udev_event_spawn(struct udev_event *event, /* pipes from child to parent */ if (result != NULL || log_get_max_level() >= LOG_INFO) { if (pipe2(outpipe, O_NONBLOCK) != 0) { - err = -errno; - log_error_errno(errno, "pipe failed: %m"); + err = log_error_errno(errno, "pipe failed: %m"); goto out; } } if (log_get_max_level() >= LOG_INFO) { if (pipe2(errpipe, O_NONBLOCK) != 0) { - err = -errno; - log_error_errno(errno, "pipe failed: %m"); + err = log_error_errno(errno, "pipe failed: %m"); goto out; } } diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c index 61bcf02b2f..a91c335381 100644 --- a/src/update-utmp/update-utmp.c +++ b/src/update-utmp/update-utmp.c @@ -130,8 +130,8 @@ static int on_reboot(Context *c) { if (c->audit_fd >= 0) if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_BOOT, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && errno != EPERM) { - log_error_errno(errno, "Failed to send audit message: %m"); - r = -errno; + r = log_error_errno(errno, + "Failed to send audit message: %m"); } #endif @@ -160,8 +160,8 @@ static int on_shutdown(Context *c) { if (c->audit_fd >= 0) if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_SHUTDOWN, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && errno != EPERM) { - log_error_errno(errno, "Failed to send audit message: %m"); - r = -errno; + r = log_error_errno(errno, + "Failed to send audit message: %m"); } #endif @@ -212,8 +212,8 @@ static int on_runlevel(Context *c) { if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_RUNLEVEL, s, "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && errno != EPERM) { - log_error_errno(errno, "Failed to send audit message: %m"); - r = -errno; + r = log_error_errno(errno, + "Failed to send audit message: %m"); } } #endif diff --git a/src/user-sessions/user-sessions.c b/src/user-sessions/user-sessions.c index e80a7771de..4dd4e87b86 100644 --- a/src/user-sessions/user-sessions.c +++ b/src/user-sessions/user-sessions.c @@ -43,8 +43,8 @@ int main(int argc, char*argv[]) { int r = 0; if (unlink("/run/nologin") < 0 && errno != ENOENT) { - log_error_errno(errno, "Failed to remove /run/nologin file: %m"); - r = -errno; + r = log_error_errno(errno, + "Failed to remove /run/nologin file: %m"); } if (unlink("/etc/nologin") < 0 && errno != ENOENT) { -- cgit v1.2.3-54-g00ecf From ece174c5439021e32ebcc858842de9586072c006 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 8 Sep 2015 23:03:38 +0200 Subject: tree-wide: drop {} from one-line if blocks Patch via coccinelle. --- coccinelle/empty-if.cocci | 19 +++++++++++++++++++ src/analyze/analyze.c | 5 +---- src/basic/strv.c | 6 ++---- src/bootchart/bootchart.c | 3 +-- src/bootchart/svg.c | 6 ++---- src/core/load-fragment.c | 3 +-- src/core/main.c | 3 +-- src/core/manager.c | 3 +-- src/core/service.c | 3 +-- src/core/transaction.c | 4 +--- src/cryptsetup/cryptsetup.c | 3 +-- src/hostname/hostnamed.c | 3 +-- src/import/importd.c | 5 +---- src/journal-remote/journal-gatewayd.c | 3 +-- src/journal-remote/journal-upload-journal.c | 3 +-- src/journal/journald-audit.c | 3 +-- src/journal/test-journal-verify.c | 3 +-- src/libsystemd-network/sd-ipv4ll.c | 3 +-- src/libsystemd/sd-bus/bus-creds.c | 3 +-- src/libsystemd/sd-netlink/netlink-message.c | 3 +-- src/login/logind-button.c | 3 +-- src/machine/machinectl.c | 3 +-- src/network/networkd-netdev-bond.c | 3 +-- src/random-seed/random-seed.c | 3 +-- src/resolve-host/resolve-host.c | 3 +-- src/resolve/resolved-dns-cache.c | 3 +-- src/shared/logs-show.c | 3 +-- src/systemctl/systemctl.c | 3 +-- src/udev/net/ethtool-util.c | 3 +-- src/udev/scsi_id/scsi_serial.c | 3 +-- src/udev/udev-ctrl.c | 6 ++---- src/udev/udev-rules.c | 3 +-- src/udev/udevd.c | 3 +-- src/update-utmp/update-utmp.c | 4 +--- src/user-sessions/user-sessions.c | 3 +-- 35 files changed, 56 insertions(+), 80 deletions(-) create mode 100644 coccinelle/empty-if.cocci (limited to 'src/journal-remote') diff --git a/coccinelle/empty-if.cocci b/coccinelle/empty-if.cocci new file mode 100644 index 0000000000..ebd0bfddce --- /dev/null +++ b/coccinelle/empty-if.cocci @@ -0,0 +1,19 @@ +@@ +expression e, f; +statement s, t; +@@ +( +if (e) { +if (f) s +} +| +if (e) { +if (f) s +else t +} +| +- if (e) { ++ if (e) +s +- } +) diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index e38a4340b6..bce8026f40 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -844,11 +844,8 @@ static int list_dependencies_one(sd_bus *bus, const char *name, unsigned int lev STRV_FOREACH(c, deps) { times = hashmap_get(unit_times_hashmap, *c); - if (times && times->activated - && times->activated <= boot->finish_time - && (service_longest - times->activated) <= arg_fuzz) { + if (times && times->activated && times->activated <= boot->finish_time && (service_longest - times->activated) <= arg_fuzz) to_print++; - } } if (!to_print) diff --git a/src/basic/strv.c b/src/basic/strv.c index aa68d290f6..b9aef64b15 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -270,9 +270,8 @@ char **strv_split_newlines(const char *s) { if (n <= 0) return l; - if (isempty(l[n-1])) { + if (isempty(l[n - 1])) l[n - 1] = mfree(l[n - 1]); - } return l; } @@ -291,9 +290,8 @@ int strv_split_extract(char ***t, const char *s, const char *separators, Extract r = extract_first_word(&s, &word, separators, flags); if (r < 0) return r; - if (r == 0) { + if (r == 0) break; - } if (!GREEDY_REALLOC(l, allocated, n + 2)) return -ENOMEM; diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c index 322cec84a9..e61b58b5e5 100644 --- a/src/bootchart/bootchart.c +++ b/src/bootchart/bootchart.c @@ -438,10 +438,9 @@ int main(int argc, char *argv[]) { res = nanosleep(&req, NULL); if (res) { - if (errno == EINTR) { + if (errno == EINTR) /* caught signal, probably HUP! */ break; - } log_error_errno(errno, "nanosleep() failed: %m"); return EXIT_FAILURE; } diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c index a7ef653d5d..1231e6eace 100644 --- a/src/bootchart/svg.c +++ b/src/bootchart/svg.c @@ -630,12 +630,11 @@ static void svg_io_bi_bar(FILE *of, pbi * (arg_scale_y * 5)); /* labels around highest value */ - if (i == max_here) { + if (i == max_here) fprintf(of, " %0.2fmb/sec\n", time_to_graph(sampledata->sampletime - graph_start) + 5, ((arg_scale_y * 5) - (pbi * (arg_scale_y * 5))) + 15, max / 1024.0 / (interval / 1000000000.0)); - } i++; prev_sampledata = sampledata; @@ -743,12 +742,11 @@ static void svg_io_bo_bar(FILE *of, pbo * (arg_scale_y * 5)); /* labels around highest bo value */ - if (i == max_here) { + if (i == max_here) fprintf(of, " %0.2fmb/sec\n", time_to_graph(sampledata->sampletime - graph_start) + 5, ((arg_scale_y * 5) - (pbo * (arg_scale_y * 5))), max / 1024.0 / (interval / 1000000000.0)); - } i++; prev_sampledata = sampledata; diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 0299fe7603..b695c57da8 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -3568,12 +3568,11 @@ int unit_load_fragment(Unit *u) { if (r < 0) return r; - if (u->load_state == UNIT_STUB) { + if (u->load_state == UNIT_STUB) /* Hmm, this didn't work? Then let's get rid * of the fragment path stored for us, so that * we don't point to an invalid location. */ u->fragment_path = mfree(u->fragment_path); - } } /* Look for a template */ diff --git a/src/core/main.c b/src/core/main.c index 091af6a9df..9aaf244e71 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1204,12 +1204,11 @@ static int status_welcome(void) { "PRETTY_NAME", &pretty_name, "ANSI_COLOR", &ansi_color, NULL); - if (r == -ENOENT) { + if (r == -ENOENT) r = parse_env_file("/usr/lib/os-release", NEWLINE, "PRETTY_NAME", &pretty_name, "ANSI_COLOR", &ansi_color, NULL); - } if (r < 0 && r != -ENOENT) log_warning_errno(r, "Failed to read os-release file: %m"); diff --git a/src/core/manager.c b/src/core/manager.c index cd0513fd69..d918007bb8 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2792,9 +2792,8 @@ static void trim_generator_dir(Manager *m, char **generator) { if (!*generator) return; - if (rmdir(*generator) >= 0) { + if (rmdir(*generator) >= 0) *generator = mfree(*generator); - } return; } diff --git a/src/core/service.c b/src/core/service.c index 1cf1fcffdc..e396dbe213 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -695,13 +695,12 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) { fprintf(f, "%sStatus Text: %s\n", prefix, s->status_text); - if (s->n_fd_store_max > 0) { + if (s->n_fd_store_max > 0) fprintf(f, "%sFile Descriptor Store Max: %u\n" "%sFile Descriptor Store Current: %u\n", prefix, s->n_fd_store_max, prefix, s->n_fd_store); - } } static int service_load_pid_file(Service *s, bool may_warn) { diff --git a/src/core/transaction.c b/src/core/transaction.c index b505297e23..b8f69ec6f3 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -380,12 +380,10 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi "Found dependency on %s/%s", k->unit->id, job_type_to_string(k->type)); - if (!delete && hashmap_get(tr->jobs, k->unit) && - !unit_matters_to_anchor(k->unit, k)) { + if (!delete && hashmap_get(tr->jobs, k->unit) && !unit_matters_to_anchor(k->unit, k)) /* Ok, we can drop this one, so let's * do so. */ delete = k; - } /* Check if this in fact was the beginning of * the cycle */ diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 74fa90a233..5d5872b7f4 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -329,12 +329,11 @@ static int get_password(const char *vol, const char *src, usec_t until, bool acc description = disk_description(src); mount_point = disk_mount_point(vol); - if (description && streq(vol, description)) { + if (description && streq(vol, description)) /* If the description string is simply the * volume name, then let's not show this * twice */ description = mfree(description); - } if (mount_point && description) r = asprintf(&name_buffer, "%s (%s) on %s", description, vol, mount_point); diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index e1ce2e6b31..cb837e9d03 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -113,12 +113,11 @@ static int context_read_data(Context *c) { "PRETTY_NAME", &c->data[PROP_OS_PRETTY_NAME], "CPE_NAME", &c->data[PROP_OS_CPE_NAME], NULL); - if (r == -ENOENT) { + if (r == -ENOENT) r = parse_env_file("/usr/lib/os-release", NEWLINE, "PRETTY_NAME", &c->data[PROP_OS_PRETTY_NAME], "CPE_NAME", &c->data[PROP_OS_CPE_NAME], NULL); - } if (r < 0 && r != -ENOENT) return r; diff --git a/src/import/importd.c b/src/import/importd.c index ffff94ee72..b91300a5df 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -600,12 +600,9 @@ static int manager_on_notify(sd_event_source *s, int fd, uint32_t revents, void cmsg_close_all(&msghdr); CMSG_FOREACH(cmsg, &msghdr) { - if (cmsg->cmsg_level == SOL_SOCKET && - cmsg->cmsg_type == SCM_CREDENTIALS && - cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred))) { + if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDENTIALS && cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred))) ucred = (struct ucred*) CMSG_DATA(cmsg); - } } if (msghdr.msg_flags & MSG_TRUNC) { diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index 52078b1b37..bb762c8832 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -337,9 +337,8 @@ static int request_parse_range( return -ENOMEM; m->cursor[strcspn(m->cursor, WHITESPACE)] = 0; - if (isempty(m->cursor)) { + if (isempty(m->cursor)) m->cursor = mfree(m->cursor); - } return 0; } diff --git a/src/journal-remote/journal-upload-journal.c b/src/journal-remote/journal-upload-journal.c index 3d2e52cacf..507210f51c 100644 --- a/src/journal-remote/journal-upload-journal.c +++ b/src/journal-remote/journal-upload-journal.c @@ -374,10 +374,9 @@ int open_journal_for_upload(Uploader *u, if (cursor) { r = sd_journal_seek_cursor(j, cursor); - if (r < 0) { + if (r < 0) return log_error_errno(r, "Failed to seek to cursor %s: %m", cursor); - } } return process_journal_input(u, 1 + !!after_cursor); diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c index 83c3332abf..fe8ae194c9 100644 --- a/src/journal/journald-audit.c +++ b/src/journal/journald-audit.c @@ -324,10 +324,9 @@ static int map_all_fields( if (r < 0) return log_debug_errno(r, "Failed to parse audit array: %m"); - if (r == 0) { + if (r == 0) /* Couldn't process as generic field, let's just skip over it */ p += strcspn(p, WHITESPACE); - } } } } diff --git a/src/journal/test-journal-verify.c b/src/journal/test-journal-verify.c index d24502d9a8..9dd9cb853f 100644 --- a/src/journal/test-journal-verify.c +++ b/src/journal/test-journal-verify.c @@ -118,12 +118,11 @@ int main(int argc, char *argv[]) { assert_se(journal_file_verify(f, verification_key, &from, &to, &total, true) >= 0); - if (verification_key && JOURNAL_HEADER_SEALED(f->header)) { + if (verification_key && JOURNAL_HEADER_SEALED(f->header)) log_info("=> Validated from %s to %s, %s missing", format_timestamp(a, sizeof(a), from), format_timestamp(b, sizeof(b), to), format_timespan(c, sizeof(c), total > to ? total - to : 0, 0)); - } journal_file_close(f); diff --git a/src/libsystemd-network/sd-ipv4ll.c b/src/libsystemd-network/sd-ipv4ll.c index 0fc05e1484..14b9444dab 100644 --- a/src/libsystemd-network/sd-ipv4ll.c +++ b/src/libsystemd-network/sd-ipv4ll.c @@ -463,9 +463,8 @@ int sd_ipv4ll_get_address(sd_ipv4ll *ll, struct in_addr *address){ assert_return(ll, -EINVAL); assert_return(address, -EINVAL); - if (ll->claimed_address == 0) { + if (ll->claimed_address == 0) return -ENOENT; - } address->s_addr = ll->claimed_address; return 0; diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c index 99b9aa8084..6826e21665 100644 --- a/src/libsystemd/sd-bus/bus-creds.c +++ b/src/libsystemd/sd-bus/bus-creds.c @@ -1014,9 +1014,8 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) { if (r != -EPERM && r != -EACCES) return r; } else { - if (c->cmdline_size == 0) { + if (c->cmdline_size == 0) c->cmdline = mfree(c->cmdline); - } c->mask |= SD_BUS_CREDS_CMDLINE; } diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c index e2a10ae2b4..7ac8949830 100644 --- a/src/libsystemd/sd-netlink/netlink-message.c +++ b/src/libsystemd/sd-netlink/netlink-message.c @@ -898,10 +898,9 @@ int sd_netlink_message_rewind(sd_netlink_message *m) { m->n_containers = 0; - if (m->containers[0].attributes) { + if (m->containers[0].attributes) /* top-level attributes have already been parsed */ return 0; - } assert(m->hdr); diff --git a/src/login/logind-button.c b/src/login/logind-button.c index cc98f5450e..f40e35a8cb 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -66,12 +66,11 @@ void button_free(Button *b) { sd_event_source_unref(b->io_event_source); sd_event_source_unref(b->check_event_source); - if (b->fd >= 0) { + if (b->fd >= 0) /* If the device has been unplugged close() returns * ENODEV, let's ignore this, hence we don't use * safe_close() */ (void) close(b->fd); - } free(b->name); free(b->seat); diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index bb8c5ac64b..7b8f6d1fab 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -597,7 +597,7 @@ static void print_machine_status_info(sd_bus *bus, MachineStatusInfo *i) { printf("\t Unit: %s\n", i->unit); show_unit_cgroup(bus, i->unit, i->leader); - if (arg_transport == BUS_TRANSPORT_LOCAL) { + if (arg_transport == BUS_TRANSPORT_LOCAL) show_journal_by_unit( stdout, @@ -611,7 +611,6 @@ static void print_machine_status_info(sd_bus *bus, MachineStatusInfo *i) { SD_JOURNAL_LOCAL_ONLY, true, NULL); - } } } diff --git a/src/network/networkd-netdev-bond.c b/src/network/networkd-netdev-bond.c index a60034dbe6..12e2321674 100644 --- a/src/network/networkd-netdev-bond.c +++ b/src/network/networkd-netdev-bond.c @@ -204,9 +204,8 @@ static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlin if (b->lacp_rate != _NETDEV_BOND_LACP_RATE_INVALID && b->mode == NETDEV_BOND_MODE_802_3AD) { r = sd_netlink_message_append_u8(m, IFLA_BOND_AD_LACP_RATE, b->lacp_rate ); - if (r < 0) { + if (r < 0) return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_LACP_RATE attribute: %m"); - } } if (b->miimon != 0) { diff --git a/src/random-seed/random-seed.c b/src/random-seed/random-seed.c index 92176b1e9f..f4778fc16a 100644 --- a/src/random-seed/random-seed.c +++ b/src/random-seed/random-seed.c @@ -54,10 +54,9 @@ int main(int argc, char *argv[]) { /* Read pool size, if possible */ f = fopen("/proc/sys/kernel/random/poolsize", "re"); if (f) { - if (fscanf(f, "%zu", &buf_size) > 0) { + if (fscanf(f, "%zu", &buf_size) > 0) /* poolsize is in bits on 2.6, but we want bytes */ buf_size /= 8; - } fclose(f); } diff --git a/src/resolve-host/resolve-host.c b/src/resolve-host/resolve-host.c index 9847effb53..22af092cc0 100644 --- a/src/resolve-host/resolve-host.c +++ b/src/resolve-host/resolve-host.c @@ -168,11 +168,10 @@ static int resolve_host(sd_bus *bus, const char *name) { if (r < 0) return bus_log_parse_error(r); - if (!streq(name, canonical)) { + if (!streq(name, canonical)) printf("%*s%s (%s)\n", (int) strlen(name), c == 0 ? name : "", c == 0 ? ":" : " ", canonical); - } if (c == 0) { log_error("%s: no addresses found", name); diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c index ef6b69c768..cbbbed8c8a 100644 --- a/src/resolve/resolved-dns-cache.c +++ b/src/resolve/resolved-dns-cache.c @@ -241,12 +241,11 @@ static void dns_cache_item_update_positive(DnsCache *c, DnsCacheItem *i, DnsReso i->type = DNS_CACHE_POSITIVE; - if (!i->by_key_prev) { + if (!i->by_key_prev) /* We are the first item in the list, we need to * update the key used in the hashmap */ assert_se(hashmap_replace(c->by_key, rr->key, i) >= 0); - } dns_resource_record_ref(rr); dns_resource_record_unref(i->rr); diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 9a5ffb7a6c..7790c1a3c8 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -334,10 +334,9 @@ static int output_short( break; case OUTPUT_SHORT_PRECISE: r = strftime(buf, sizeof(buf), "%b %d %H:%M:%S", gettime_r(&t, &tm)); - if (r > 0) { + if (r > 0) snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ".%06llu", (unsigned long long) (x % USEC_PER_SEC)); - } break; default: r = strftime(buf, sizeof(buf), "%b %d %H:%M:%S", gettime_r(&t, &tm)); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 96c39aa0a9..a82b9b83a2 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3585,7 +3585,7 @@ static void print_status_info( } } - if (i->id && arg_transport == BUS_TRANSPORT_LOCAL) { + if (i->id && arg_transport == BUS_TRANSPORT_LOCAL) show_journal_by_unit( stdout, i->id, @@ -3598,7 +3598,6 @@ static void print_status_info( SD_JOURNAL_LOCAL_ONLY, arg_scope == UNIT_FILE_SYSTEM, ellipsized); - } if (i->need_daemon_reload) warn_unit_file_changed(i->id); diff --git a/src/udev/net/ethtool-util.c b/src/udev/net/ethtool-util.c index 927b8abc64..a4b05d1bec 100644 --- a/src/udev/net/ethtool-util.c +++ b/src/udev/net/ethtool-util.c @@ -54,9 +54,8 @@ int ethtool_connect(int *ret) { assert_return(ret, -EINVAL); fd = socket(PF_INET, SOCK_DGRAM, 0); - if (fd < 0) { + if (fd < 0) return -errno; - } *ret = fd; diff --git a/src/udev/scsi_id/scsi_serial.c b/src/udev/scsi_id/scsi_serial.c index 3691a69d48..69260cb1a0 100644 --- a/src/udev/scsi_id/scsi_serial.c +++ b/src/udev/scsi_id/scsi_serial.c @@ -577,9 +577,8 @@ static int check_fill_0x83_id(struct udev *udev, if (id_search->id_type == SCSI_ID_NAA && wwn != NULL) { strncpy(wwn, &serial[s], 16); - if (wwn_vendor_extension != NULL) { + if (wwn_vendor_extension != NULL) strncpy(wwn_vendor_extension, &serial[s + 16], 16); - } } return 0; diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index 12bc6029b3..56277f551f 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -121,14 +121,12 @@ int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl) { err = bind(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen); } - if (err < 0) { + if (err < 0) return log_error_errno(errno, "bind failed: %m"); - } err = listen(uctrl->sock, 0); - if (err < 0) { + if (err < 0) return log_error_errno(errno, "listen failed: %m"); - } uctrl->bound = true; uctrl->cleanup_socket = true; diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 62e21e13a7..822f292217 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -672,9 +672,8 @@ static int import_parent_into_properties(struct udev_device *dev, const char *fi const char *key = udev_list_entry_get_name(list_entry); const char *val = udev_list_entry_get_value(list_entry); - if (fnmatch(filter, key, 0) == 0) { + if (fnmatch(filter, key, 0) == 0) udev_device_add_property(dev, key, val); - } } return 0; } diff --git a/src/udev/udevd.c b/src/udev/udevd.c index f354ced2e2..20497ae8be 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -1670,9 +1670,8 @@ int main(int argc, char *argv[]) { arg_children_max = 8; - if (sched_getaffinity(0, sizeof (cpu_set), &cpu_set) == 0) { + if (sched_getaffinity(0, sizeof(cpu_set), &cpu_set) == 0) arg_children_max += CPU_COUNT(&cpu_set) * 2; - } log_debug("set children_max to %u", arg_children_max); } diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c index a91c335381..b2998dce43 100644 --- a/src/update-utmp/update-utmp.c +++ b/src/update-utmp/update-utmp.c @@ -210,11 +210,9 @@ static int on_runlevel(Context *c) { runlevel > 0 ? runlevel : 'N') < 0) return log_oom(); - if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_RUNLEVEL, s, "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && - errno != EPERM) { + if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_RUNLEVEL, s, "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && errno != EPERM) r = log_error_errno(errno, "Failed to send audit message: %m"); - } } #endif diff --git a/src/user-sessions/user-sessions.c b/src/user-sessions/user-sessions.c index 4dd4e87b86..7c736c44d2 100644 --- a/src/user-sessions/user-sessions.c +++ b/src/user-sessions/user-sessions.c @@ -42,10 +42,9 @@ int main(int argc, char*argv[]) { if (streq(argv[1], "start")) { int r = 0; - if (unlink("/run/nologin") < 0 && errno != ENOENT) { + if (unlink("/run/nologin") < 0 && errno != ENOENT) r = log_error_errno(errno, "Failed to remove /run/nologin file: %m"); - } if (unlink("/etc/nologin") < 0 && errno != ENOENT) { /* If the file doesn't exist and /etc simply -- cgit v1.2.3-54-g00ecf