diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index cd0bc4fd13..27635ad899 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -1263,12 +1263,10 @@ int flush_accept(int fd) { int cfd; r = fd_wait_for_event(fd, POLLIN, 0); - if (r < 0) { - if (r == -EINTR) - continue; - + if (r == -EINTR) + continue; + if (r < 0) return r; - } if (r == 0) return 0; @@ -1305,12 +1303,10 @@ ssize_t flush_mqueue(int fd) { ssize_t l; r = fd_wait_for_event(fd, POLLIN, /* timeout= */ 0); - if (r < 0) { - if (r == -EINTR) - continue; - + if (r == -EINTR) + continue; + if (r < 0) return r; - } if (r == 0) return count; diff --git a/src/basic/virt.c b/src/basic/virt.c index 2493ef8ac7..707af529e0 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -199,12 +199,10 @@ static Virtualization detect_vm_dmi_vendor(void) { _cleanup_free_ char *s = NULL; r = read_one_line_file(*vendor, &s); - if (r < 0) { - if (r == -ENOENT) - continue; - + if (r == -ENOENT) + continue; + if (r < 0) return r; - } FOREACH_ELEMENT(dmi_vendor, dmi_vendor_table) if (startswith(s, dmi_vendor->vendor)) { diff --git a/src/core/import-creds.c b/src/core/import-creds.c index e0df078448..6d81d2ca63 100644 --- a/src/core/import-creds.c +++ b/src/core/import-creds.c @@ -810,12 +810,10 @@ static int report_credentials_per_func(const char *title, int (*get_directory_fu assert(get_directory_func); r = get_directory_func(&d); - if (r < 0) { - if (r == -ENXIO) /* Env var not set */ - return 0; - + if (r == -ENXIO) /* Env var not set */ + return 0; + if (r < 0) return log_warning_errno(r, "Failed to determine %s directory: %m", title); - } r = readdir_all_at(AT_FDCWD, d, RECURSE_DIR_SORT|RECURSE_DIR_IGNORE_DOT, &de); if (r < 0) diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index ca1ce53066..6e5fb6afc4 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -5573,16 +5573,13 @@ int config_parse_emergency_action( runtime_scope = ltype; /* otherwise, assume the scope is passed in via ltype */ r = parse_emergency_action(rvalue, runtime_scope, x); - if (r < 0) { - if (r == -EOPNOTSUPP) - log_syntax(unit, LOG_WARNING, filename, line, r, - "%s= specified as %s mode action, ignoring: %s", - lvalue, runtime_scope_to_string(runtime_scope), rvalue); - else - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse %s=, ignoring: %s", lvalue, rvalue); - return 0; - } + if (r == -EOPNOTSUPP) + log_syntax(unit, LOG_WARNING, filename, line, r, + "%s= specified as %s mode action, ignoring: %s", + lvalue, runtime_scope_to_string(runtime_scope), rvalue); + else if (r < 0) + log_syntax(unit, LOG_WARNING, filename, line, r, + "Failed to parse %s=, ignoring: %s", lvalue, rvalue); return 0; } diff --git a/src/core/manager-serialize.c b/src/core/manager-serialize.c index df97fde97e..2ce8e894eb 100644 --- a/src/core/manager-serialize.c +++ b/src/core/manager-serialize.c @@ -198,18 +198,16 @@ static int manager_deserialize_one_unit(Manager *m, const char *name, FILE *f, F int r; r = manager_load_unit(m, name, NULL, NULL, &u); - if (r < 0) { - if (r == -ENOMEM) - return r; + if (r == -ENOMEM) + return r; + if (r < 0) return log_notice_errno(r, "Failed to load unit \"%s\", skipping deserialization: %m", name); - } r = unit_deserialize_state(u, f, fds); - if (r < 0) { - if (r == -ENOMEM) - return r; + if (r == -ENOMEM) + return r; + if (r < 0) return log_notice_errno(r, "Failed to deserialize unit \"%s\", skipping: %m", name); - } return 0; } diff --git a/src/escape/escape-tool.c b/src/escape/escape-tool.c index 0742bf3f05..621182897d 100644 --- a/src/escape/escape-tool.c +++ b/src/escape/escape-tool.c @@ -174,23 +174,21 @@ static int run(int argc, char *argv[]) { case ACTION_ESCAPE: if (arg_path) { r = unit_name_path_escape(*i, &e); - if (r < 0) { - if (r == -EINVAL) { - /* If escaping failed because the string was invalid, let's print a - * friendly message about it. Catch these specific error cases - * explicitly. */ - - if (!path_is_valid(*i)) - return log_error_errno(r, "Input '%s' is not a valid file system path, failed to escape.", *i); - if (!path_is_absolute(*i)) - return log_error_errno(r, "Input '%s' is not an absolute file system path, failed to escape.", *i); - if (!path_is_normalized(*i)) - return log_error_errno(r, "Input '%s' is not a normalized file system path, failed to escape.", *i); - } + if (r == -EINVAL) { + /* If escaping failed because the string was invalid, let's print a + * friendly message about it. Catch these specific error cases + * explicitly. */ + if (!path_is_valid(*i)) + return log_error_errno(r, "Input '%s' is not a valid file system path, failed to escape.", *i); + if (!path_is_absolute(*i)) + return log_error_errno(r, "Input '%s' is not an absolute file system path, failed to escape.", *i); + if (!path_is_normalized(*i)) + return log_error_errno(r, "Input '%s' is not a normalized file system path, failed to escape.", *i); + } + if (r < 0) /* All other error cases. */ return log_error_errno(r, "Failed to escape string: %m"); - } /* If the escaping worked, then still warn if the path is not like we'd like * it. Because that means escaping is not necessarily reversible. */ diff --git a/src/home/homework-fscrypt.c b/src/home/homework-fscrypt.c index be61d2b36f..ac45c191d7 100644 --- a/src/home/homework-fscrypt.c +++ b/src/home/homework-fscrypt.c @@ -71,12 +71,10 @@ static int fscrypt_unlink_key(UserRecord *h) { char *d; r = keyring_describe(*key, &description); - if (r < 0) { - if (r == -ENOKEY) /* Something else deleted it already, that's ok. */ - continue; - + if (r == -ENOKEY) /* Something else deleted it already, that's ok. */ + continue; + if (r < 0) return log_error_errno(r, "Failed to describe key id %d: %m", *key); - } /* The description is the final element as per manpage. */ d = strrchr(description, ';'); diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 489343cddc..0b637c1fd9 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -2353,16 +2353,12 @@ int home_create_luks( 0, LOCK_EX, &setup->loop); - if (r < 0) { - if (r == -ENOENT) { /* this means /dev/loop-control doesn't exist, i.e. we are in a container - * or similar and loopback bock devices are not available, return a - * recognizable error in this case. */ - log_error_errno(r, "Loopback block device support is not available on this system."); - return -ENOLINK; /* Make recognizable */ - } - + if (r == -ENOENT) /* this means /dev/loop-control doesn't exist, i.e. we are in a container + * or similar and loopback bock devices are not available, return a + * recognizable error in this case. */ + return log_error_errno(SYNTHETIC_ERRNO(ENOLINK), "Loopback block device support is not available on this system."); + if (r < 0) return log_error_errno(r, "Failed to set up loopback device for %s: %m", setup->temporary_image_path); - } log_info("Setting up loopback device %s completed.", setup->loop->node ?: ip); diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 94d4a8647e..dbee88c452 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -1802,12 +1802,10 @@ int device_read_db_internal_filename(sd_device *device, const char *filename) { assert(filename); r = read_full_file(filename, &db, &db_len); - if (r < 0) { - if (r == -ENOENT) - return 0; - + if (r == -ENOENT) + return 0; + if (r < 0) return log_device_debug_errno(device, r, "sd-device: Failed to read db '%s': %m", filename); - } /* devices with a database entry are initialized */ device->is_initialized = true; diff --git a/src/login/logind-core.c b/src/login/logind-core.c index 4962aa0308..33f895f004 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -772,14 +772,13 @@ int manager_read_efi_boot_loader_entries(Manager *m) { return 0; r = efi_loader_get_entries(&m->efi_boot_loader_entries); - if (r < 0) { - if (r == -ENOENT || ERRNO_IS_NOT_SUPPORTED(r)) { - log_debug_errno(r, "Boot loader reported no entries."); - m->efi_boot_loader_entries_set = true; - return 0; - } - return log_error_errno(r, "Failed to determine entries reported by boot loader: %m"); + if (r == -ENOENT || ERRNO_IS_NEG_NOT_SUPPORTED(r)) { + log_debug_errno(r, "Boot loader reported no entries."); + m->efi_boot_loader_entries_set = true; + return 0; } + if (r < 0) + return log_error_errno(r, "Failed to determine entries reported by boot loader: %m"); m->efi_boot_loader_entries_set = true; return 1; diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 6adcc789b7..1e729761ac 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -2820,15 +2820,13 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_ if (elapse == USEC_INFINITY) { if (m->maintenance_time) { r = calendar_spec_next_usec(m->maintenance_time, now(CLOCK_REALTIME), &elapse); - if (r < 0) { - if (r == -ENOENT) - return sd_bus_error_set(error, - BUS_ERROR_DESIGNATED_MAINTENANCE_TIME_NOT_SCHEDULED, - "No upcoming maintenance window scheduled"); - + if (r == -ENOENT) + return sd_bus_error_set(error, + BUS_ERROR_DESIGNATED_MAINTENANCE_TIME_NOT_SCHEDULED, + "No upcoming maintenance window scheduled"); + if (r < 0) return sd_bus_error_set_errnof(error, r, "Failed to determine next maintenance window: %m"); - } log_info("Scheduled %s at maintenance window %s", type, FORMAT_TIMESTAMP(elapse)); } else diff --git a/src/repart/repart.c b/src/repart/repart.c index 497654d012..ad5f14299f 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -8297,13 +8297,12 @@ static int context_fstab(Context *context) { switch (arg_append_fstab) { case APPEND_AUTO: { r = read_full_file(path, &c, NULL); - if (r < 0) { - if (r == -ENOENT) { - log_debug("File fstab not found in %s", path); - break; - } - return log_error_errno(r, "Failed to open %s: %m", path); + if (r == -ENOENT) { + log_debug("File fstab not found in %s", path); + break; } + if (r < 0) + return log_error_errno(r, "Failed to open %s: %m", path); const char *acs, *ace; acs = find_line(c, AUTOMATIC_FSTAB_HEADER_START); @@ -9713,11 +9712,10 @@ static int parse_efi_variable_factory_reset(void) { return 0; r = efi_get_variable_string(EFI_SYSTEMD_VARIABLE_STR("FactoryReset"), &value); - if (r < 0) { - if (r == -ENOENT || ERRNO_IS_NOT_SUPPORTED(r)) - return 0; + if (r == -ENOENT || ERRNO_IS_NEG_NOT_SUPPORTED(r)) + return 0; + if (r < 0) return log_error_errno(r, "Failed to read EFI variable FactoryReset: %m"); - } log_warning("Warning, EFI variable FactoryReset is in use, please migrate to use FactoryResetRequest instead, support will be removed in v260!"); @@ -9738,11 +9736,10 @@ static int remove_efi_variable_factory_reset(void) { // FIXME: Remove this in v260, see above r = efi_set_variable(EFI_SYSTEMD_VARIABLE_STR("FactoryReset"), NULL, 0); - if (r < 0) { - if (r == -ENOENT || ERRNO_IS_NOT_SUPPORTED(r)) - return 0; + if (r == -ENOENT || ERRNO_IS_NEG_NOT_SUPPORTED(r)) + return 0; + if (r < 0) return log_error_errno(r, "Failed to remove EFI variable FactoryReset: %m"); - } log_info("Successfully unset EFI variable FactoryReset."); return 0; diff --git a/src/udev/udev-builtin-net_setup_link.c b/src/udev/udev-builtin-net_setup_link.c index 1277d0fb45..83f647da02 100644 --- a/src/udev/udev-builtin-net_setup_link.c +++ b/src/udev/udev-builtin-net_setup_link.c @@ -51,14 +51,12 @@ static int builtin_net_setup_link(UdevEvent *event, int argc, char **argv) { return log_device_warning_errno(dev, r, "Failed to get link information: %m"); r = link_get_config(ctx, link); - if (r < 0) { - if (r == -ENOENT) { - log_device_debug_errno(dev, r, "No matching link configuration found, ignoring device."); - return 0; - } - - return log_device_error_errno(dev, r, "Failed to get link config: %m"); + if (r == -ENOENT) { + log_device_debug_errno(dev, r, "No matching link configuration found, ignoring device."); + return 0; } + if (r < 0) + return log_device_error_errno(dev, r, "Failed to get link config: %m"); r = link_apply_config(ctx, link); if (r == -ENODEV)