]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: assorted coccinelle fixes
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 9 Oct 2020 12:59:44 +0000 (14:59 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 9 Oct 2020 13:02:23 +0000 (15:02 +0200)
56 files changed:
src/analyze/analyze-security.c
src/analyze/analyze.c
src/basic/khash.c
src/basic/socket-label.c
src/busctl/busctl.c
src/core/dbus-cgroup.c
src/core/main.c
src/core/selinux-setup.c
src/core/service.c
src/coredump/coredump.c
src/coredump/coredumpctl.c
src/cryptsetup/cryptsetup-generator.c
src/cryptsetup/cryptsetup.c
src/fsck/fsck.c
src/home/homectl-fido2.c
src/home/homectl-pkcs11.c
src/home/homework.c
src/hostname/hostnamectl.c
src/import/import-fs.c
src/import/import.c
src/import/pull-common.c
src/import/pull.c
src/journal/compress.c
src/journal/journal-send.c
src/journal/journalctl.c
src/journal/test-journal-stream.c
src/libsystemd-network/sd-dhcp-lease.c
src/libsystemd-network/test-dhcp-server.c
src/libsystemd/sd-bus/test-bus-chat.c
src/libsystemd/sd-event/test-event.c
src/libsystemd/sd-hwdb/sd-hwdb.c
src/libsystemd/sd-netlink/test-netlink.c
src/libsystemd/sd-resolve/test-resolve.c
src/login/loginctl.c
src/login/logind-core.c
src/machine/machinectl.c
src/mount/mount-tool.c
src/network/networkd-dhcp-common.c
src/network/tc/gred.c
src/network/tc/teql.c
src/nspawn/nspawn-oci.c
src/nspawn/nspawn.c
src/nss-systemd/nss-systemd.c
src/portable/portable.c
src/resolve/resolvectl.c
src/resolve/resolved-dns-packet.c
src/resolve/resolved-dnssd.c
src/resolve/resolved-manager.c
src/run/run.c
src/shared/bus-util.c
src/shared/dissect-image.c
src/shared/pkcs11-util.c
src/shared/seccomp-util.c
src/systemctl/systemctl-logind.c
src/test/test-libudev.c
src/tmpfiles/tmpfiles.c

index 16ab4f893e129bdd31b0342811a6ebd68657e167..9c1d63030d18a899c33b85a7c1b7ef8d36235c8a 100644 (file)
@@ -2185,10 +2185,10 @@ int analyze_security(sd_bus *bus, char **units, AnalyzeSecurityFlags flags) {
                         if (r < 0)
                                 return log_error_errno(r, "Failed to mangle unit name '%s': %m", *i);
 
-                        if (!endswith(mangled, ".service")) {
-                                log_error("Unit %s is not a service unit, refusing.", *i);
-                                return -EINVAL;
-                        }
+                        if (!endswith(mangled, ".service"))
+                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                       "Unit %s is not a service unit, refusing.",
+                                                       *i);
 
                         if (unit_name_is_valid(mangled, UNIT_NAME_TEMPLATE)) {
                                 r = unit_name_replace_instance(mangled, "test-instance", &instance);
index a9e4b37573043d1a1eddf2fc421646f19973f2fd..591ba6d33cf73970fa2942daf03cfd6a0c06152d 100644 (file)
@@ -1248,8 +1248,7 @@ static int expand_patterns(sd_bus *bus, char **patterns, char ***ret) {
                 }
         }
 
-        *ret = expanded_patterns;
-        expanded_patterns = NULL; /* do not free */
+        *ret = TAKE_PTR(expanded_patterns); /* do not free */
 
         return 0;
 }
index e893298d6868a676f3d3e3b23f0cba0a7a8f9a1c..dbae418282b7c8ccd5f066d6bcd5d8a8a97c932e 100644 (file)
@@ -160,8 +160,7 @@ int khash_new_with_key(khash **ret, const char *algorithm, const void *key, size
         /* Temporary fix for rc kernel bug: https://bugzilla.redhat.com/show_bug.cgi?id=1395896 */
         (void) send(h->fd, NULL, 0, 0);
 
-        *ret = h;
-        h = NULL;
+        *ret = TAKE_PTR(h);
 
         return 0;
 }
index dd69eaaac2da520d8468179ba936d4dacea6f2b6..718a6953e5b57622c8e26ddf9855e6703b8978e7 100644 (file)
@@ -129,8 +129,5 @@ int socket_address_listen(
         if (p)
                 (void) touch(p);
 
-        r = fd;
-        fd = -1;
-
-        return r;
+        return TAKE_FD(fd);
 }
index 16dca649cf9c929cf7170a55d191d04f0b899fda..4d98941d748c1891ae09b536f4179810278cc7d6 100644 (file)
@@ -1130,14 +1130,13 @@ static int introspect(int argc, char **argv, void *userdata) {
 
         (void) pager_open(arg_pager_flags);
 
-        if (arg_legend) {
+        if (arg_legend)
                 printf("%-*s %-*s %-*s %-*s %s\n",
                        (int) name_width, "NAME",
                        (int) type_width, "TYPE",
                        (int) signature_width, "SIGNATURE",
                        (int) result_width, "RESULT/VALUE",
                        "FLAGS");
-        }
 
         for (j = 0; j < k; j++) {
                 _cleanup_free_ char *ellipsized = NULL;
index b7d2e32639a51699b5df2404c3260e73bb672a9c..9fdd3d83caf96562e9c3ffd2bcb480189c0069c4 100644 (file)
@@ -1500,9 +1500,9 @@ int bus_cgroup_set_property(
                                         LIST_PREPEND(device_allow, c->device_allow, a);
                                 }
 
-                                a->r = !!strchr(rwm, 'r');
-                                a->w = !!strchr(rwm, 'w');
-                                a->m = !!strchr(rwm, 'm');
+                                a->r = strchr(rwm, 'r');
+                                a->w = strchr(rwm, 'w');
+                                a->m = strchr(rwm, 'm');
                         }
 
                         n++;
index f957217eaaa1ce07417daea8c24d2feff6b8aacb..08504961a273d155b736c0f9b2e0c7a4ee3afdb3 100644 (file)
@@ -1064,13 +1064,11 @@ static int parse_argv(int argc, char *argv[]) {
                         assert_not_reached("Unhandled option code.");
                 }
 
-        if (optind < argc && getpid_cached() != 1) {
+        if (optind < argc && getpid_cached() != 1)
                 /* Hmm, when we aren't run as init system
                  * let's complain about excess arguments */
-
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                        "Excess arguments.");
-        }
 
         return 0;
 }
