]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
various: use _NEG_ macros to reduce indentation
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 9 Aug 2023 15:03:15 +0000 (17:03 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 16 Aug 2023 10:52:56 +0000 (12:52 +0200)
No functional change intended.

23 files changed:
src/basic/fd-util.c
src/basic/os-util.c
src/basic/psi-util.c
src/boot/bootctl-status.c
src/core/dbus-manager.c
src/core/execute.c
src/cryptenroll/cryptenroll-password.c
src/cryptsetup/cryptsetup.c
src/firstboot/firstboot.c
src/home/homework-directory.c
src/home/homework-luks.c
src/home/homework-quota.c
src/journal/journald-client.c
src/network/networkd-wiphy.c
src/nspawn/nspawn.c
src/resolve/resolved-manager.c
src/shared/ask-password-api.c
src/shared/copy.c
src/shared/kbd-util.c
src/shared/userdb-dropin.c
src/shared/utmp-wtmp.c
src/shared/varlink.c
src/stdio-bridge/stdio-bridge.c

index 8640149af8c03fb39b136ec63ac5d0476a52b6cc..5292e41937af4c19792d39f60a663be78e075222 100644 (file)
@@ -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;
index 3046a40ebdcfbf7c8d609c56af0bb844322cd29f..86318a8263b816509bf6bf5e57e905889791a82d 100644 (file)
@@ -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);
index af8e278bd0615565dfcb9dfe75670541881885fd..2a43b03d97476ece55f9271d768b19a1f9481f8b 100644 (file)
@@ -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);
index 65f351031d733caaccf1e6e9a029fa289ece7dfe..a6520e07197a7ea1ccc9640d342062916de0c7e0 100644 (file)
@@ -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);
         }
 
index 074de33eeac45e03c365e63ef6ff8b81f79452bd..245c5f14f1fbd4d4bd4ebcb7604889a1ccc8486b 100644 (file)
@@ -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);
index 854e40ed6df44d341655dcc077fd759d0f946ebc..a81a7d57d484cfd8e3ac451363a42c6ad2a687bd 100644 (file)
@@ -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;
index 9deb98f202f214c1a8d56d2c9c68e907fe8bad9f..c35b6092c8ca25869ff0c9b3c20b0533ea738717 100644 (file)
@@ -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(
index b5aa396cde71bccb57f96be4059a285cb915eda2..1ce95b3d7e2391a7c25d1bc3fc6f7818bf872c91 100644 (file)
@@ -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;
 
index 59d4dcd118f85c4eeb6bb6b2913dedce5a36e3c9..87a82df4ee8302c95523a445a7718099f9575fd0 100644 (file)
@@ -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);
index 4ec5f3dde105524e120e91bf7fe20711e19e0e43..6870ae98916857d5bdd7d14eb9c5db5081190e4a 100644 (file)
@@ -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)
index 23a29d58113ffc7bea7604dbda80cb2a8cc76b44..3b3090a1368f44a6e25f2278109a4fd7746de567 100644 (file)
@@ -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);
         }
index 574d1556af18ea03298d4032ee61df99255894c9..9c6b55a537fb6b46bf2581da69dfb661189337a4 100644 (file)
@@ -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.");
 
index 5aedf4e5b622238471b2b66163e9e49222ba1c68..a40568f393112728224b4edbbddfbbb527b447bb 100644 (file)
@@ -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)
index 63874cdf98ec3c38ea1fe7a9cc14280c3e51fbe3..13f2d7202eb2b9c06d2d387f1f12068f9d2ab29b 100644 (file)
@@ -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;
 }
index 7eac4ca0bba5ff410e2596e8bb83dc0c8c580cd5..95e5bf29c5982a3711c2dea55391f6100244414e 100644 (file)
@@ -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)
index dc8629b050d5e8e70c6d2979a544abda072dc958..43e7b95e1796f28479a772a9c71ebb02835d9a63 100644 (file)
@@ -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;
         }
index ca6ba80cbd27d756e3bf62ba68f781205650ecf6..f4697736d9cc01b55a8e576e56da3867383c3bb3 100644 (file)
@@ -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;
                 }
index 04603fd20e963dfb130e163e3bad399d7b82b009..a2740857e9a3906f8432e9a3372c73244c6e7ef2 100644 (file)
@@ -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,
index e6fe973471bb093a05acefa22e9d50bbf50be0c4..e4e7926bf96556d17d7c9089d2d9824414ba52eb 100644 (file)
@@ -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);
index 309f33b5b5bb085521f5a75c547afe533b1828a1..533fd0f0d387b3eef3e13fdf56c781b823bb803f 100644 (file)
@@ -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;
index 3a68cf801691c2f464c2524870ee5da85cd5ea6c..c79764ced020a1a4f5040b33e784c51cb9148b47 100644 (file)
@@ -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;
 
index 7685377cba58c5ff8bb3919fcee2a33101eaf6f9..41c2daf02bd8d21e12338ed405a0adf8fa509839 100644 (file)
@@ -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);
         }
index 12abc18524859b81d5ff808b0f471e77590ab7cf..48c29a67b4cdf9ffea6a404c5b19a358f54c7b65 100644 (file)
@@ -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;