diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/fd-util.c | 14 | ||||
-rw-r--r-- | src/basic/os-util.c | 14 | ||||
-rw-r--r-- | src/basic/psi-util.c | 8 | ||||
-rw-r--r-- | src/boot/bootctl-status.c | 11 | ||||
-rw-r--r-- | src/core/dbus-manager.c | 4 | ||||
-rw-r--r-- | src/core/execute.c | 53 | ||||
-rw-r--r-- | src/cryptenroll/cryptenroll-password.c | 12 | ||||
-rw-r--r-- | src/cryptsetup/cryptsetup.c | 9 | ||||
-rw-r--r-- | src/firstboot/firstboot.c | 12 | ||||
-rw-r--r-- | src/home/homework-directory.c | 7 | ||||
-rw-r--r-- | src/home/homework-luks.c | 25 | ||||
-rw-r--r-- | src/home/homework-quota.c | 28 | ||||
-rw-r--r-- | src/journal/journald-client.c | 11 | ||||
-rw-r--r-- | src/network/networkd-wiphy.c | 27 | ||||
-rw-r--r-- | src/nspawn/nspawn.c | 60 | ||||
-rw-r--r-- | src/resolve/resolved-manager.c | 23 | ||||
-rw-r--r-- | src/shared/ask-password-api.c | 30 | ||||
-rw-r--r-- | src/shared/copy.c | 22 | ||||
-rw-r--r-- | src/shared/kbd-util.c | 12 | ||||
-rw-r--r-- | src/shared/userdb-dropin.c | 30 | ||||
-rw-r--r-- | src/shared/utmp-wtmp.c | 7 | ||||
-rw-r--r-- | src/shared/varlink.c | 11 | ||||
-rw-r--r-- | src/stdio-bridge/stdio-bridge.c | 15 |
23 files changed, 189 insertions, 256 deletions
diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index 8640149af8..5292e41937 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -936,11 +936,10 @@ int path_is_root_at(int dir_fd, const char *path) { int mntid; r = path_get_mnt_id_at_fallback(dir_fd, "", &mntid); - if (r < 0) { - if (ERRNO_IS_NOT_SUPPORTED(r)) - return true; /* skip the mount ID check */ + if (ERRNO_IS_NEG_NOT_SUPPORTED(r)) + return true; /* skip the mount ID check */ + if (r < 0) return r; - } assert(mntid >= 0); st.nsx.stx_mnt_id = mntid; @@ -951,11 +950,10 @@ int path_is_root_at(int dir_fd, const char *path) { int mntid; r = path_get_mnt_id_at_fallback(dir_fd, "..", &mntid); - if (r < 0) { - if (ERRNO_IS_NOT_SUPPORTED(r)) - return true; /* skip the mount ID check */ + if (ERRNO_IS_NEG_NOT_SUPPORTED(r)) + return true; /* skip the mount ID check */ + if (r < 0) return r; - } assert(mntid >= 0); pst.nsx.stx_mnt_id = mntid; diff --git a/src/basic/os-util.c b/src/basic/os-util.c index 3046a40ebd..86318a8263 100644 --- a/src/basic/os-util.c +++ b/src/basic/os-util.c @@ -94,14 +94,12 @@ static int extension_release_strict_xattr_value(int extension_release_fd, const /* No xattr or cannot parse it? Then skip this. */ _cleanup_free_ char *extension_release_xattr = NULL; r = fgetxattr_malloc(extension_release_fd, "user.extension-release.strict", &extension_release_xattr); - if (r < 0) { - if (!ERRNO_IS_XATTR_ABSENT(r)) - return log_debug_errno(r, - "%s/%s: Failed to read 'user.extension-release.strict' extended attribute from file, ignoring: %m", - extension_release_dir_path, filename); - - return log_debug_errno(r, "%s/%s does not have user.extension-release.strict xattr, ignoring.", extension_release_dir_path, filename); - } + if (ERRNO_IS_NEG_XATTR_ABSENT(r)) + return log_debug_errno(r, "%s/%s does not have user.extension-release.strict xattr, ignoring.", + extension_release_dir_path, filename); + if (r < 0) + return log_debug_errno(r, "%s/%s: Failed to read 'user.extension-release.strict' extended attribute from file, ignoring: %m", + extension_release_dir_path, filename); /* Explicitly set to request strict matching? Skip it. */ r = parse_boolean(extension_release_xattr); diff --git a/src/basic/psi-util.c b/src/basic/psi-util.c index af8e278bd0..2a43b03d97 100644 --- a/src/basic/psi-util.c +++ b/src/basic/psi-util.c @@ -118,12 +118,10 @@ int is_pressure_supported(void) { FOREACH_STRING(p, "/proc/pressure/cpu", "/proc/pressure/io", "/proc/pressure/memory") { r = read_virtual_file(p, 0, NULL, NULL); - if (r < 0) { - if (r == -ENOENT || ERRNO_IS_NOT_SUPPORTED(r)) - return (cached = false); - + if (r == -ENOENT || ERRNO_IS_NEG_NOT_SUPPORTED(r)) + return (cached = false); + if (r < 0) return r; - } } return (cached = true); diff --git a/src/boot/bootctl-status.c b/src/boot/bootctl-status.c index 65f351031d..a6520e0719 100644 --- a/src/boot/bootctl-status.c +++ b/src/boot/bootctl-status.c @@ -43,12 +43,11 @@ static int boot_config_load_and_select( _cleanup_strv_free_ char **efi_entries = NULL; r = efi_loader_get_entries(&efi_entries); - if (r < 0) { - if (r == -ENOENT || ERRNO_IS_NOT_SUPPORTED(r)) - log_debug_errno(r, "Boot loader reported no entries."); - else - log_warning_errno(r, "Failed to determine entries reported by boot loader, ignoring: %m"); - } else + if (r == -ENOENT || ERRNO_IS_NEG_NOT_SUPPORTED(r)) + log_debug_errno(r, "Boot loader reported no entries."); + else if (r < 0) + log_warning_errno(r, "Failed to determine entries reported by boot loader, ignoring: %m"); + else (void) boot_config_augment_from_loader(config, efi_entries, /* only_auto= */ false); } diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 074de33eea..245c5f14f1 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -2191,9 +2191,9 @@ static int method_enqueue_marked_jobs(sd_bus_message *message, void *userdata, s r = bus_unit_queue_job_one(message, u, JOB_TRY_RESTART, JOB_FAIL, flags, reply, error); + if (ERRNO_IS_NEG_RESOURCE(r)) + return r; if (r < 0) { - if (ERRNO_IS_RESOURCE(r)) - return r; if (ret >= 0) ret = r; sd_bus_error_free(error); diff --git a/src/core/execute.c b/src/core/execute.c index 854e40ed6d..a81a7d57d4 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -5112,27 +5112,24 @@ static int exec_child( } if (context->oom_score_adjust_set) { - /* When we can't make this change due to EPERM, then let's silently skip over it. User namespaces - * prohibit write access to this file, and we shouldn't trip up over that. */ + /* When we can't make this change due to EPERM, then let's silently skip over it. User + * namespaces prohibit write access to this file, and we shouldn't trip up over that. */ r = set_oom_score_adjust(context->oom_score_adjust); - if (r < 0) { - if (ERRNO_IS_PRIVILEGE(r)) - log_unit_debug_errno(unit, r, "Failed to adjust OOM setting, assuming containerized execution, ignoring: %m"); - else { - *exit_status = EXIT_OOM_ADJUST; - return log_unit_error_errno(unit, r, "Failed to adjust OOM setting: %m"); - } + if (ERRNO_IS_NEG_PRIVILEGE(r)) + log_unit_debug_errno(unit, r, + "Failed to adjust OOM setting, assuming containerized execution, ignoring: %m"); + else if (r < 0) { + *exit_status = EXIT_OOM_ADJUST; + return log_unit_error_errno(unit, r, "Failed to adjust OOM setting: %m"); } } if (context->coredump_filter_set) { r = set_coredump_filter(context->coredump_filter); - if (r < 0) { - if (ERRNO_IS_PRIVILEGE(r)) - log_unit_debug_errno(unit, r, "Failed to adjust coredump_filter, ignoring: %m"); - else - return log_unit_error_errno(unit, r, "Failed to adjust coredump_filter: %m"); - } + if (ERRNO_IS_NEG_PRIVILEGE(r)) + log_unit_debug_errno(unit, r, "Failed to adjust coredump_filter, ignoring: %m"); + else if (r < 0) + return log_unit_error_errno(unit, r, "Failed to adjust coredump_filter: %m"); } if (context->nice_set) { @@ -5180,13 +5177,11 @@ static int exec_child( if (mpol_is_valid(numa_policy_get_type(&context->numa_policy))) { r = apply_numa_policy(&context->numa_policy); - if (r < 0) { - if (ERRNO_IS_NOT_SUPPORTED(r)) - log_unit_debug_errno(unit, r, "NUMA support not available, ignoring."); - else { - *exit_status = EXIT_NUMA_POLICY; - return log_unit_error_errno(unit, r, "Failed to set NUMA memory policy: %m"); - } + if (ERRNO_IS_NEG_NOT_SUPPORTED(r)) + log_unit_debug_errno(unit, r, "NUMA support not available, ignoring."); + else if (r < 0) { + *exit_status = EXIT_NUMA_POLICY; + return log_unit_error_errno(unit, r, "Failed to set NUMA memory policy: %m"); } } @@ -5468,14 +5463,12 @@ static int exec_child( * namespace without the ability to set up "lo". Hence gracefully skip things then. */ if (ns_type_supported(NAMESPACE_NET) && have_effective_cap(CAP_NET_ADMIN) > 0) { r = setup_shareable_ns(runtime->shared->netns_storage_socket, CLONE_NEWNET); - if (r < 0) { - if (ERRNO_IS_PRIVILEGE(r)) - log_unit_notice_errno(unit, r, - "PrivateNetwork=yes is configured, but network namespace setup not permitted, proceeding without: %m"); - else { - *exit_status = EXIT_NETWORK; - return log_unit_error_errno(unit, r, "Failed to set up network namespacing: %m"); - } + if (ERRNO_IS_NEG_PRIVILEGE(r)) + log_unit_notice_errno(unit, r, + "PrivateNetwork=yes is configured, but network namespace setup not permitted, proceeding without: %m"); + else if (r < 0) { + *exit_status = EXIT_NETWORK; + return log_unit_error_errno(unit, r, "Failed to set up network namespacing: %m"); } } else if (context->network_namespace_path) { *exit_status = EXIT_NETWORK; diff --git a/src/cryptenroll/cryptenroll-password.c b/src/cryptenroll/cryptenroll-password.c index 9deb98f202..c35b6092c8 100644 --- a/src/cryptenroll/cryptenroll-password.c +++ b/src/cryptenroll/cryptenroll-password.c @@ -159,13 +159,11 @@ int enroll_password( } r = check_password_quality(new_password, /* old */ NULL, /* user */ NULL, &error); - if (r < 0) { - if (ERRNO_IS_NOT_SUPPORTED(r)) - log_warning("Password quality check is not supported, proceeding anyway."); - else - return log_error_errno(r, "Failed to check password quality: %m"); - } - if (r == 0) + if (ERRNO_IS_NEG_NOT_SUPPORTED(r)) + log_warning("Password quality check is not supported, proceeding anyway."); + else if (r < 0) + return log_error_errno(r, "Failed to check password quality: %m"); + else if (r == 0) log_warning("Specified password does not pass quality checks (%s), proceeding anyway.", error); keyslot = crypt_keyslot_add_by_volume_key( diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index b5aa396cde..1ce95b3d7e 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -1728,11 +1728,12 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2( found_some ? "No TPM2 metadata matching the current system state found in LUKS2 header, falling back to traditional unlocking." : "No TPM2 metadata enrolled in LUKS2 header, falling back to traditional unlocking."); - if (r < 0) { - if (ERRNO_IS_NOT_SUPPORTED(r)) /* TPM2 support not compiled in? */ - return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), "TPM2 support not available, falling back to traditional unlocking."); + if (ERRNO_IS_NEG_NOT_SUPPORTED(r)) + /* TPM2 support not compiled in? */ + return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), + "TPM2 support not available, falling back to traditional unlocking."); + if (r < 0) return r; - } found_some = true; diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 59d4dcd118..87a82df4ee 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -792,13 +792,11 @@ static int prompt_root_password(int rfd) { } r = check_password_quality(*a, /* old */ NULL, "root", &error); - if (r < 0) { - if (ERRNO_IS_NOT_SUPPORTED(r)) - log_warning("Password quality check is not supported, proceeding anyway."); - else - return log_error_errno(r, "Failed to check password quality: %m"); - } - if (r == 0) + if (ERRNO_IS_NEG_NOT_SUPPORTED(r)) + log_warning("Password quality check is not supported, proceeding anyway."); + else if (r < 0) + return log_error_errno(r, "Failed to check password quality: %m"); + else if (r == 0) log_warning("Password is weak, accepting anyway: %s", error); r = ask_password_tty(-1, msg2, NULL, 0, 0, NULL, &b); diff --git a/src/home/homework-directory.c b/src/home/homework-directory.c index 4ec5f3dde1..6870ae9891 100644 --- a/src/home/homework-directory.c +++ b/src/home/homework-directory.c @@ -285,11 +285,10 @@ int home_resize_directory( return r; r = home_update_quota_auto(h, NULL); - if (r < 0) { - if (ERRNO_IS_NOT_SUPPORTED(r)) - return -ESOCKTNOSUPPORT; /* make recognizable */ + if (ERRNO_IS_NEG_NOT_SUPPORTED(r)) + return -ESOCKTNOSUPPORT; /* make recognizable */ + if (r < 0) return r; - } r = home_store_embedded_identity(new_home, setup->root_fd, h->uid, embedded_home); if (r < 0) diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 23a29d5811..3b3090a136 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -498,11 +498,10 @@ static int acquire_open_luks_device( return r; r = sym_crypt_init_by_name(&cd, setup->dm_name); - if (r < 0) { - if ((ERRNO_IS_DEVICE_ABSENT(r) || r == -EINVAL) && graceful) - return 0; + if ((ERRNO_IS_NEG_DEVICE_ABSENT(r) || r == -EINVAL) && graceful) + return 0; + if (r < 0) return log_error_errno(r, "Failed to initialize cryptsetup context for %s: %m", setup->dm_name); - } cryptsetup_enable_logging(cd); @@ -1639,12 +1638,11 @@ int home_deactivate_luks(UserRecord *h, HomeSetup *setup) { cryptsetup_enable_logging(setup->crypt_device); r = sym_crypt_deactivate_by_name(setup->crypt_device, setup->dm_name, 0); - if (r < 0) { - if (ERRNO_IS_DEVICE_ABSENT(r) || r == -EINVAL) - log_debug_errno(r, "LUKS device %s is already detached.", setup->dm_node); - else - return log_info_errno(r, "LUKS device %s couldn't be deactivated: %m", setup->dm_node); - } else { + if (ERRNO_IS_NEG_DEVICE_ABSENT(r) || r == -EINVAL) + log_debug_errno(r, "LUKS device %s is already detached.", setup->dm_node); + else if (r < 0) + return log_info_errno(r, "LUKS device %s couldn't be deactivated: %m", setup->dm_node); + else { log_info("LUKS device detaching completed."); we_detached = true; } @@ -2026,11 +2024,10 @@ static int wait_for_devlink(const char *path) { return log_error_errno(SYNTHETIC_ERRNO(ETIMEDOUT), "Device link %s still hasn't shown up, giving up.", path); r = fd_wait_for_event(inotify_fd, POLLIN, until - w); - if (r < 0) { - if (ERRNO_IS_TRANSIENT(r)) - continue; + if (ERRNO_IS_NEG_TRANSIENT(r)) + continue; + if (r < 0) return log_error_errno(r, "Failed to watch inotify: %m"); - } (void) flush_fd(inotify_fd); } diff --git a/src/home/homework-quota.c b/src/home/homework-quota.c index 574d1556af..9c6b55a537 100644 --- a/src/home/homework-quota.c +++ b/src/home/homework-quota.c @@ -55,32 +55,26 @@ int home_update_quota_classic(UserRecord *h, const char *path) { return log_error_errno(SYNTHETIC_ERRNO(ENODEV), "File system %s not backed by a block device.", path); r = quotactl_devnum(QCMD_FIXED(Q_GETQUOTA, USRQUOTA), devno, h->uid, &req); - if (r < 0) { - if (ERRNO_IS_NOT_SUPPORTED(r)) - return log_error_errno(r, "No UID quota support on %s.", path); - - if (r != -ESRCH) - return log_error_errno(r, "Failed to query disk quota for UID " UID_FMT ": %m", h->uid); - + if (r == -ESRCH) zero(req); - } else { + else if (ERRNO_IS_NEG_NOT_SUPPORTED(r)) + return log_error_errno(r, "No UID quota support on %s.", path); + else if (r < 0) + return log_error_errno(r, "Failed to query disk quota for UID " UID_FMT ": %m", h->uid); + else if (FLAGS_SET(req.dqb_valid, QIF_BLIMITS) && h->disk_size / QIF_DQBLKSIZE == req.dqb_bhardlimit) { /* Shortcut things if everything is set up properly already */ - if (FLAGS_SET(req.dqb_valid, QIF_BLIMITS) && h->disk_size / QIF_DQBLKSIZE == req.dqb_bhardlimit) { - log_info("Configured quota already matches the intended setting, not updating quota."); - return 0; - } + log_info("Configured quota already matches the intended setting, not updating quota."); + return 0; } req.dqb_valid = QIF_BLIMITS; req.dqb_bsoftlimit = req.dqb_bhardlimit = h->disk_size / QIF_DQBLKSIZE; r = quotactl_devnum(QCMD_FIXED(Q_SETQUOTA, USRQUOTA), devno, h->uid, &req); - if (r < 0) { - if (r == -ESRCH) - return log_error_errno(SYNTHETIC_ERRNO(ENOTTY), "UID quota not available on %s.", path); - + if (r == -ESRCH) + return log_error_errno(SYNTHETIC_ERRNO(ENOTTY), "UID quota not available on %s.", path); + if (r < 0) return log_error_errno(r, "Failed to set disk quota for UID " UID_FMT ": %m", h->uid); - } log_info("Updated per-UID quota."); diff --git a/src/journal/journald-client.c b/src/journal/journald-client.c index 5aedf4e5b6..a40568f393 100644 --- a/src/journal/journald-client.c +++ b/src/journal/journald-client.c @@ -57,13 +57,11 @@ int client_context_read_log_filter_patterns(ClientContext *c, const char *cgroup return log_debug_errno(r, "Failed to get the unit's cgroup path for %s: %m", cgroup); r = cg_get_xattr_malloc(SYSTEMD_CGROUP_CONTROLLER, unit_cgroup, "user.journald_log_filter_patterns", &xattr); - if (r < 0) { - if (!ERRNO_IS_XATTR_ABSENT(r)) - return log_debug_errno(r, "Failed to get user.journald_log_filter_patterns xattr for %s: %m", unit_cgroup); - + if (ERRNO_IS_NEG_XATTR_ABSENT(r)) { client_set_filtering_patterns(c, NULL, NULL); return 0; - } + } else if (r < 0) + return log_debug_errno(r, "Failed to get user.journald_log_filter_patterns xattr for %s: %m", unit_cgroup); xattr_end = xattr + r; @@ -79,7 +77,8 @@ int client_context_read_log_filter_patterns(ClientContext *c, const char *cgroup * before writing to xattr. */ deny_list_xattr = memchr(xattr, (char)0xff, r); if (!deny_list_xattr) - return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG), "Missing delimiter in cgroup user.journald_log_filter_patterns attribute: %m"); + return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG), + "Missing delimiter in cgroup user.journald_log_filter_patterns attribute: %m"); r = client_parse_log_filter_nulstr(xattr, deny_list_xattr - xattr, &allow_list); if (r < 0) diff --git a/src/network/networkd-wiphy.c b/src/network/networkd-wiphy.c index 63874cdf98..13f2d7202e 100644 --- a/src/network/networkd-wiphy.c +++ b/src/network/networkd-wiphy.c @@ -214,11 +214,10 @@ int link_rfkilled(Link *link) { assert(link); r = link_get_wiphy(link, &w); - if (r < 0) { - if (ERRNO_IS_NOT_SUPPORTED(r) || ERRNO_IS_DEVICE_ABSENT(r)) - return false; /* Typically, non-wifi interface or running in container */ + if (ERRNO_IS_NEG_NOT_SUPPORTED(r) || ERRNO_IS_NEG_DEVICE_ABSENT(r)) + return false; /* Typically, non-wifi interface or running in container */ + if (r < 0) return log_link_debug_errno(link, r, "Could not get phy: %m"); - } return wiphy_rfkilled(w); } @@ -339,20 +338,16 @@ static int wiphy_update(Wiphy *w) { assert(w); r = wiphy_update_device(w); - if (r < 0) { - if (ERRNO_IS_DEVICE_ABSENT(r)) - log_wiphy_debug_errno(w, r, "Failed to update wiphy device, ignoring: %m"); - else - return log_wiphy_warning_errno(w, r, "Failed to update wiphy device: %m"); - } + if (ERRNO_IS_NEG_DEVICE_ABSENT(r)) + log_wiphy_debug_errno(w, r, "Failed to update wiphy device, ignoring: %m"); + else if (r < 0) + return log_wiphy_warning_errno(w, r, "Failed to update wiphy device: %m"); r = wiphy_update_rfkill(w); - if (r < 0) { - if (ERRNO_IS_DEVICE_ABSENT(r)) - log_wiphy_debug_errno(w, r, "Failed to update rfkill device, ignoring: %m"); - else - return log_wiphy_warning_errno(w, r, "Failed to update rfkill device: %m"); - } + if (ERRNO_IS_NEG_DEVICE_ABSENT(r)) + log_wiphy_debug_errno(w, r, "Failed to update rfkill device, ignoring: %m"); + else if (r < 0) + return log_wiphy_warning_errno(w, r, "Failed to update rfkill device: %m"); return 0; } diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 7eac4ca0bb..95e5bf29c5 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -2839,16 +2839,15 @@ static int setup_machine_id(const char *directory) { * container behaves nicely). */ r = id128_get_machine(directory, &arg_uuid); - if (r < 0) { - if (!ERRNO_IS_MACHINE_ID_UNSET(r)) /* If the file is missing, empty, or uninitialized, we don't mind */ - return log_error_errno(r, "Failed to read machine ID from container image: %m"); - + if (ERRNO_IS_NEG_MACHINE_ID_UNSET(r)) { + /* If the file is missing, empty, or uninitialized, we don't mind */ if (sd_id128_is_null(arg_uuid)) { r = sd_id128_randomize(&arg_uuid); if (r < 0) return log_error_errno(r, "Failed to acquire randomized machine UUID: %m"); } - } + } else if (r < 0) + return log_error_errno(r, "Failed to read machine ID from container image: %m"); return 0; } @@ -3826,20 +3825,19 @@ static int outer_child( arg_uid_shift != 0) { r = remount_idmap(directory, arg_uid_shift, arg_uid_range, UID_INVALID, REMOUNT_IDMAPPING_HOST_ROOT); - if (r < 0) { - if (r == -EINVAL || ERRNO_IS_NOT_SUPPORTED(r)) { - /* This might fail because the kernel or file system doesn't support idmapping. We - * can't really distinguish this nicely, nor do we have any guarantees about the - * error codes we see, could be EOPNOTSUPP or EINVAL. */ - if (arg_userns_ownership != USER_NAMESPACE_OWNERSHIP_AUTO) - return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), - "ID mapped mounts are apparently not available, sorry."); - - log_debug("ID mapped mounts are apparently not available on this kernel or for the selected file system, reverting to recursive chown()ing."); - arg_userns_ownership = USER_NAMESPACE_OWNERSHIP_CHOWN; - } else - return log_error_errno(r, "Failed to set up ID mapped mounts: %m"); - } else { + if (r == -EINVAL || ERRNO_IS_NEG_NOT_SUPPORTED(r)) { + /* This might fail because the kernel or file system doesn't support idmapping. We + * can't really distinguish this nicely, nor do we have any guarantees about the + * error codes we see, could be EOPNOTSUPP or EINVAL. */ + if (arg_userns_ownership != USER_NAMESPACE_OWNERSHIP_AUTO) + return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), + "ID mapped mounts are apparently not available, sorry."); + + log_debug("ID mapped mounts are apparently not available on this kernel or for the selected file system, reverting to recursive chown()ing."); + arg_userns_ownership = USER_NAMESPACE_OWNERSHIP_CHOWN; + } else if (r < 0) + return log_error_errno(r, "Failed to set up ID mapped mounts: %m"); + else { log_debug("ID mapped mounts available, making use of them."); idmap = true; } @@ -4264,15 +4262,13 @@ static int nspawn_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t r } n = recvmsg_safe(fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC); - if (n < 0) { - if (ERRNO_IS_TRANSIENT(n)) - return 0; - if (n == -EXFULL) { - log_warning("Got message with truncated control data (too many fds sent?), ignoring."); - return 0; - } + if (ERRNO_IS_NEG_TRANSIENT(n)) + return 0; + else if (n == -EXFULL) { + log_warning("Got message with truncated control data (too many fds sent?), ignoring."); + return 0; + } else if (n < 0) return log_warning_errno(n, "Couldn't read notification socket: %m"); - } cmsg_close_all(&msghdr); @@ -5414,13 +5410,11 @@ static int cant_be_in_netns(void) { return log_error_errno(errno, "Failed to allocate udev control socket: %m"); r = connect_unix_path(fd, AT_FDCWD, "/run/udev/control"); - if (r < 0) { - if (r == -ENOENT || ERRNO_IS_DISCONNECT(r)) - return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), - "Sorry, but --image= requires access to the host's /run/ hierarchy, since we need access to udev."); - + if (r == -ENOENT || ERRNO_IS_NEG_DISCONNECT(r)) + return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), + "Sorry, but --image= requires access to the host's /run/ hierarchy, since we need access to udev."); + if (r < 0) return log_error_errno(r, "Failed to connect socket to udev control socket: %m"); - } r = getpeercred(fd, &ucred); if (r < 0) diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index dc8629b050..43e7b95e17 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -796,13 +796,10 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) { iov = IOVEC_MAKE(DNS_PACKET_DATA(p), p->allocated); l = recvmsg_safe(fd, &mh, 0); - if (l < 0) { - if (ERRNO_IS_TRANSIENT(l)) - return 0; - return l; - } - if (l == 0) + if (ERRNO_IS_NEG_TRANSIENT(l)) return 0; + if (l <= 0) + return l; assert(!(mh.msg_flags & MSG_TRUNC)); @@ -914,11 +911,10 @@ static int sendmsg_loop(int fd, struct msghdr *mh, int flags) { return -errno; r = fd_wait_for_event(fd, POLLOUT, LESS_BY(end, now(CLOCK_MONOTONIC))); - if (r < 0) { - if (ERRNO_IS_TRANSIENT(r)) - continue; + if (ERRNO_IS_NEG_TRANSIENT(r)) + continue; + if (r < 0) return r; - } if (r == 0) return -ETIMEDOUT; } @@ -942,11 +938,10 @@ static int write_loop(int fd, void *message, size_t length) { return -errno; r = fd_wait_for_event(fd, POLLOUT, LESS_BY(end, now(CLOCK_MONOTONIC))); - if (r < 0) { - if (ERRNO_IS_TRANSIENT(r)) - continue; + if (ERRNO_IS_NEG_TRANSIENT(r)) + continue; + if (r < 0) return r; - } if (r == 0) return -ETIMEDOUT; } diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index ca6ba80cbd..f4697736d9 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -158,16 +158,14 @@ static int ask_password_keyring(const char *keyname, AskPasswordFlags flags, cha return -EUNATCH; r = lookup_key(keyname, &serial); - if (r < 0) { - /* when retrieving the distinction between "kernel or container manager don't support - * or allow this" and "no matching key known" doesn't matter. Note that we propagate - * EACCESS here (even if EPERM not) since that is used if the keyring is available but - * we lack access to the key. */ - if (ERRNO_IS_NOT_SUPPORTED(r) || r == -EPERM) - return -ENOKEY; - + if (ERRNO_IS_NEG_NOT_SUPPORTED(r) || r == -EPERM) + /* When retrieving, the distinction between "kernel or container manager don't support or + * allow this" and "no matching key known" doesn't matter. Note that we propagate EACCESS + * here (even if EPERM not) since that is used if the keyring is available, but we lack + * access to the key. */ + return -ENOKEY; + if (r < 0) return r; - } return retrieve_key(serial, ret); } @@ -867,14 +865,12 @@ int ask_password_agent( }; n = recvmsg_safe(socket_fd, &msghdr, 0); - if (n < 0) { - if (ERRNO_IS_TRANSIENT(n)) - continue; - if (n == -EXFULL) { - log_debug("Got message with truncated control data, ignoring."); - continue; - } - + if (ERRNO_IS_NEG_TRANSIENT(n)) + continue; + else if (n == -EXFULL) { + log_debug("Got message with truncated control data, ignoring."); + continue; + } else if (n < 0) { r = (int) n; goto finish; } diff --git a/src/shared/copy.c b/src/shared/copy.c index 04603fd20e..a2740857e9 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -844,14 +844,11 @@ static int fd_copy_fifo( r = RET_NERRNO(mkfifoat(dt, to, st->st_mode & 07777)); if (copy_flags & COPY_MAC_CREATE) mac_selinux_create_file_clear(); - if (r < 0) { - if (FLAGS_SET(copy_flags, COPY_GRACEFUL_WARN) && (ERRNO_IS_PRIVILEGE(r) || ERRNO_IS_NOT_SUPPORTED(r))) { - log_notice_errno(r, "Failed to copy fifo '%s', ignoring: %m", from); - return 0; - } - + if (FLAGS_SET(copy_flags, COPY_GRACEFUL_WARN) && (ERRNO_IS_NEG_PRIVILEGE(r) || ERRNO_IS_NEG_NOT_SUPPORTED(r))) { + log_notice_errno(r, "Failed to copy fifo '%s', ignoring: %m", from); + return 0; + } else if (r < 0) return r; - } if (fchownat(dt, to, uid_is_valid(override_uid) ? override_uid : st->st_uid, @@ -898,14 +895,11 @@ static int fd_copy_node( r = RET_NERRNO(mknodat(dt, to, st->st_mode, st->st_rdev)); if (copy_flags & COPY_MAC_CREATE) mac_selinux_create_file_clear(); - if (r < 0) { - if (FLAGS_SET(copy_flags, COPY_GRACEFUL_WARN) && (ERRNO_IS_PRIVILEGE(r) || ERRNO_IS_NOT_SUPPORTED(r))) { - log_notice_errno(r, "Failed to copy node '%s', ignoring: %m", from); - return 0; - } - + if (FLAGS_SET(copy_flags, COPY_GRACEFUL_WARN) && (ERRNO_IS_NEG_PRIVILEGE(r) || ERRNO_IS_NEG_NOT_SUPPORTED(r))) { + log_notice_errno(r, "Failed to copy node '%s', ignoring: %m", from); + return 0; + } else if (r < 0) return r; - } if (fchownat(dt, to, uid_is_valid(override_uid) ? override_uid : st->st_uid, diff --git a/src/shared/kbd-util.c b/src/shared/kbd-util.c index e6fe973471..e4e7926bf9 100644 --- a/src/shared/kbd-util.c +++ b/src/shared/kbd-util.c @@ -82,14 +82,12 @@ int get_keymaps(char ***ret) { &(struct recurse_dir_userdata) { .keymaps = keymaps, }); - if (r < 0) { - if (r == -ENOENT) - continue; - if (ERRNO_IS_RESOURCE(r)) - return log_warning_errno(r, "Failed to read keymap list from %s: %m", dir); - + if (r == -ENOENT) + continue; + if (ERRNO_IS_NEG_RESOURCE(r)) + return log_warning_errno(r, "Failed to read keymap list from %s: %m", dir); + if (r < 0) log_debug_errno(r, "Failed to read keymap list from %s, ignoring: %m", dir); - } } _cleanup_strv_free_ char **l = set_get_strv(keymaps); diff --git a/src/shared/userdb-dropin.c b/src/shared/userdb-dropin.c index 309f33b5b5..533fd0f0d3 100644 --- a/src/shared/userdb-dropin.c +++ b/src/shared/userdb-dropin.c @@ -57,14 +57,13 @@ static int load_user( } r = json_parse_file(NULL, j, JSON_PARSE_SENSITIVE, &privileged_v, NULL, NULL); - if (r < 0) { - if (ERRNO_IS_PRIVILEGE(r)) - have_privileged = false; - else if (r == -ENOENT) - have_privileged = true; /* if the privileged file doesn't exist, we are complete */ - else - return r; - } else { + if (ERRNO_IS_NEG_PRIVILEGE(r)) + have_privileged = false; + else if (r == -ENOENT) + have_privileged = true; /* if the privileged file doesn't exist, we are complete */ + else if (r < 0) + return r; + else { r = json_variant_merge(&v, privileged_v); if (r < 0) return r; @@ -202,14 +201,13 @@ static int load_group( } r = json_parse_file(NULL, j, JSON_PARSE_SENSITIVE, &privileged_v, NULL, NULL); - if (r < 0) { - if (ERRNO_IS_PRIVILEGE(r)) - have_privileged = false; - else if (r == -ENOENT) - have_privileged = true; /* if the privileged file doesn't exist, we are complete */ - else - return r; - } else { + if (ERRNO_IS_NEG_PRIVILEGE(r)) + have_privileged = false; + else if (r == -ENOENT) + have_privileged = true; /* if the privileged file doesn't exist, we are complete */ + else if (r < 0) + return r; + else { r = json_variant_merge(&v, privileged_v); if (r < 0) return r; diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c index 3a68cf8016..c79764ced0 100644 --- a/src/shared/utmp-wtmp.c +++ b/src/shared/utmp-wtmp.c @@ -313,11 +313,10 @@ static int write_to_terminal(const char *tty, const char *message) { return -ETIME; k = fd_wait_for_event(fd, POLLOUT, end - t); - if (k < 0) { - if (ERRNO_IS_TRANSIENT(k)) - continue; + if (ERRNO_IS_NEG_TRANSIENT(k)) + continue; + if (k < 0) return k; - } if (k == 0) return -ETIME; diff --git a/src/shared/varlink.c b/src/shared/varlink.c index 7685377cba..41c2daf02b 100644 --- a/src/shared/varlink.c +++ b/src/shared/varlink.c @@ -1368,14 +1368,11 @@ int varlink_flush(Varlink *v) { } r = fd_wait_for_event(v->fd, POLLOUT, USEC_INFINITY); - if (r < 0) { - if (ERRNO_IS_TRANSIENT(r)) - continue; - + if (ERRNO_IS_NEG_TRANSIENT(r)) + continue; + if (r < 0) return varlink_log_errno(v, r, "Poll failed on fd: %m"); - } - - assert(r != 0); + assert(r > 0); handle_revents(v, r); } diff --git a/src/stdio-bridge/stdio-bridge.c b/src/stdio-bridge/stdio-bridge.c index 12abc18524..48c29a67b4 100644 --- a/src/stdio-bridge/stdio-bridge.c +++ b/src/stdio-bridge/stdio-bridge.c @@ -195,13 +195,11 @@ static int run(int argc, char *argv[]) { continue; r = sd_bus_process(b, &m); - if (r < 0) { - /* treat 'connection reset by peer' as clean exit condition */ - if (ERRNO_IS_DISCONNECT(r)) - return 0; - + if (ERRNO_IS_NEG_DISCONNECT(r)) + /* Treat 'connection reset by peer' as clean exit condition */ + return 0; + if (r < 0) return log_error_errno(r, "Failed to process bus: %m"); - } if (m) { r = sd_bus_send(a, m, NULL); @@ -241,11 +239,8 @@ static int run(int argc, char *argv[]) { }; r = ppoll_usec(p, ELEMENTSOF(p), t); - if (r < 0) { - if (ERRNO_IS_TRANSIENT(r)) /* don't be bothered by signals, i.e. EINTR */ - continue; + if (r < 0 && !ERRNO_IS_TRANSIENT(r)) /* don't be bothered by signals, i.e. EINTR */ return log_error_errno(r, "ppoll() failed: %m"); - } } return 0; |