index 40da8dd0e5c03e5df34135c71764863265dcfa92..8c67352ddb478ab5d9d750511b8549a84688b921 100644 (file)
@@ -96,10 +96,9 @@ int mac_selinux_setup(bool *loaded_policy) {
                 log_open();
 
                 if (enforce > 0) {
-                        if (!initialized) {
-                                log_emergency("Failed to load SELinux policy.");
-                                return -EIO;
-                        }
+                        if (!initialized)
+                                return log_emergency_errno(SYNTHETIC_ERRNO(EIO),
+                                                           "Failed to load SELinux policy.");
 
                         log_warning("Failed to load new SELinux policy. Continuing with old policy.");
                 } else
index 863b6755b1d6068d4b5fff4ca071efd5051e7641..d23384c4758fef928c8979cb58425ba6cb764aae 100644 (file)
@@ -4201,7 +4201,7 @@ static void service_bus_name_owner_change(Unit *u, const char *new_owner) {
         else
                 log_unit_debug(u, "D-Bus name %s now not owned by anyone.", s->bus_name);
 
-        s->bus_name_good = !!new_owner;
+        s->bus_name_good = new_owner;
 
         /* Track the current owner, so we can reconstruct changes after a daemon reload */
         r = free_and_strdup(&s->bus_name_owner, new_owner);
index 229e2d8f87fcca151ac9578e0f1a1f0177acba95..104a051688e57d285eec6243f4233d55c9653720 100644 (file)
@@ -353,7 +353,7 @@ static int save_external_coredump(
         if (r < 0)
                 return log_error_errno(r, "Failed to parse resource limit '%s': %m",
                                        context->meta[META_ARGV_RLIMIT]);
-        if (rlimit < page_size()) {
+        if (rlimit < page_size())
                 /* Is coredumping disabled? Then don't bother saving/processing the
                  * coredump.  Anything below PAGE_SIZE cannot give a readable coredump
                  * (the kernel uses ELF_EXEC_PAGESIZE which is not easily accessible, but
@@ -361,7 +361,6 @@ static int save_external_coredump(
                 return log_info_errno(SYNTHETIC_ERRNO(EBADSLT),
                                       "Resource limits disable core dumping for process %s (%s).",
                                       context->meta[META_ARGV_PID], context->meta[META_COMM]);
-        }
 
         process_limit = MAX(arg_process_size_max, storage_size_max());
         if (process_limit == 0)
index 02502528afe2bf3909d53742410e29f8e19c64e5..f252c8175861f0eea9929a4f51320f17e50cd308 100644 (file)
@@ -888,10 +888,9 @@ static int dump_core(int argc, char **argv, void *userdata) {
         _cleanup_fclose_ FILE *f = NULL;
         int r;
 
-        if (arg_field) {
-                log_error("Option --field/-F only makes sense with list");
-                return -EINVAL;
-        }
+        if (arg_field)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Option --field/-F only makes sense with list");
 
         r = acquire_journal(&j, argv + 1);
         if (r < 0)
@@ -943,10 +942,9 @@ static int run_debug(int argc, char **argv, void *userdata) {
         if (!debugger)
                 return -ENOMEM;
 
-        if (arg_field) {
-                log_error("Option --field/-F only makes sense with list");
-                return -EINVAL;
-        }
+        if (arg_field)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Option --field/-F only makes sense with list");
 
         r = acquire_journal(&j, argv + 1);
         if (r < 0)
@@ -971,15 +969,13 @@ static int run_debug(int argc, char **argv, void *userdata) {
         if (!exe)
                 return log_oom();
 
-        if (endswith(exe, " (deleted)")) {
-                log_error("Binary already deleted.");
-                return -ENOENT;
-        }
+        if (endswith(exe, " (deleted)"))
+                return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
+                                       "Binary already deleted.");
 
-        if (!path_is_absolute(exe)) {
-                log_error("Binary is not an absolute path.");
-                return -ENOENT;
-        }
+        if (!path_is_absolute(exe))
+                return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
+                                       "Binary is not an absolute path.");
 
         r = save_core(j, NULL, &path, &unlink_path);
         if (r < 0)
index cd0cedf118cb123b80bbee99841e1372c64d69c6..bfd71cd595c5dd9ec4569e11b344d87252343eca 100644 (file)
@@ -378,14 +378,13 @@ static int create_disk(
                 else
                         fprintf(f, "Requires=%s\n", unit);
 
-                if (umount_unit) {
+                if (umount_unit)
                         fprintf(f,
                                 "Wants=%s\n"
                                 "Before=%s\n",
                                 umount_unit,
                                 umount_unit
                         );
-                }
         }
 
         if (!nofail)
index 10472bde26642c54804859602fe8491f38325eac..fb08b4a1a0bbdecb2aceee630dadaac4b4952ec9 100644 (file)
@@ -832,10 +832,9 @@ static int run(int argc, char *argv[]) {
         if (argc <= 1)
                 return help();
 
-        if (argc < 3) {
-                log_error("This program requires at least two arguments.");
-                return -EINVAL;
-        }
+        if (argc < 3)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "This program requires at least two arguments.");
 
         log_setup_service();
 
index 80f7107b9d9758aaac1445de1487b68ffd6a924b..472ba6d54985e08e64363dbe80384e215182d08c 100644 (file)
@@ -258,10 +258,9 @@ static int run(int argc, char *argv[]) {
 
         log_setup_service();
 
-        if (argc > 2) {
-                log_error("This program expects one or no arguments.");
-                return -EINVAL;
-        }
+        if (argc > 2)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "This program expects one or no arguments.");
 
         umask(0022);
 
@@ -284,10 +283,10 @@ static int run(int argc, char *argv[]) {
                 if (stat(device, &st) < 0)
                         return log_error_errno(errno, "Failed to stat %s: %m", device);
 
-                if (!S_ISBLK(st.st_mode)) {
-                        log_error("%s is not a block device.", device);
-                        return -EINVAL;
-                }
+                if (!S_ISBLK(st.st_mode))
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "%s is not a block device.",
+                                               device);
 
                 r = sd_device_new_from_devnum(&dev, 'b', st.st_rdev);
                 if (r < 0)
index eb9098fda95ec79f8902c562a4379edc12783dad..0019f59f0f676ce6a5bac70ec0bcd2837a4d82b1 100644 (file)
@@ -401,7 +401,8 @@ int identity_add_fido2_parameters(
 
         return 0;
 #else
-        return log_error_errno(EOPNOTSUPP, "FIDO2 tokens not supported on this build.");
+        return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+                               "FIDO2 tokens not supported on this build.");
 #endif
 }
 
@@ -467,7 +468,8 @@ finish:
         fido_dev_info_free(&di, allocated);
         return r;
 #else
-        return log_error_errno(EOPNOTSUPP, "FIDO2 tokens not supported on this build.");
+        return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+                               "FIDO2 tokens not supported on this build.");
 #endif
 }
 
index 0583171f042ea511afe55b1794ea897a6821edf2..592a6413e1d319e737b08df6d2393bbcf8851efe 100644 (file)
@@ -77,7 +77,9 @@ static int acquire_pkcs11_certificate(
 
         r = pkcs11_find_token(uri, pkcs11_callback, &data);
         if (r == -EAGAIN) /* pkcs11_find_token() doesn't log about this error, but all others */
-                return log_error_errno(ENXIO, "Specified PKCS#11 token with URI '%s' not found.", uri);
+                return log_error_errno(SYNTHETIC_ERRNO(ENXIO),
+                                       "Specified PKCS#11 token with URI '%s' not found.",
+                                       uri);
         if (r < 0)
                 return r;
 
@@ -86,7 +88,8 @@ static int acquire_pkcs11_certificate(
 
         return 0;
 #else
-        return log_error_errno(EOPNOTSUPP, "PKCS#11 tokens not supported on this build.");
+        return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+                               "PKCS#11 tokens not supported on this build.");
 #endif
 }
 
@@ -415,7 +418,8 @@ int list_pkcs11_tokens(void) {
 
         return 0;
 #else
-        return log_error_errno(EOPNOTSUPP, "PKCS#11 tokens not supported on this build.");
+        return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+                               "PKCS#11 tokens not supported on this build.");
 #endif
 }
 
index 14e2002c7325fab5e7177d046a901e08b2383869..4b924b2a7c0117afe93d0a195e76850fa40558f3 100644 (file)
@@ -910,7 +910,8 @@ static int user_record_compile_effective_passwords(
          * the old literal password only (and do not care for the old PKCS#11 token) */
 
         if (strv_isempty(h->hashed_password))
-                return log_error_errno(EINVAL, "User record has no hashed passwords, refusing.");
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "User record has no hashed passwords, refusing.");
 
         /* Generates the list of plaintext passwords to propagate to LUKS/fscrypt devices, and checks whether
          * we have a plaintext password for each hashed one. If we are missing one we'll fail, since we
index c6d8b8d08204891e8aff7576c3016182fbff2291..c38600b9c3f2c8e72afc23292861dc00229922a5 100644 (file)
@@ -194,10 +194,9 @@ static int show_status(int argc, char **argv, void *userdata) {
         if (arg_pretty || arg_static || arg_transient) {
                 const char *attr;
 
-                if (!!arg_static + !!arg_pretty + !!arg_transient > 1) {
-                        log_error("Cannot query more than one name type at a time");
-                        return -EINVAL;
-                }
+                if (!!arg_static + !!arg_pretty + !!arg_transient > 1)
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Cannot query more than one name type at a time");
 
                 attr = arg_pretty ? "PrettyHostname" :
                         arg_static ? "StaticHostname" : "Hostname";
index db55fa50d5d9f2cc8dffb75922c5b68b5ddecfb5..f631f857fc9ccbe932f7e8695a41b77172dcea60 100644 (file)
@@ -126,10 +126,10 @@ static int import_fs(int argc, char *argv[], void *userdata) {
         local = empty_or_dash_to_null(local);
 
         if (local) {
-                if (!machine_name_is_valid(local)) {
-                        log_error("Local image name '%s' is not valid.", local);
-                        return -EINVAL;
-                }
+                if (!machine_name_is_valid(local))
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Local image name '%s' is not valid.",
+                                               local);
 
                 if (!arg_force) {
                         r = image_find(IMAGE_MACHINE, local, NULL);
@@ -137,8 +137,9 @@ static int import_fs(int argc, char *argv[], void *userdata) {
                                 if (r != -ENOENT)
                                         return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
                         } else {
-                                log_error("Image '%s' already exists.", local);
-                                return -EEXIST;
+                                return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
+                                                       "Image '%s' already exists.",
+                                                       local);
                         }
                 }
         } else
index cc2855745962af444b4c0c30150c1b1e47b39cb3..64ec066a8f326e74921b4103d186075b53189bc3 100644 (file)
@@ -64,10 +64,10 @@ static int import_tar(int argc, char *argv[], void *userdata) {
 
                 local = ll;
 
-                if (!machine_name_is_valid(local)) {
-                        log_error("Local image name '%s' is not valid.", local);
-                        return -EINVAL;
-                }
+                if (!machine_name_is_valid(local))
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Local image name '%s' is not valid.",
+                                               local);
 
                 if (!arg_force) {
                         r = image_find(IMAGE_MACHINE, local, NULL);
@@ -75,8 +75,9 @@ static int import_tar(int argc, char *argv[], void *userdata) {
                                 if (r != -ENOENT)
                                         return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
                         } else {
-                                log_error("Image '%s' already exists.", local);
-                                return -EEXIST;
+                                return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
+                                                       "Image '%s' already exists.",
+                                                       local);
                         }
                 }
         } else
@@ -158,10 +159,10 @@ static int import_raw(int argc, char *argv[], void *userdata) {
 
                 local = ll;
 
-                if (!machine_name_is_valid(local)) {
-                        log_error("Local image name '%s' is not valid.", local);
-                        return -EINVAL;
-                }
+                if (!machine_name_is_valid(local))
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Local image name '%s' is not valid.",
+                                               local);
 
                 if (!arg_force) {
                         r = image_find(IMAGE_MACHINE, local, NULL);
@@ -169,8 +170,9 @@ static int import_raw(int argc, char *argv[], void *userdata) {
                                 if (r != -ENOENT)
                                         return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
                         } else {
-                                log_error("Image '%s' already exists.", local);
-                                return -EEXIST;
+                                return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
+                                                       "Image '%s' already exists.",
+                                                       local);
                         }
                 }
         } else
index 249ea533e63b63c474aef241c471df999be444e0..fdc70447e1286854b6d9d1473f52afc747d09e42 100644 (file)
@@ -389,10 +389,9 @@ int pull_verify(PullJob *main_job,
 
         assert(checksum_job->state == PULL_JOB_DONE);
 
-        if (!checksum_job->payload || checksum_job->payload_size <= 0) {
-                log_error("Checksum is empty, cannot verify.");
-                return -EBADMSG;
-        }
+        if (!checksum_job->payload || checksum_job->payload_size <= 0)
+                return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+                                       "Checksum is empty, cannot verify.");
 
         r = verify_one(checksum_job, main_job);
         if (r < 0)
@@ -414,10 +413,9 @@ int pull_verify(PullJob *main_job,
 
         assert(signature_job->state == PULL_JOB_DONE);
 
-        if (!signature_job->payload || signature_job->payload_size <= 0) {
-                log_error("Signature is empty, cannot verify.");
-                return -EBADMSG;
-        }
+        if (!signature_job->payload || signature_job->payload_size <= 0)
+                return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+                                       "Signature is empty, cannot verify.");
 
         r = pipe2(gpg_pipe, O_CLOEXEC);
         if (r < 0)
index 7e8712493fb5412592695a0e2f4bd412172e66be..9b27ec26306e7fbd19cf99580cc8d61f8158e855 100644 (file)
@@ -49,10 +49,9 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
         int r;
 
         url = argv[1];
-        if (!http_url_is_valid(url)) {
-                log_error("URL '%s' is not valid.", url);
-                return -EINVAL;
-        }
+        if (!http_url_is_valid(url))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "URL '%s' is not valid.", url);
 
         if (argc >= 3)
                 local = argv[2];
@@ -73,10 +72,10 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
 
                 local = ll;
 
-                if (!machine_name_is_valid(local)) {
-                        log_error("Local image name '%s' is not valid.", local);
-                        return -EINVAL;
-                }
+                if (!machine_name_is_valid(local))
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Local image name '%s' is not valid.",
+                                               local);
 
                 if (!arg_force) {
                         r = image_find(IMAGE_MACHINE, local, NULL);
@@ -84,8 +83,9 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
                                 if (r != -ENOENT)
                                         return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
                         } else {
-                                log_error("Image '%s' already exists.", local);
-                                return -EEXIST;
+                                return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
+                                                       "Image '%s' already exists.",
+                                                       local);
                         }
                 }
 
@@ -135,10 +135,9 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
         int r;
 
         url = argv[1];
-        if (!http_url_is_valid(url)) {
-                log_error("URL '%s' is not valid.", url);
-                return -EINVAL;
-        }
+        if (!http_url_is_valid(url))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "URL '%s' is not valid.", url);
 
         if (argc >= 3)
                 local = argv[2];
@@ -159,10 +158,10 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
 
                 local = ll;
 
-                if (!machine_name_is_valid(local)) {
-                        log_error("Local image name '%s' is not valid.", local);
-                        return -EINVAL;
-                }
+                if (!machine_name_is_valid(local))
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Local image name '%s' is not valid.",
+                                               local);
 
                 if (!arg_force) {
                         r = image_find(IMAGE_MACHINE, local, NULL);
@@ -170,8 +169,9 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
                                 if (r != -ENOENT)
                                         return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
                         } else {
-                                log_error("Image '%s' already exists.", local);
-                                return -EEXIST;
+                                return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
+                                                       "Image '%s' already exists.",
+                                                       local);
                         }
                 }
 
index 852f9e07bab3078d555eca373bbfe6c87463a0f9..a1bd4a379ede1661d79082fd3aa934279d20c7f8 100644 (file)
@@ -544,10 +544,10 @@ int compress_stream_xz(int fdf, int fdt, uint64_t max_bytes) {
         assert(fdt >= 0);
 
         ret = lzma_easy_encoder(&s, LZMA_PRESET_DEFAULT, LZMA_CHECK_CRC64);
-        if (ret != LZMA_OK) {
-                log_error("Failed to initialize XZ encoder: code %u", ret);
-                return -EINVAL;
-        }
+        if (ret != LZMA_OK)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Failed to initialize XZ encoder: code %u",
+                                       ret);
 
         for (;;) {
                 if (s.avail_in == 0 && action == LZMA_RUN) {
@@ -579,10 +579,10 @@ int compress_stream_xz(int fdf, int fdt, uint64_t max_bytes) {
                 }
 
                 ret = lzma_code(&s, action);
-                if (!IN_SET(ret, LZMA_OK, LZMA_STREAM_END)) {
-                        log_error("Compression failed: code %u", ret);
-                        return -EBADMSG;
-                }
+                if (!IN_SET(ret, LZMA_OK, LZMA_STREAM_END))
+                        return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
+                                               "Compression failed: code %u",
+                                               ret);
 
                 if (s.avail_out == 0 || ret == LZMA_STREAM_END) {
                         ssize_t n, k;
@@ -664,10 +664,10 @@ int compress_stream_lz4(int fdf, int fdt, uint64_t max_bytes) {
                 offset += n;
                 total_out += n;
 
-                if (max_bytes != (uint64_t) -1 && total_out > (size_t) max_bytes) {
-                        log_debug("Compressed stream longer than %"PRIu64" bytes", max_bytes);
-                        return -EFBIG;
-                }
+                if (max_bytes != (uint64_t) -1 && total_out > (size_t) max_bytes)
+                        return log_debug_errno(SYNTHETIC_ERRNO(EFBIG),
+                                               "Compressed stream longer than %" PRIu64 " bytes",
+                                               max_bytes);
 
                 if (size - offset < frame_size + 4) {
                         k = loop_write(fdt, buf, offset, false);
@@ -715,10 +715,10 @@ int decompress_stream_xz(int fdf, int fdt, uint64_t max_bytes) {
         assert(fdt >= 0);
 
         ret = lzma_stream_decoder(&s, UINT64_MAX, 0);
-        if (ret != LZMA_OK) {
-                log_debug("Failed to initialize XZ decoder: code %u", ret);
-                return -ENOMEM;
-        }
+        if (ret != LZMA_OK)
+                return log_debug_errno(SYNTHETIC_ERRNO(ENOMEM),
+                                       "Failed to initialize XZ decoder: code %u",
+                                       ret);
 
         for (;;) {
                 if (s.avail_in == 0 && action == LZMA_RUN) {
@@ -741,10 +741,10 @@ int decompress_stream_xz(int fdf, int fdt, uint64_t max_bytes) {
                 }
 
                 ret = lzma_code(&s, action);
-                if (!IN_SET(ret, LZMA_OK, LZMA_STREAM_END)) {
-                        log_debug("Decompression failed: code %u", ret);
-                        return -EBADMSG;
-                }
+                if (!IN_SET(ret, LZMA_OK, LZMA_STREAM_END))
+                        return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+                                               "Decompression failed: code %u",
+                                               ret);
 
                 if (s.avail_out == 0 || ret == LZMA_STREAM_END) {
                         ssize_t n, k;
@@ -772,8 +772,8 @@ int decompress_stream_xz(int fdf, int fdt, uint64_t max_bytes) {
                 }
         }
 #else
-        log_debug("Cannot decompress file. Compiled without XZ support.");
-        return -EPROTONOSUPPORT;
+        return log_debug_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT),
+                               "Cannot decompress file. Compiled without XZ support.");
 #endif
 }
 
@@ -833,8 +833,8 @@ int decompress_stream_lz4(int in, int out, uint64_t max_bytes) {
         munmap(src, st.st_size);
         return r;
 #else
-        log_debug("Cannot decompress file. Compiled without LZ4 support.");
-        return -EPROTONOSUPPORT;
+        return log_debug_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT),
+                               "Cannot decompress file. Compiled without LZ4 support.");
 #endif
 }
 
@@ -1043,8 +1043,8 @@ int decompress_stream_zstd(int fdf, int fdt, uint64_t max_bytes) {
                 (double) (max_bytes - left) / in_bytes * 100);
         return 0;
 #else
-        log_debug("Cannot decompress file. Compiled without ZSTD support.");
-        return -EPROTONOSUPPORT;
+        return log_debug_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT),
+                               "Cannot decompress file. Compiled without ZSTD support.");
 #endif
 }
 
index d51d03acd9de09ccecb815b6002b4224e55ed2d3..64882eb4ee4fc67fa8c2c1969223726bd7e1c6ab 100644 (file)
@@ -139,7 +139,7 @@ _printf_(1, 0) static int fill_iovec_sprintf(const char *format, va_list ap, int
 
                 if (i >= n) {
                         n = MAX(i*2, 4);
-                        c = realloc(iov, n * sizeof(struct iovec));
+                        c = reallocarray(iov, n, sizeof(struct iovec));
                         if (!c) {
                                 r = -ENOMEM;
                                 goto fail;
index 52e204ee1155fce11a4ec914511d278d1c5eec5d..e43e9d1afac95000f1d7f590bb0f4b2edf2c120b 100644 (file)
@@ -199,10 +199,9 @@ static int add_matches_for_device(sd_journal *j, const char *devpath) {
         assert(j);
         assert(devpath);
 
-        if (!path_startswith(devpath, "/dev/")) {
-                log_error("Devpath does not start with /dev/");
-                return -EINVAL;
-        }
+        if (!path_startswith(devpath, "/dev/"))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Devpath does not start with /dev/");
 
         if (stat(devpath, &st) < 0)
                 return log_error_errno(errno, "Couldn't stat file: %m");
@@ -1055,35 +1054,30 @@ static int parse_argv(int argc, char *argv[]) {
         if (arg_follow && !arg_no_tail && !arg_since && arg_lines == ARG_LINES_DEFAULT)
                 arg_lines = 10;
 
-        if (!!arg_directory + !!arg_file + !!arg_machine + !!arg_root + !!arg_image > 1) {
-                log_error("Please specify at most one of -D/--directory=, --file=, -M/--machine=, --root=, --image=.");
-                return -EINVAL;
-        }
+        if (!!arg_directory + !!arg_file + !!arg_machine + !!arg_root + !!arg_image > 1)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Please specify at most one of -D/--directory=, --file=, -M/--machine=, --root=, --image=.");
 
-        if (arg_since_set && arg_until_set && arg_since > arg_until) {
-                log_error("--since= must be before --until=.");
-                return -EINVAL;
-        }
+        if (arg_since_set && arg_until_set && arg_since > arg_until)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "--since= must be before --until=.");
 
-        if (!!arg_cursor + !!arg_after_cursor + !!arg_since_set > 1) {
-                log_error("Please specify only one of --since=, --cursor=, and --after-cursor.");
-                return -EINVAL;
-        }
+        if (!!arg_cursor + !!arg_after_cursor + !!arg_since_set > 1)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Please specify only one of --since=, --cursor=, and --after-cursor.");
 
-        if (arg_follow && arg_reverse) {
-                log_error("Please specify either --reverse= or --follow=, not both.");
-                return -EINVAL;
-        }
+        if (arg_follow && arg_reverse)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Please specify either --reverse= or --follow=, not both.");
 
-        if (!IN_SET(arg_action, ACTION_SHOW, ACTION_DUMP_CATALOG, ACTION_LIST_CATALOG) && optind < argc) {
-                log_error("Extraneous arguments starting with '%s'", argv[optind]);
-                return -EINVAL;
-        }
+        if (!IN_SET(arg_action, ACTION_SHOW, ACTION_DUMP_CATALOG, ACTION_LIST_CATALOG) && optind < argc)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Extraneous arguments starting with '%s'",
+                                       argv[optind]);
 
-        if ((arg_boot || arg_action == ACTION_LIST_BOOTS) && arg_merge) {
-                log_error("Using --boot or --list-boots with --merge is not supported.");
-                return -EINVAL;
-        }
+        if ((arg_boot || arg_action == ACTION_LIST_BOOTS) && arg_merge)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Using --boot or --list-boots with --merge is not supported.");
 
         if (!strv_isempty(arg_system_units) && arg_journal_type == SD_JOURNAL_CURRENT_USER) {
                 /* Specifying --user and --unit= at the same time makes no sense (as the former excludes the user
@@ -1921,7 +1915,8 @@ static int setup_keys(void) {
                         "Please write down the following %ssecret verification key%s. It should be stored\n"
                         "in a safe location and should not be saved locally on disk.\n"
                         "\n\t%s",
-                        hn ?: "", hn ? "/" : "", SD_ID128_FORMAT_VAL(machine),
+                        strempty(hn), hn ? "/" : "",
+                        SD_ID128_FORMAT_VAL(machine),
                         ansi_highlight(), ansi_normal(),
                         p,
                         format_timespan(tsb, sizeof(tsb), arg_interval, 0),
@@ -2476,7 +2471,7 @@ int main(int argc, char *argv[]) {
                                 after_cursor = true;
                         }
                 } else
-                        after_cursor = !!arg_after_cursor;
+                        after_cursor = arg_after_cursor;
 
                 if (cursor) {
                         r = sd_journal_seek_cursor(j, cursor);
index 50aab11c6a8b61182f4a3914477e7b7909aa79bb..924d727d97ce92b90bf5e2642b3d204f4658d451 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "alloc-util.h"
 #include "chattr-util.h"
+#include "io-util.h"
 #include "journal-file.h"
 #include "journal-internal.h"
 #include "log.h"
@@ -92,13 +93,11 @@ static void run_test(void) {
                 previous_ts = ts;
 
                 assert_se(asprintf(&p, "NUMBER=%u", i) >= 0);
-                iovec[0].iov_base = p;
-                iovec[0].iov_len = strlen(p);
+                iovec[0] = IOVEC_MAKE(p, strlen(p));
 
                 assert_se(asprintf(&q, "MAGIC=%s", i % 5 == 0 ? "quux" : "waldo") >= 0);
 
-                iovec[1].iov_base = q;
-                iovec[1].iov_len = strlen(q);
+                iovec[1] = IOVEC_MAKE(q, strlen(q));
 
                 if (i % 10 == 0)
                         assert_se(journal_file_append_entry(three, &ts, NULL, iovec, 2, NULL, NULL, NULL) == 0);
index 83e1b902916ad1e4ac87280ddf420bf8c47316f1..0aa6a63c0a99182977c430685a5d6385a6517e14 100644 (file)
@@ -1234,8 +1234,7 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
                         return -ENOMEM;
 
                 if (!strv_isempty(a)) {
-                        lease->search_domains = a;
-                        a = NULL;
+                        lease->search_domains = TAKE_PTR(a);
                 }
         }
 
index a45d98f669077d61fe9534ceafc8c9aff03d16a6..16a4f16bfa4a6b961824d40c81a6b289c2551698 100644 (file)
@@ -23,10 +23,10 @@ static void test_pool(struct in_addr *address, unsigned size, int ret) {
 static int test_basic(sd_event *event) {
         _cleanup_(sd_dhcp_server_unrefp) sd_dhcp_server *server = NULL;
         struct in_addr address_lo = {
-                .s_addr = htonl(INADDR_LOOPBACK),
+                .s_addr = htobe32(INADDR_LOOPBACK),
         };
         struct in_addr address_any = {
-                .s_addr = htonl(INADDR_ANY),
+                .s_addr = htobe32(INADDR_ANY),
         };
         int r;
 
@@ -105,7 +105,7 @@ static void test_message_handler(void) {
                 .end = SD_DHCP_OPTION_END,
         };
         struct in_addr address_lo = {
-                .s_addr = htonl(INADDR_LOOPBACK),
+                .s_addr = htobe32(INADDR_LOOPBACK),
         };
 
         assert_se(sd_dhcp_server_new(&server, 1) >= 0);
index f67d06ecec0d8475c643c671bfcfc5e21f4813d8..1497dc696f2f82a40b9809dad39aff48e5dbc644 100644 (file)
@@ -285,8 +285,7 @@ static void* client1(void *p) {
         assert_se(streq(hello, "hello"));
 
         if (pipe2(pp, O_CLOEXEC|O_NONBLOCK) < 0) {
-                log_error_errno(errno, "Failed to allocate pipe: %m");
-                r = -errno;
+                r = log_error_errno(errno, "Failed to allocate pipe: %m");
                 goto finish;
         }
 
index 54d293ca4619153ca9fd5434783597c1604e38bc..b623972365677fca509bf6c42a46fcc7d7f1530c 100644 (file)
@@ -548,10 +548,9 @@ static void test_pidfd(void) {
         assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD, -1) >= 0);
 
         pid = fork();
-        if (pid == 0) {
+        if (pid == 0)
                 /* child */
                 _exit(66);
-        }
 
         assert_se(pid > 1);
 
index b3febdbb313376c8bbb00c823466bc10450f598b..0e326f3d223842465788c8d5d6f1fdf96f78b01b 100644 (file)
@@ -343,10 +343,10 @@ _public_ int sd_hwdb_new(sd_hwdb **ret) {
                 return log_debug_errno(errno, "Failed to map %s: %m", hwdb_bin_path);
 
         if (memcmp(hwdb->map, sig, sizeof(hwdb->head->signature)) != 0 ||
-            (size_t) hwdb->st.st_size != le64toh(hwdb->head->file_size)) {
-                log_debug("Failed to recognize the format of %s", hwdb_bin_path);
-                return -EINVAL;
-        }
+            (size_t) hwdb->st.st_size != le64toh(hwdb->head->file_size))
+                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Failed to recognize the format of %s",
+                                       hwdb_bin_path);
 
         log_debug("=== trie on-disk ===");
         log_debug("tool version:          %"PRIu64, le64toh(hwdb->head->tool_version));
index f9d79bc0d6ea43a9b79f05bce52ae911fb3ddffd..be7a4f7835deca4df58c7d3068f3c066f33ea79f 100644 (file)
@@ -139,7 +139,7 @@ static void test_route(sd_netlink *rtnl) {
                 return;
         }
 
-        addr.s_addr = htonl(INADDR_LOOPBACK);
+        addr.s_addr = htobe32(INADDR_LOOPBACK);
 
         r = sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &addr);
         if (r < 0) {
index 8377c66ae359674adbed3697264af4727bc8ee1f..627b86b3cb00c2200f2b631038f9180f134b8fce 100644 (file)
@@ -63,7 +63,7 @@ int main(int argc, char *argv[]) {
 
         struct sockaddr_in sa = {
                 .sin_family = AF_INET,
-                .sin_port = htons(80)
+                .sin_port = htobe16(80)
         };
 
         assert_se(sd_resolve_default(&resolve) >= 0);
index 053bb601a235437bb7a6b3e5b8ee9fdf2f374f62..b7f400dc5e2c225f5cd30cf42e2f0b26d1126d79 100644 (file)
@@ -545,8 +545,7 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
                 printf("\t    Unit: %s\n", i.scope);
                 show_unit_cgroup(bus, "org.freedesktop.systemd1.Scope", i.scope, i.leader);
 
-                if (arg_transport == BUS_TRANSPORT_LOCAL) {
-
+                if (arg_transport == BUS_TRANSPORT_LOCAL)
                         show_journal_by_unit(
                                         stdout,
                                         i.scope,
@@ -560,7 +559,6 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
                                         SD_JOURNAL_LOCAL_ONLY,
                                         true,
                                         NULL);
-                }
         }
 
         return 0;
index a685b8e5b88c82149da311403b19a498416c72d6..370604f936d80cdaa7a208e2dac58525617355b4 100644 (file)
@@ -21,6 +21,7 @@
 #include "parse-util.h"
 #include "path-util.h"
 #include "process-util.h"
+#include "stdio-util.h"
 #include "strv.h"
 #include "terminal-util.h"
 #include "udev-util.h"
@@ -533,7 +534,7 @@ int manager_spawn_autovt(Manager *m, unsigned vtnr) {
                         return -EBUSY;
         }
 
-        snprintf(name, sizeof(name), "autovt@tty%u.service", vtnr);
+        xsprintf(name, "autovt@tty%u.service", vtnr);
         r = sd_bus_call_method(
                         m->bus,
                         "org.freedesktop.systemd1",
index 41070dcda58b5b90d7ddd91ab502fd2e97931085..4869797b1e22c71a69c457cc6f316f66bd05f112 100644 (file)
@@ -1312,15 +1312,13 @@ static int login_machine(int argc, char *argv[], void *userdata) {
 
         assert(bus);
 
-        if (!strv_isempty(arg_setenv) || arg_uid) {
-                log_error("--setenv= and --uid= are not supported for 'login'. Use 'shell' instead.");
-                return -EINVAL;
-        }
+        if (!strv_isempty(arg_setenv) || arg_uid)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "--setenv= and --uid= are not supported for 'login'. Use 'shell' instead.");
 
-        if (!IN_SET(arg_transport, BUS_TRANSPORT_LOCAL, BUS_TRANSPORT_MACHINE)) {
-                log_error("Login only supported on local machines.");
-                return -EOPNOTSUPP;
-        }
+        if (!IN_SET(arg_transport, BUS_TRANSPORT_LOCAL, BUS_TRANSPORT_MACHINE))
+                return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+                                       "Login only supported on local machines.");
 
         polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
 
@@ -1369,10 +1367,9 @@ static int shell_machine(int argc, char *argv[], void *userdata) {
 
         assert(bus);
 
-        if (!IN_SET(arg_transport, BUS_TRANSPORT_LOCAL, BUS_TRANSPORT_MACHINE)) {
-                log_error("Shell only supported on local machines.");
-                return -EOPNOTSUPP;
-        }
+        if (!IN_SET(arg_transport, BUS_TRANSPORT_LOCAL, BUS_TRANSPORT_MACHINE))
+                return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+                                       "Shell only supported on local machines.");
 
         /* Pass $TERM to shell session, if not explicitly specified. */
         if (!strv_find_prefix(arg_setenv, "TERM=")) {
@@ -1525,10 +1522,10 @@ static int read_only_image(int argc, char *argv[], void *userdata) {
 
         if (argc > 2) {
                 b = parse_boolean(argv[2]);
-                if (b < 0) {
-                        log_error("Failed to parse boolean argument: %s", argv[2]);
-                        return -EINVAL;
-                }
+                if (b < 0)
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Failed to parse boolean argument: %s",
+                                               argv[2]);
         }
 
         polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
@@ -1602,10 +1599,10 @@ static int start_machine(int argc, char *argv[], void *userdata) {
                 r = image_exists(bus, argv[i]);
                 if (r < 0)
                         return r;
-                if (r == 0) {
-                        log_error("Machine image '%s' does not exist.", argv[i]);
-                        return -ENXIO;
-                }
+                if (r == 0)
+                        return log_error_errno(SYNTHETIC_ERRNO(ENXIO),
+                                               "Machine image '%s' does not exist.",
+                                               argv[i]);
 
                 r = sd_bus_call_method(
                                 bus,
@@ -1674,10 +1671,10 @@ static int enable_machine(int argc, char *argv[], void *userdata) {
                 r = image_exists(bus, argv[i]);
                 if (r < 0)
                         return r;
-                if (r == 0) {
-                        log_error("Machine image '%s' does not exist.", argv[i]);
-                        return -ENXIO;
-                }
+                if (r == 0)
+                        return log_error_errno(SYNTHETIC_ERRNO(ENXIO),
+                                               "Machine image '%s' does not exist.",
+                                               argv[i]);
 
                 r = sd_bus_message_append(m, "s", unit);
                 if (r < 0)
@@ -1874,10 +1871,9 @@ static int import_tar(int argc, char *argv[], void *userdata) {
 
                 local = fn;
         }
-        if (!local) {
-                log_error("Need either path or local name.");
-                return -EINVAL;
-        }
+        if (!local)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Need either path or local name.");
 
         r = tar_strip_suffixes(local, &ll);
         if (r < 0)
@@ -1885,10 +1881,10 @@ static int import_tar(int argc, char *argv[], void *userdata) {
 
         local = ll;
 
-        if (!machine_name_is_valid(local)) {
-                log_error("Local name %s is not a suitable machine name.", local);
-                return -EINVAL;
-        }
+        if (!machine_name_is_valid(local))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Local name %s is not a suitable machine name.",
+                                       local);
 
         if (path) {
                 fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY);
@@ -1935,10 +1931,9 @@ static int import_raw(int argc, char *argv[], void *userdata) {
 
                 local = fn;
         }
-        if (!local) {
-                log_error("Need either path or local name.");
-                return -EINVAL;
-        }
+        if (!local)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Need either path or local name.");
 
         r = raw_strip_suffixes(local, &ll);
         if (r < 0)
@@ -1946,10 +1941,10 @@ static int import_raw(int argc, char *argv[], void *userdata) {
 
         local = ll;
 
-        if (!machine_name_is_valid(local)) {
-                log_error("Local name %s is not a suitable machine name.", local);
-                return -EINVAL;
-        }
+        if (!machine_name_is_valid(local))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Local name %s is not a suitable machine name.",
+                                       local);
 
         if (path) {
                 fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY);
@@ -1996,15 +1991,14 @@ static int import_fs(int argc, char *argv[], void *userdata) {
 
                 local = fn;
         }
-        if (!local) {
-                log_error("Need either path or local name.");
-                return -EINVAL;
-        }
+        if (!local)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Need either path or local name.");
 
-        if (!machine_name_is_valid(local)) {
-                log_error("Local name %s is not a suitable machine name.", local);
-                return -EINVAL;
-        }
+        if (!machine_name_is_valid(local))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Local name %s is not a suitable machine name.",
+                                       local);
 
         if (path) {
                 fd = open(path, O_DIRECTORY|O_RDONLY|O_CLOEXEC);
@@ -2054,10 +2048,9 @@ static int export_tar(int argc, char *argv[], void *userdata) {
         assert(bus);
 
         local = argv[1];
-        if (!machine_name_is_valid(local)) {
-                log_error("Machine name %s is not valid.", local);
-                return -EINVAL;
-        }
+        if (!machine_name_is_valid(local))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Machine name %s is not valid.", local);
 
         if (argc >= 3)
                 path = argv[2];
@@ -2097,10 +2090,9 @@ static int export_raw(int argc, char *argv[], void *userdata) {
         assert(bus);
 
         local = argv[1];
-        if (!machine_name_is_valid(local)) {
-                log_error("Machine name %s is not valid.", local);
-                return -EINVAL;
-        }
+        if (!machine_name_is_valid(local))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Machine name %s is not valid.", local);
 
         if (argc >= 3)
                 path = argv[2];
@@ -2140,10 +2132,9 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
         assert(bus);
 
         remote = argv[1];
-        if (!http_url_is_valid(remote)) {
-                log_error("URL '%s' is not valid.", remote);
-                return -EINVAL;
-        }
+        if (!http_url_is_valid(remote))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "URL '%s' is not valid.", remote);
 
         if (argc >= 3)
                 local = argv[2];
@@ -2164,10 +2155,10 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
 
                 local = ll;
 
-                if (!machine_name_is_valid(local)) {
-                        log_error("Local name %s is not a suitable machine name.", local);
-                        return -EINVAL;
-                }
+                if (!machine_name_is_valid(local))
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Local name %s is not a suitable machine name.",
+                                               local);
         }
 
         r = bus_message_new_method_call(bus, &m, bus_import_mgr, "PullTar");
@@ -2197,10 +2188,9 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
         assert(bus);
 
         remote = argv[1];
-        if (!http_url_is_valid(remote)) {
-                log_error("URL '%s' is not valid.", remote);
-                return -EINVAL;
-        }
+        if (!http_url_is_valid(remote))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "URL '%s' is not valid.", remote);
 
         if (argc >= 3)
                 local = argv[2];
@@ -2221,10 +2211,10 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
 
                 local = ll;
 
-                if (!machine_name_is_valid(local)) {
-                        log_error("Local name %s is not a suitable machine name.", local);
-                        return -EINVAL;
-                }
+                if (!machine_name_is_valid(local))
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Local name %s is not a suitable machine name.",
+                                               local);
         }
 
         r = bus_message_new_method_call(bus, &m, bus_import_mgr, "PullRaw");
index 22da189684fb3e45d716f04baa326330129623ae..9e570339992fe834496eb45a114026e9c23b7cf1 100644 (file)
@@ -923,10 +923,9 @@ static int umount_by_device(sd_bus *bus, const char *what) {
         if (stat(what, &st) < 0)
                 return log_error_errno(errno, "Can't stat %s: %m", what);
 
-        if (!S_ISBLK(st.st_mode)) {
-                log_error("Not a block device: %s", what);
-                return -ENOTBLK;
-        }
+        if (!S_ISBLK(st.st_mode))
+                return log_error_errno(SYNTHETIC_ERRNO(ENOTBLK),
+                                       "Not a block device: %s", what);
 
         r = sd_device_new_from_devnum(&d, 'b', st.st_rdev);
         if (r < 0)
@@ -1249,10 +1248,10 @@ static int discover_loop_backing_file(void) {
                 escaped = xescape(basename(arg_mount_what), "\\");
                 if (!escaped)
                         return log_oom();
-                if (!filename_is_valid(escaped)) {
-                        log_error("Escaped name %s is not a valid filename.", escaped);
-                        return -EINVAL;
-                }
+                if (!filename_is_valid(escaped))
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Escaped name %s is not a valid filename.",
+                                               escaped);
 
                 arg_mount_where = path_join("/run/media/system", escaped);
                 if (!arg_mount_where)
@@ -1265,10 +1264,9 @@ static int discover_loop_backing_file(void) {
         if (stat(loop_dev, &st) < 0)
                 return log_error_errno(errno, "Can't stat %s: %m", loop_dev);
 
-        if (!S_ISBLK(st.st_mode)) {
-                log_error("Invalid file type: %s", loop_dev);
-                return -EINVAL;
-        }
+        if (!S_ISBLK(st.st_mode))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Invalid file type: %s", loop_dev);
 
         r = sd_device_new_from_devnum(&d, 'b', st.st_rdev);
         if (r < 0)
@@ -1309,19 +1307,19 @@ static int discover_device(void) {
         if (S_ISREG(st.st_mode))
                 return discover_loop_backing_file();
 
-        if (!S_ISBLK(st.st_mode)) {
-                log_error("Invalid file type: %s", arg_mount_what);
-                return -EINVAL;
-        }
+        if (!S_ISBLK(st.st_mode))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Invalid file type: %s",
+                                       arg_mount_what);
 
         r = sd_device_new_from_devnum(&d, 'b', st.st_rdev);
         if (r < 0)
                 return log_error_errno(r, "Failed to get device from device number: %m");
 
-        if (sd_device_get_property_value(d, "ID_FS_USAGE", &v) < 0 || !streq(v, "filesystem")) {
-                log_error("%s does not contain a known file system.", arg_mount_what);
-                return -EINVAL;
-        }
+        if (sd_device_get_property_value(d, "ID_FS_USAGE", &v) < 0 || !streq(v, "filesystem"))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "%s does not contain a known file system.",
+                                       arg_mount_what);
 
         r = acquire_mount_type(d);
         if (r < 0)
@@ -1462,10 +1460,10 @@ static int run(int argc, char* argv[]) {
                 return action_umount(bus, argc, argv);
 
         if ((!arg_mount_type || fstype_is_blockdev_backed(arg_mount_type))
-            && !path_is_normalized(arg_mount_what)) {
-                log_error("Path contains non-normalized components: %s", arg_mount_what);
-                return -EINVAL;
-        }
+            && !path_is_normalized(arg_mount_what))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Path contains non-normalized components: %s",
+                                       arg_mount_what);
 
         if (arg_discover) {
                 r = discover_device();
@@ -1473,20 +1471,19 @@ static int run(int argc, char* argv[]) {
                         return r;
         }
 
-        if (!arg_mount_where) {
-                log_error("Can't figure out where to mount %s.", arg_mount_what);
-                return -EINVAL;
-        }
+        if (!arg_mount_where)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Can't figure out where to mount %s.",
+                                       arg_mount_what);
 
-        if (path_equal(arg_mount_where, "/")) {
-                log_error("Refusing to operate on root directory.");
-                return -EINVAL;
-        }
+        if (path_equal(arg_mount_where, "/"))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Refusing to operate on root directory.");
 
-        if (!path_is_normalized(arg_mount_where)) {
-                log_error("Path contains non-normalized components: %s", arg_mount_where);
-                return -EINVAL;
-        }
+        if (!path_is_normalized(arg_mount_where))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Path contains non-normalized components: %s",
+                                       arg_mount_where);
 
         if (streq_ptr(arg_mount_type, "auto"))
                 arg_mount_type = mfree(arg_mount_type);
@@ -1516,11 +1513,10 @@ static int run(int argc, char* argv[]) {
         if (arg_mount_type &&
             !streq(arg_mount_type, "auto") &&
             arg_uid != UID_INVALID &&
-            !fstype_can_uid_gid(arg_mount_type)) {
-                log_error("File system type %s is not known to support uid=/gid=, refusing.",
-                          arg_mount_type);
-                return -EOPNOTSUPP;
-        }
+            !fstype_can_uid_gid(arg_mount_type))
+                return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+                                       "File system type %s is not known to support uid=/gid=, refusing.",
+                                       arg_mount_type);
 
         switch (arg_action) {
 
index d3053d0354a7a5d8fcb64d230c2d3fffeff9f951..46d27f8f544c13dea8b612b28b3d59f43c745959 100644 (file)
@@ -762,10 +762,9 @@ int config_parse_dhcp_send_option(
         }
         case DHCP_OPTION_DATA_STRING:
                 sz = cunescape(p, UNESCAPE_ACCEPT_NUL, &q);
-                if (sz < 0) {
+                if (sz < 0)
                         log_syntax(unit, LOG_WARNING, filename, line, sz,
                                    "Failed to decode DHCP option data, ignoring assignment: %s", p);
-                }
 
                 udata = q;
                 break;
index 5629ecd01a4721b833a4f209e60b1c6aaf85d35f..7c9e01aba7bfa60c9b222bad1eb495aa47e370a6 100644 (file)
@@ -123,11 +123,10 @@ int config_parse_generic_random_early_detection_u32(
                 return 0;
         }
 
-        if (v > MAX_DPs) {
+        if (v > MAX_DPs)
                 log_syntax(unit, LOG_WARNING, filename, line, 0,
                            "Invalid '%s=', ignoring assignment: %s",
                            lvalue, rvalue);
-        }
 
         *p = v;
         qdisc = NULL;
index bc64860a353af8982138d173fd9e17505c838b81..f727d1434174e6b4f6e810460452fd3e40d29e57 100644 (file)
@@ -79,11 +79,10 @@ int config_parse_trivial_link_equalizer_id(
                            lvalue, rvalue);
                 return 0;
         }
-        if (id > INT_MAX) {
+        if (id > INT_MAX)
                 log_syntax(unit, LOG_WARNING, filename, line, 0,
                            "'%s=' is too large, ignoring assignment: %s",
                            lvalue, rvalue);
-        }
 
         teql->id = id;
 
index 60a59096fbc4fb819fdf495a348d0373447abf95..9445dc5b0e6e7351540f7d66de9c7e5bea8e8641 100644 (file)
@@ -660,10 +660,9 @@ static int oci_namespaces(const char *name, JsonVariant *v, JsonDispatchFlags fl
                         s->network_namespace_path = data.path;
                 }
 
-                if (FLAGS_SET(n, data.type)) {
+                if (FLAGS_SET(n, data.type))
                         return json_log(e, flags, SYNTHETIC_ERRNO(EINVAL),
                                         "Duplicate namespace specification, refusing.");
-                }
 
                 n |= data.type;
         }
@@ -2216,14 +2215,14 @@ int oci_load(FILE *f, const char *bundle, Settings **ret) {
         }
 
         v = json_variant_by_key(oci, "ociVersion");
-        if (!v) {
-                log_error("JSON file '%s' is not an OCI bundle configuration file. Refusing.", path);
-                return -EINVAL;
-        }
-        if (!streq_ptr(json_variant_string(v), "1.0.0")) {
-                log_error("OCI bundle version not supported: %s", strna(json_variant_string(v)));
-                return -EINVAL;
-        }
+        if (!v)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "JSON file '%s' is not an OCI bundle configuration file. Refusing.",
+                                       path);
+        if (!streq_ptr(json_variant_string(v), "1.0.0"))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "OCI bundle version not supported: %s",
+                                       strna(json_variant_string(v)));
 
         // {
         //         _cleanup_free_ char *formatted = NULL;
index 12a04b0baeda12cc83d8e0188f727d8bd00cc25b..82bb1673975ed0dde2724155355b07430cf4e511 100644 (file)
@@ -4342,7 +4342,7 @@ static int load_settings(void) {
 
         /* If all settings are masked, there's no point in looking for
          * the settings file */
-        if ((arg_settings_mask & _SETTINGS_MASK_ALL) == _SETTINGS_MASK_ALL)
+        if (FLAGS_SET(arg_settings_mask, _SETTINGS_MASK_ALL))
                 return 0;
 
         fn = strjoina(arg_machine, ".nspawn");
index 0e8c13f7ea2cd515fed39325e6a2008c2d451d54..06ac335b291a9deb9be1bf46e244fb8d3a63cfe2 100644 (file)
@@ -595,7 +595,7 @@ enum nss_status _nss_systemd_initgroups_dyn(
                                 new_size = limit;
 
                         /* Enlarge buffer */
-                        new_groups = realloc(*groupsp, new_size * sizeof(**groupsp));
+                        new_groups = reallocarray(*groupsp, new_size, sizeof(**groupsp));
                         if (!new_groups) {
                                 UNPROTECT_ERRNO;
                                 *errnop = ENOMEM;
index d74331df3ea771f35c4676acb6aec0ced8f35b22..55ea6759e912d08ffbc47c7e996fb1bbe7cdcc28 100644 (file)
@@ -434,10 +434,9 @@ static int portable_extract_by_path(
                         if (isempty(name) && fd < 0)
                                 break;
 
-                        if (isempty(name) || fd < 0) {
-                                log_debug("Invalid item sent from child.");
-                                return -EINVAL;
-                        }
+                        if (isempty(name) || fd < 0)
+                                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                       "Invalid item sent from child.");
 
                         add = portable_metadata_new(name, fd);
                         if (!add)
index 4581c2e3c8710fffdd453fb72326c63247cb7268..f3aabcc50e9baf6c357c739e7aab8eff89508a90 100644 (file)
@@ -261,10 +261,9 @@ static int resolve_host(sd_bus *bus, const char *name) {
                        (int) strlen(name), c == 0 ? name : "", c == 0 ? ":" : " ",
                        canonical);
 
-        if (c == 0) {
-                log_error("%s: no addresses found", name);
-                return -ESRCH;
-        }
+        if (c == 0)
+                return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
+                                       "%s: no addresses found", name);
 
         print_source(flags, ts);
 
@@ -356,10 +355,9 @@ static int resolve_address(sd_bus *bus, int family, const union in_addr_union *a
         if (r < 0)
                 return bus_log_parse_error(r);
 
-        if (c == 0) {
-                log_error("%s: no names found", pretty);
-                return -ESRCH;
-        }
+        if (c == 0)
+                return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
+                                       "%s: no names found", pretty);
 
         print_source(flags, ts);
 
@@ -2050,10 +2048,10 @@ static int call_domain(sd_bus *bus, char **domain, const BusLocator *locator, sd
                         r = dns_name_is_valid(n);
                         if (r < 0)
                                 return log_error_errno(r, "Failed to validate specified domain %s: %m", n);
-                        if (r == 0) {
-                                log_error("Domain not valid: %s", n);
-                                return -EINVAL;
-                        }
+                        if (r == 0)
+                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                       "Domain not valid: %s",
+                                                       n);
 
                         r = sd_bus_message_append(req, "(sb)", n, **p == '~');
                         if (r < 0)
@@ -2348,10 +2346,10 @@ static int verb_nta(int argc, char **argv, void *userdata) {
                         r = dns_name_is_valid(*p);
                         if (r < 0)
                                 return log_error_errno(r, "Failed to validate specified domain %s: %m", *p);
-                        if (r == 0) {
-                                log_error("Domain not valid: %s", *p);
-                                return -EINVAL;
-                        }
+                        if (r == 0)
+                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                       "Domain not valid: %s",
+                                                       *p);
                 }
 
         r = call_nta(bus, clear ? NULL : argv + 2, bus_resolve_mgr, &error);
index 75c8bf315ebce44db3687a5eb4be87afda4e8bb6..664e92c363e90cafa79c89237b0d750d7a44593e 100644 (file)
@@ -1426,7 +1426,7 @@ int dns_packet_read_name(
 
                         n += r;
                         continue;
-                } else if (allow_compression && (c & 0xc0) == 0xc0) {
+                } else if (allow_compression && FLAGS_SET(c, 0xc0)) {
                         uint16_t ptr;
 
                         /* Pointer */
@@ -2241,12 +2241,11 @@ static int dns_packet_extract_answer(DnsPacket *p, DnsAnswer **ret_answer) {
                         if (DNS_PACKET_QR(p)) {
                                 /* Additional checks for responses */
 
-                                if (!DNS_RESOURCE_RECORD_OPT_VERSION_SUPPORTED(rr)) {
+                                if (!DNS_RESOURCE_RECORD_OPT_VERSION_SUPPORTED(rr))
                                         /* If this is a reply and we don't know the EDNS version
                                          * then something is weird... */
-                                        log_debug("EDNS version newer that our request, bad server.");
-                                        return -EBADMSG;
-                                }
+                                        return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
+                                                               "EDNS version newer that our request, bad server.");
 
                                 if (has_rfc6975) {
                                         /* If the OPT RR contains RFC6975 algorithm data, then this
index 8ffe45e744fcb0dce53b46ae6ff935a7a39545ff..d7f3a5adef2ee6eed245b5e9604cb12f81169a19 100644 (file)
@@ -97,15 +97,15 @@ static int dnssd_service_load(Manager *manager, const char *filename) {
         if (r < 0)
                 return r;
 
-        if (!service->name_template) {
-                log_error("%s doesn't define service instance name", service->name);
-                return -EINVAL;
-        }
-
-        if (!service->type) {
-                log_error("%s doesn't define service type", service->name);
-                return -EINVAL;
-        }
+        if (!service->name_template)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "%s doesn't define service instance name",
+                                       service->name);
+
+        if (!service->type)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "%s doesn't define service type",
+                                       service->name);
 
         if (LIST_IS_EMPTY(service->txt_data_items)) {
                 txt_data = new0(DnssdTxtData, 1);
index 7523c65e9641a3cc67a820698162d47e0aa11174..319fb50803007eaa230d891bbbc62212ffbdbc6a 100644 (file)
@@ -780,10 +780,8 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) {
         l = recvmsg_safe(fd, &mh, 0);
         if (IN_SET(l, -EAGAIN, -EINTR))
                 return 0;
-        if (l < 0)
+        if (l <= 0)
                 return l;
-        if (l == 0)
-                return 0;
 
         assert(!(mh.msg_flags & MSG_TRUNC));
 
index 214b2695695e6fe5cbb009e42636ea0853f2facd..9ea3de4b17660a14e67c512c2dca0a56fb90d77c 100644 (file)
@@ -1336,7 +1336,7 @@ static int start_transient_service(
                         if (c.cpu_usage_nsec != NSEC_INFINITY) {
                                 char ts[FORMAT_TIMESPAN_MAX];
                                 log_info("CPU time consumed: %s",
-                                         format_timespan(ts, sizeof ts, (c.cpu_usage_nsec + NSEC_PER_USEC - 1) / NSEC_PER_USEC, USEC_PER_MSEC));
+                                         format_timespan(ts, sizeof ts, DIV_ROUND_UP(c.cpu_usage_nsec, NSEC_PER_USEC), USEC_PER_MSEC));
                         }
 
                         if (c.ip_ingress_bytes != UINT64_MAX) {
index 9a306daa032ba6574ee3718389316c339672da6c..aa5dadba45573f780113b0705eabf027ac553d9f 100644 (file)
@@ -266,12 +266,10 @@ int bus_connect_transport(BusTransport transport, const char *host, bool user, s
                 if (user)
                         r = sd_bus_default_user(&bus);
                 else {
-                        if (sd_booted() <= 0) {
+                        if (sd_booted() <= 0)
                                 /* Print a friendly message when the local system is actually not running systemd as PID 1. */
-                                log_error("System has not been booted with systemd as init system (PID 1). Can't operate.");
-
-                                return -EHOSTDOWN;
-                        }
+                                return log_error_errno(SYNTHETIC_ERRNO(EHOSTDOWN),
+                                                       "System has not been booted with systemd as init system (PID 1). Can't operate.");
                         r = sd_bus_default_system(&bus);
                 }
                 break;
index eaf44f156c67e5acb0256f30505b7d8a81870bbc..91120d72194f490dcc6c51542937e8e0d9d643ef 100644 (file)
@@ -224,7 +224,7 @@ static int wait_for_partitions_to_appear(
                         if (r < 0)
                                 return r;
                         if (r == 0)
-                                return log_debug_errno(EPROTONOSUPPORT,
+                                return log_debug_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT),
                                                        "Device is a loop device and partition scanning is off!");
 
                         return -EINVAL; /* original error */
index 4088439f93ff918f3d33d5e52118dab4d37038c0..400cebb66fc953c51e7f037996d6d28ab5f9c05e 100644 (file)
@@ -791,8 +791,8 @@ static int slot_process(
 
         rv = m->C_GetTokenInfo(slotid, &token_info);
         if (rv == CKR_TOKEN_NOT_PRESENT) {
-                log_debug("Token not present in slot, ignoring.");
-                return -EAGAIN;
+                return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
+                                       "Token not present in slot, ignoring.");
         } else if (rv != CKR_OK) {
                 log_warning("Failed to acquire token info for slot %lu, ignoring slot: %s", slotid, p11_kit_strerror(rv));
                 return -EAGAIN;
@@ -808,10 +808,10 @@ static int slot_process(
                 return -EAGAIN;
         }
 
-        if (search_uri && !p11_kit_uri_match_token_info(search_uri, &token_info)) {
-                log_debug("Found non-matching token with URI %s.", token_uri_string);
-                return -EAGAIN;
-        }
+        if (search_uri && !p11_kit_uri_match_token_info(search_uri, &token_info))
+                return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
+                                       "Found non-matching token with URI %s.",
+                                       token_uri_string);
 
         log_debug("Found matching token with URI %s.", token_uri_string);
 
@@ -876,10 +876,9 @@ static int module_process(
                 log_warning("Failed to get slot list, ignoring module: %s", p11_kit_strerror(rv));
                 return -EAGAIN;
         }
-        if (n_slotids == 0) {
-                log_debug("This module has no slots? Ignoring module.");
-                return -EAGAIN;
-        }
+        if (n_slotids == 0)
+                return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
+                                       "This module has no slots? Ignoring module.");
 
         for (k = 0; k < n_slotids; k++) {
                 r = slot_process(
index 9e3555d986782dbbc955304d3e67008c7e379979..75ff2bb7bf4542791acb8a6f44dcc1b350d17b4b 100644 (file)
@@ -1190,7 +1190,7 @@ int seccomp_restrict_namespaces(unsigned long retain) {
         }
 
         /* NOOP? */
-        if ((retain & NAMESPACE_FLAGS_ALL) == NAMESPACE_FLAGS_ALL)
+        if (FLAGS_SET(retain, NAMESPACE_FLAGS_ALL))
                 return 0;
 
         SECCOMP_FOREACH_LOCAL_ARCH(arch) {
@@ -1228,7 +1228,7 @@ int seccomp_restrict_namespaces(unsigned long retain) {
                         unsigned long f;
 
                         f = namespace_flag_map[i].flag;
-                        if ((retain & f) == f) {
+                        if (FLAGS_SET(retain, f)) {
                                 log_debug("Permitting %s.", namespace_flag_map[i].name);
                                 continue;
                         }
index cf28ea7d1c207340a5dc05a327be4da3bbe0624f..20486c968ea1ed40b3000fcba49df32600ffe23f 100644 (file)
@@ -187,11 +187,10 @@ int logind_check_inhibitors(enum action a) {
         if (c <= 0)
                 return 0;
 
-        log_error("Please retry operation after closing inhibitors and logging out other users.\n"
-                  "Alternatively, ignore inhibitors and users with 'systemctl %s -i'.",
-                  action_table[a].verb);
-
-        return -EPERM;
+        return log_error_errno(SYNTHETIC_ERRNO(EPERM),
+                               "Please retry operation after closing inhibitors and logging out other users.\n"
+                               "Alternatively, ignore inhibitors and users with 'systemctl %s -i'.",
+                               action_table[a].verb);
 #else
         return 0;
 #endif
index 3ca8e1b10832f68d7d60c8b3430c15a6193d0331..2cc679f42e1abfd5a0cfc36c840ccdddddc1f846 100644 (file)
@@ -106,7 +106,7 @@ static void test_device_parents(struct udev *udev, const char *syspath) {
 
         log_info("/* %s, device %s */", __func__, syspath);
         device = udev_device_new_from_syspath(udev, syspath);
-        if (device == NULL)
+        if (!device)
                 return;
 
         log_info("looking at parents");
@@ -142,7 +142,7 @@ static void test_device_subsys_name(struct udev *udev, const char *subsys, const
 
         log_info("looking up device: '%s:%s'", subsys, dev);
         device = udev_device_new_from_subsystem_sysname(udev, subsys, dev);
-        if (device == NULL)
+        if (!device)
                 log_warning_errno(errno, "udev_device_new_from_subsystem_sysname: %m");
         else
                 print_device(device);
@@ -213,7 +213,7 @@ static void test_monitor(struct udev *udev) {
                 for (i = 0; i < fdcount; i++) {
                         if (ev[i].data.fd == fd_udev && ev[i].events & EPOLLIN) {
                                 device = udev_monitor_receive_device(udev_monitor);
-                                if (device == NULL) {
+                                if (!device) {
                                         printf("no device from socket\n");
                                         continue;
                                 }
index b9b37008b128a5a56b966555c04afe3741a1d388..c3c1c6d49af69ad976788f9e999e86f885160fcd 100644 (file)
@@ -1417,10 +1417,10 @@ static int create_file(Item *i, const char *path) {
                 if (fstat(fd, &stbuf) < 0)
                         return log_error_errno(errno, "stat(%s) failed: %m", path);
 
-                if (!S_ISREG(stbuf.st_mode)) {
-                        log_error("%s exists and is not a regular file.", path);
-                        return -EEXIST;
-                }
+                if (!S_ISREG(stbuf.st_mode))
+                        return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
+                                               "%s exists and is not a regular file.",
+                                               path);
 
                 st = &stbuf;
         } else {
@@ -1481,10 +1481,10 @@ static int truncate_file(Item *i, const char *path) {
 
                 fd = openat(dir_fd, bn, O_NOFOLLOW|O_CLOEXEC|O_PATH, i->mode);
                 if (fd < 0) {
-                        if (errno == ENOENT) {
-                                log_error("Cannot create file %s on a read-only file system.", path);
-                                return -EROFS;
-                        }
+                        if (errno == ENOENT)
+                                return log_error_errno(SYNTHETIC_ERRNO(EROFS),
+                                                       "Cannot create file %s on a read-only file system.",
+                                                       path);
 
                         return log_error_errno(errno, "Failed to re-open file %s: %m", path);
                 }
@@ -1495,10 +1495,10 @@ static int truncate_file(Item *i, const char *path) {
         if (fstat(fd, &stbuf) < 0)
                 return log_error_errno(errno, "stat(%s) failed: %m", path);
 
-        if (!S_ISREG(stbuf.st_mode)) {
-                log_error("%s exists and is not a regular file.", path);
-                return -EEXIST;
-        }
+        if (!S_ISREG(stbuf.st_mode))
+                return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
+                                       "%s exists and is not a regular file.",
+                                       path);
 
         if (stbuf.st_size > 0) {
                 if (ftruncate(fd, 0) < 0) {