]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #12121 from poettering/contrib v242-rc1
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 3 Apr 2019 07:48:10 +0000 (09:48 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 3 Apr 2019 07:53:51 +0000 (09:53 +0200)
19 files changed:
NEWS
docs/PORTABLE_SERVICES.md
meson.build
src/analyze/analyze-security.c
src/basic/fs-util.c
src/boot/bootctl.c
src/boot/efi/boot.c
src/boot/efi/util.c
src/cgtop/cgtop.c
src/core/load-fragment-gperf.gperf.m4
src/core/meson.build
src/libsystemd/sd-device/sd-device.c
src/libsystemd/sd-event/sd-event.c
src/libsystemd/sd-login/sd-login.c
src/nspawn/nspawn.c
src/resolve/resolvectl.c
src/shared/bus-util.c
src/shared/json.c
src/udev/udev-rules.c

diff --git a/NEWS b/NEWS
index 568a31a87d7d07c72f4829d1bdee83ea81698e67..a2fdec08c679859d15c3fe3eb3714421f382768a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,6 @@
 systemd System and Service Manager
 
-CHANGES WITH 242 in spe:
+CHANGES WITH 242:
 
         * In .link files, MACAddressPolicy=persistent (the default) is changed
           to cover more devices. For devices like bridges, tun, tap, bond, and
@@ -253,7 +253,7 @@ CHANGES WITH 242 in spe:
         Jungel, Tom Yan, Tony Asleson, Topi Miettinen, unixsysadmin, Van Laser,
         Vesa Jääskeläinen, Yu, Li-Yu, Yu Watanabe, Zbigniew Jędrzejewski-Szmek
 
-        — Somewhere, 2019-0X-YZ
+        — Warsaw, 2019-04-03
 
 CHANGES WITH 241:
 
index 631d063b01911dc744ffff066bb3dc695498abf7..194ef5bcdbbaad16f73665640e689ed4ca82a70e 100644 (file)
@@ -195,17 +195,17 @@ wonder what the most minimal image would be that complies with the requirements
 above, it could consist of this:
 
 ```
-/usr/bin/minimald                        # a statically compiled binary
-/usr/lib/systemd/minimal-test.service    # the unit file for the service, with ExecStart=/usr/bin/minimald
-/usr/lib/os-release                      # an os-release file explaining what this is
-/etc/resolv.conf                         # empty file to mount over with host's version
-/etc/machine-id                          # ditto
-/proc/                                   # empty directory to use as mount point for host's API fs
-/sys/                                    # ditto
-/dev/                                    # ditto
-/run/                                    # ditto
-/tmp/                                    # ditto
-/var/tmp/                                # ditto
+/usr/bin/minimald                            # a statically compiled binary
+/usr/lib/systemd/system/minimal-test.service # the unit file for the service, with ExecStart=/usr/bin/minimald
+/usr/lib/os-release                          # an os-release file explaining what this is
+/etc/resolv.conf                             # empty file to mount over with host's version
+/etc/machine-id                              # ditto
+/proc/                                       # empty directory to use as mount point for host's API fs
+/sys/                                        # ditto
+/dev/                                        # ditto
+/run/                                        # ditto
+/tmp/                                        # ditto
+/var/tmp/                                    # ditto
 ```
 
 And that's it.
index 84805067a7a79783b66f459a1458f3db0f2469b0..3c022315dafbdd43ae762ab4aaa754f4b0943868 100644 (file)
@@ -133,8 +133,6 @@ networkdir = join_paths(rootprefixdir, 'lib/systemd/network')
 pkgincludedir = join_paths(includedir, 'systemd')
 systemgeneratordir = join_paths(rootlibexecdir, 'system-generators')
 usergeneratordir = join_paths(prefixdir, 'lib/systemd/user-generators')
-pkgsysconfsystemgeneratordir = join_paths(pkgsysconfdir, 'system-generators')
-pkgsysconfusergeneratordir = join_paths(pkgsysconfdir, 'user-generators')
 systemenvgeneratordir = join_paths(prefixdir, 'lib/systemd/system-environment-generators')
 userenvgeneratordir = join_paths(prefixdir, 'lib/systemd/user-environment-generators')
 systemshutdowndir = join_paths(rootlibexecdir, 'system-shutdown')
index b1b88855af4ae108843c8c7eb771889adab2c573..a9a93d0f076323c431a8bb1eb475d282aa2e677b 100644 (file)
@@ -297,10 +297,8 @@ static int assess_root_directory(
         assert(ret_description);
 
         *ret_badness =
-                (isempty(info->root_directory) ||
-                 path_equal(info->root_directory, "/")) &&
-                (isempty(info->root_image) ||
-                 path_equal(info->root_image, "/"));
+                empty_or_root(info->root_directory) ||
+                empty_or_root(info->root_image);
         *ret_description = NULL;
 
         return 0;
index 9f3fd4569111ba8e1700a7b9170fc52bb8e8f69f..d1c06cf12a3a92223ce3ab2f4aa682105a5c32d9 100644 (file)
@@ -1411,9 +1411,9 @@ int open_parent(const char *path, int flags, mode_t mode) {
         /* Let's insist on O_DIRECTORY since the parent of a file or directory is a directory. Except if we open an
          * O_TMPFILE file, because in that case we are actually create a regular file below the parent directory. */
 
-        if ((flags & O_PATH) == O_PATH)
+        if (FLAGS_SET(flags, O_PATH))
                 flags |= O_DIRECTORY;
-        else if ((flags & O_TMPFILE) != O_TMPFILE)
+        else if (!FLAGS_SET(flags, O_TMPFILE))
                 flags |= O_DIRECTORY|O_RDONLY;
 
         fd = open(parent, flags, mode);
index 381c234f3b0e5d24167c802ba967e05fe50d7278..a7de3800fcf1a31131299fe6cdb7b652ea69bcf3 100644 (file)
@@ -675,7 +675,7 @@ static int insert_into_order(uint16_t slot, bool first) {
         }
 
         /* extend array */
-        t = realloc(order, (n + 1) * sizeof(uint16_t));
+        t = reallocarray(order, n + 1, sizeof(uint16_t));
         if (!t)
                 return -ENOMEM;
         order = t;
index 7b3e7824546e7304ce467a790ed00ec6e90f5307..57c423bfb6d8e38c3086b098cacde8b64f28ce87 100644 (file)
@@ -269,10 +269,8 @@ static BOOLEAN line_edit(
 
                 case KEYPRESS(0, 0, CHAR_LINEFEED):
                 case KEYPRESS(0, 0, CHAR_CARRIAGE_RETURN):
-                        if (StrCmp(line, line_in) != 0) {
-                                *line_out = line;
-                                line = NULL;
-                        }
+                        if (StrCmp(line, line_in) != 0)
+                                *line_out = TAKE_PTR(line);
                         enter = TRUE;
                         exit = TRUE;
                         break;
@@ -1258,8 +1256,7 @@ static VOID config_entry_bump_counters(
         /* If the file we just renamed is the loader path, then let's update that. */
         if (StrCmp(entry->loader, old_path) == 0) {
                 FreePool(entry->loader);
-                entry->loader = new_path;
-                new_path = NULL;
+                entry->loader = TAKE_PTR(new_path);
         }
 }
 
@@ -1360,10 +1357,8 @@ static VOID config_entry_add_from_file(
                                 s = PoolPrint(L"%s %s", entry->options, new);
                                 FreePool(entry->options);
                                 entry->options = s;
-                        } else {
-                                entry->options = new;
-                                new = NULL;
-                        }
+                        } else
+                                entry->options = TAKE_PTR(new);
 
                         continue;
                 }
@@ -1382,10 +1377,8 @@ static VOID config_entry_add_from_file(
                         s = PoolPrint(L"%s %s", initrd, entry->options);
                         FreePool(entry->options);
                         entry->options = s;
-                } else {
-                        entry->options = initrd;
-                        initrd = NULL;
-                }
+                } else
+                        entry->options = TAKE_PTR(initrd);
         }
 
         entry->device = device;
index bc1d4ae5c46225af62ece7507fe8a5ac3ab63aaf..4134e2200a9c87d4e7adf73e0b3c424529150aea 100644 (file)
@@ -122,8 +122,7 @@ EFI_STATUS efivar_get(const CHAR16 *name, CHAR16 **value) {
 
         /* Return buffer directly if it happens to be NUL terminated already */
         if (size >= 2 && buf[size-2] == 0 && buf[size-1] == 0) {
-                *value = (CHAR16*) buf;
-                buf = NULL;
+                *value = (CHAR16*) TAKE_PTR(buf);
                 return EFI_SUCCESS;
         }
 
index eb9ccd0cb0896b2e007f4e34e8ca34311894b7ae..f27c80120d6e57be40c8bd5392d53ddbf3d6c9c1 100644 (file)
@@ -922,10 +922,9 @@ static int run(int argc, char *argv[]) {
 
         arg_count = (mask & CGROUP_MASK_PIDS) ? COUNT_PIDS : COUNT_USERSPACE_PROCESSES;
 
-        if (arg_recursive_unset && arg_count == COUNT_PIDS) {
-                log_error("Non-recursive counting is only supported when counting processes, not tasks. Use -P or -k.");
-                return -EINVAL;
-        }
+        if (arg_recursive_unset && arg_count == COUNT_PIDS)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Non-recursive counting is only supported when counting processes, not tasks. Use -P or -k.");
 
         r = show_cgroup_get_path_and_warn(arg_machine, arg_root, &root);
         if (r < 0)
index 73b368e702a18d9dc235a0b92224d2a60e82f221..7fb1e6cc8be685b51423313e4ccd63800aeb8f47 100644 (file)
@@ -83,7 +83,7 @@ $1.SystemCallErrorNumber,        config_parse_warn_compat,           DISABLED_CO
 $1.MemoryDenyWriteExecute,       config_parse_warn_compat,           DISABLED_CONFIGURATION,        0
 $1.RestrictNamespaces,           config_parse_warn_compat,           DISABLED_CONFIGURATION,        0
 $1.RestrictRealtime,             config_parse_warn_compat,           DISABLED_CONFIGURATION,        0
-$1.RestrictSUIDSGID,             config_parse_warn_compat,           DISABLED_CONFIGURATION         0
+$1.RestrictSUIDSGID,             config_parse_warn_compat,           DISABLED_CONFIGURATION,        0
 $1.RestrictAddressFamilies,      config_parse_warn_compat,           DISABLED_CONFIGURATION,        0
 $1.LockPersonality,              config_parse_warn_compat,           DISABLED_CONFIGURATION,        0')
 $1.LimitCPU,                     config_parse_rlimit,                RLIMIT_CPU,                    offsetof($1, exec_context.rlimit)
index d850e106a39224ce0513b5c1e14dcd074f8c0490..86ab35d818d2c032cae4ff5da646d380d22bbc0f 100644 (file)
@@ -211,8 +211,6 @@ meson.add_install_script('sh', '-c', mkdir_p.format(systemshutdowndir))
 meson.add_install_script('sh', '-c', mkdir_p.format(systemsleepdir))
 meson.add_install_script('sh', '-c', mkdir_p.format(systemgeneratordir))
 meson.add_install_script('sh', '-c', mkdir_p.format(usergeneratordir))
-meson.add_install_script('sh', '-c', mkdir_p.format(pkgsysconfsystemgeneratordir))
-meson.add_install_script('sh', '-c', mkdir_p.format(pkgsysconfusergeneratordir))
 
 meson.add_install_script('sh', '-c',
                          mkdir_p.format(join_paths(pkgsysconfdir, 'system/multi-user.target.wants')))
index f455a4eb27cba6145f84fad59a065d07ea58691c..c2315c03fe6d803403e0a0c747fa59c3270c822a 100644 (file)
@@ -237,7 +237,7 @@ _public_ int sd_device_new_from_devnum(sd_device **ret, char type, dev_t devnum)
         assert_return(IN_SET(type, 'b', 'c'), -EINVAL);
 
         /* use /sys/dev/{block,char}/<maj>:<min> link */
-        snprintf(id, sizeof(id), "%u:%u", major(devnum), minor(devnum));
+        xsprintf(id, "%u:%u", major(devnum), minor(devnum));
 
         syspath = strjoina("/sys/dev/", (type == 'b' ? "block" : "char"), "/", id);
 
index eb98e49ca210b2aa3e36e6b6f4be233d90efb9d8..1987f279eb3f733c64ef6f7347fe7a7c3855bfea 100644 (file)
@@ -3116,7 +3116,7 @@ _public_ int sd_event_wait(sd_event *e, uint64_t timeout) {
                 timeout = 0;
 
         m = epoll_wait(e->epoll_fd, ev_queue, ev_queue_max,
-                       timeout == (uint64_t) -1 ? -1 : (int) ((timeout + USEC_PER_MSEC - 1) / USEC_PER_MSEC));
+                       timeout == (uint64_t) -1 ? -1 : (int) DIV_ROUND_UP(timeout, USEC_PER_MSEC));
         if (m < 0) {
                 if (errno == EINTR) {
                         e->state = SD_EVENT_PENDING;
index 07f21e84de534cfcea365915545995f03cb38d36..0dc368e6e25f69d27df834216373629a3a89321a 100644 (file)
@@ -818,7 +818,7 @@ _public_ int sd_get_uids(uid_t **users) {
                                 uid_t *t;
 
                                 n = MAX(16, 2*r);
-                                t = realloc(l, sizeof(uid_t) * n);
+                                t = reallocarray(l, sizeof(uid_t), n);
                                 if (!t)
                                         return -ENOMEM;
 
index 7c5d9d0abdefbf74dd38cac2e9d08f4b192e4bff..5ab4b480b92487ec19dd2a2b1e0b26f4a0a7d74f 100644 (file)
@@ -949,10 +949,8 @@ static int parse_argv(int argc, char *argv[]) {
 
                 case ARG_LINK_JOURNAL:
                         r = parse_link_journal(optarg, &arg_link_journal, &arg_link_journal_try);
-                        if (r < 0) {
-                                log_error_errno(r, "Failed to parse link journal mode %s", optarg);
-                                return -EINVAL;
-                        }
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to parse link journal mode %s", optarg);
 
                         arg_settings_mask |= SETTING_LINK_JOURNAL;
                         break;
@@ -1243,9 +1241,8 @@ static int parse_argv(int argc, char *argv[]) {
                         if (r < 0)
                                 return log_error_errno(r, "Failed to parse root hash: %s", optarg);
                         if (l < sizeof(sd_id128_t)) {
-                                log_error("Root hash must be at least 128bit long: %s", optarg);
                                 free(k);
-                                return -EINVAL;
+                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Root hash must be at least 128bit long: %s", optarg);
                         }
 
                         free(arg_root_hash);
@@ -1389,10 +1386,8 @@ static int parse_argv(int argc, char *argv[]) {
                                      "read-only\n"
                                      "passive\n"
                                      "pipe");
-                        else {
-                                log_error("Unknown console mode: %s", optarg);
-                                return -EINVAL;
-                        }
+                        else
+                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown console mode: %s", optarg);
 
                         arg_settings_mask |= SETTING_CONSOLE_MODE;
                         break;
@@ -2618,10 +2613,8 @@ static int determine_names(void) {
                                 return log_error_errno(r, "Failed to determine current directory: %m");
                 }
 
-                if (!arg_directory && !arg_image) {
-                        log_error("Failed to determine path, please use -D or -i.");
-                        return -EINVAL;
-                }
+                if (!arg_directory && !arg_image)
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to determine path, please use -D or -i.");
         }
 
         if (!arg_machine) {
@@ -2644,10 +2637,8 @@ static int determine_names(void) {
                         return log_oom();
 
                 hostname_cleanup(arg_machine);
-                if (!machine_name_is_valid(arg_machine)) {
-                        log_error("Failed to determine machine name automatically, please use -M.");
-                        return -EINVAL;
-                }
+                if (!machine_name_is_valid(arg_machine))
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to determine machine name automatically, please use -M.");
 
                 if (arg_ephemeral) {
                         char *b;
@@ -2774,10 +2765,8 @@ static int patch_sysctl(void) {
                                 break;
                 }
 
-                if (!good) {
-                        log_error("Refusing to write to sysctl '%s', as it is not safe in the selected namespaces.", *k);
-                        return -EPERM;
-                }
+                if (!good)
+                        return log_error_errno(SYNTHETIC_ERRNO(EPERM), "Refusing to write to sysctl '%s', as it is not safe in the selected namespaces.", *k);
 
                 r = sysctl_write(*k, *v);
                 if (r < 0)
@@ -4162,10 +4151,9 @@ static int run_container(int master,
                         log_debug_errno(r, "Cannot determine if passed network namespace path '%s' really refers to a network namespace, assuming it does.", arg_network_namespace_path);
                 else if (r < 0)
                         return log_error_errno(r, "Failed to check %s fs type: %m", arg_network_namespace_path);
-                else if (r == 0) {
-                        log_error("Path %s doesn't refer to a network namespace, refusing.", arg_network_namespace_path);
-                        return -EINVAL;
-                }
+                else if (r == 0)
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Path %s doesn't refer to a network namespace, refusing.", arg_network_namespace_path);
         }
 
         *pid = raw_clone(SIGCHLD|CLONE_NEWNS);
@@ -4228,10 +4216,8 @@ static int run_container(int master,
                 l = recv(uid_shift_socket_pair[0], &arg_uid_shift, sizeof arg_uid_shift, 0);
                 if (l < 0)
                         return log_error_errno(errno, "Failed to read UID shift: %m");
-                if (l != sizeof arg_uid_shift) {
-                        log_error("Short read while reading UID shift.");
-                        return -EIO;
-                }
+                if (l != sizeof arg_uid_shift)
+                        return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short read while reading UID shift.");
 
                 if (arg_userns_mode == USER_NAMESPACE_PICK) {
                         /* If we are supposed to pick the UID shift, let's try to use the shift read from the
@@ -4245,10 +4231,8 @@ static int run_container(int master,
                         l = send(uid_shift_socket_pair[0], &arg_uid_shift, sizeof arg_uid_shift, MSG_NOSIGNAL);
                         if (l < 0)
                                 return log_error_errno(errno, "Failed to send UID shift: %m");
-                        if (l != sizeof arg_uid_shift) {
-                                log_error("Short write while writing UID shift.");
-                                return -EIO;
-                        }
+                        if (l != sizeof arg_uid_shift)
+                                return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short write while writing UID shift.");
                 }
         }
 
@@ -4257,11 +4241,9 @@ static int run_container(int master,
                 l = recv(unified_cgroup_hierarchy_socket_pair[0], &arg_unified_cgroup_hierarchy, sizeof(arg_unified_cgroup_hierarchy), 0);
                 if (l < 0)
                         return log_error_errno(errno, "Failed to read cgroup mode: %m");
-                if (l != sizeof(arg_unified_cgroup_hierarchy)) {
-                        log_error("Short read while reading cgroup mode (%zu bytes).%s",
-                                  l, l == 0 ? " The child is most likely dead." : "");
-                        return -EIO;
-                }
+                if (l != sizeof(arg_unified_cgroup_hierarchy))
+                        return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short read while reading cgroup mode (%zu bytes).%s",
+                                               l, l == 0 ? " The child is most likely dead." : "");
         }
 
         /* Wait for the outer child. */
@@ -4275,19 +4257,15 @@ static int run_container(int master,
         l = recv(pid_socket_pair[0], pid, sizeof *pid, 0);
         if (l < 0)
                 return log_error_errno(errno, "Failed to read inner child PID: %m");
-        if (l != sizeof *pid) {
-                log_error("Short read while reading inner child PID.");
-                return -EIO;
-        }
+        if (l != sizeof *pid)
+                return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short read while reading inner child PID.");
 
         /* We also retrieve container UUID in case it was generated by outer child */
         l = recv(uuid_socket_pair[0], &arg_uuid, sizeof arg_uuid, 0);
         if (l < 0)
                 return log_error_errno(errno, "Failed to read container machine ID: %m");
-        if (l != sizeof(arg_uuid)) {
-                log_error("Short read while reading container machined ID.");
-                return -EIO;
-        }
+        if (l != sizeof(arg_uuid))
+                return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short read while reading container machined ID.");
 
         /* We also retrieve the socket used for notifications generated by outer child */
         notify_socket = receive_one_fd(notify_socket_pair[0], 0);
@@ -4298,10 +4276,8 @@ static int run_container(int master,
         log_debug("Init process invoked as PID "PID_FMT, *pid);
 
         if (arg_userns_mode != USER_NAMESPACE_NO) {
-                if (!barrier_place_and_sync(&barrier)) { /* #1 */
-                        log_error("Child died too early.");
-                        return -ESRCH;
-                }
+                if (!barrier_place_and_sync(&barrier)) /* #1 */
+                        return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "Child died too early.");
 
                 r = setup_uid_map(*pid);
                 if (r < 0)
@@ -4313,10 +4289,8 @@ static int run_container(int master,
         if (arg_private_network) {
                 if (!arg_network_namespace_path) {
                         /* Wait until the child has unshared its network namespace. */
-                        if (!barrier_place_and_sync(&barrier)) { /* #3 */
-                                log_error("Child died too early");
-                                return -ESRCH;
-                        }
+                        if (!barrier_place_and_sync(&barrier)) /* #3 */
+                                return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "Child died too early");
                 }
 
                 r = move_network_interfaces(*pid, arg_network_interfaces);
@@ -4472,10 +4446,8 @@ static int run_container(int master,
                 return r;
 
         /* Let the child know that we are ready and wait that the child is completely ready now. */
-        if (!barrier_place_and_sync(&barrier)) { /* #5 */
-                log_error("Child died too early.");
-                return -ESRCH;
-        }
+        if (!barrier_place_and_sync(&barrier)) /* #5 */
+                return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "Child died too early.");
 
         /* At this point we have made use of the UID we picked, and thus nss-mymachines
          * will make them appear in getpwuid(), thus we can release the /etc/passwd lock. */
index 7b9e13f3f63bc93017ac5a6dea17a17690e4d76d..1d2fc713092bdc63ca50131a2d0e01ac68fd99f2 100644 (file)
@@ -119,10 +119,8 @@ int ifname_mangle(const char *s) {
                 }
         }
 
-        if (arg_ifindex > 0 && arg_ifindex != ifi) {
-                log_error("Specified multiple different interfaces. Refusing.");
-                return -EINVAL;
-        }
+        if (arg_ifindex > 0 && arg_ifindex != ifi)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Specified multiple different interfaces. Refusing.");
 
         arg_ifindex = ifi;
         free_and_replace(arg_ifname, iface);
index 1911dd0ce642f875db511e9b5c56da66752d1942..00120e987414e4d4c7b683d71cbecea7d85414ac 100644 (file)
@@ -756,7 +756,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
 
                         if ((u & NAMESPACE_FLAGS_ALL) == 0)
                                 result = "yes";
-                        else if ((u & NAMESPACE_FLAGS_ALL) == NAMESPACE_FLAGS_ALL)
+                        else if (FLAGS_SET(u, NAMESPACE_FLAGS_ALL))
                                 result = "no";
                         else {
                                 r = namespace_flags_to_string(u, &s);
index 10431423e9ddeab3f8a7cd0b3dfda7f25f300029..db003a41a45360ae94ebd8bb71978b3ff1b1a4f0 100644 (file)
@@ -3297,10 +3297,8 @@ int json_dispatch_boolean(const char *name, JsonVariant *variant, JsonDispatchFl
         assert(variant);
         assert(b);
 
-        if (!json_variant_is_boolean(variant)) {
-                json_log(variant, flags, 0, "JSON field '%s' is not a boolean.", strna(name));
-                return -EINVAL;
-        }
+        if (!json_variant_is_boolean(variant))
+                return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a boolean.", strna(name));
 
         *b = json_variant_boolean(variant);
         return 0;
@@ -3312,10 +3310,8 @@ int json_dispatch_tristate(const char *name, JsonVariant *variant, JsonDispatchF
         assert(variant);
         assert(b);
 
-        if (!json_variant_is_boolean(variant)) {
-                json_log(variant, flags, 0, "JSON field '%s' is not a boolean.", strna(name));
-                return -EINVAL;
-        }
+        if (!json_variant_is_boolean(variant))
+                return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a boolean.", strna(name));
 
         *b = json_variant_boolean(variant);
         return 0;
@@ -3327,10 +3323,8 @@ int json_dispatch_integer(const char *name, JsonVariant *variant, JsonDispatchFl
         assert(variant);
         assert(i);
 
-        if (!json_variant_is_integer(variant)) {
-                json_log(variant, flags, 0, "JSON field '%s' is not an integer.", strna(name));
-                return -EINVAL;
-        }
+        if (!json_variant_is_integer(variant))
+                return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an integer.", strna(name));
 
         *i = json_variant_integer(variant);
         return 0;
@@ -3342,10 +3336,8 @@ int json_dispatch_unsigned(const char *name, JsonVariant *variant, JsonDispatchF
         assert(variant);
         assert(u);
 
-        if (!json_variant_is_unsigned(variant)) {
-                json_log(variant, flags, 0, "JSON field '%s' is not an unsigned integer.", strna(name));
-                return -EINVAL;
-        }
+        if (!json_variant_is_unsigned(variant))
+                return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an unsigned integer.", strna(name));
 
         *u = json_variant_unsigned(variant);
         return 0;
@@ -3357,15 +3349,11 @@ int json_dispatch_uint32(const char *name, JsonVariant *variant, JsonDispatchFla
         assert(variant);
         assert(u);
 
-        if (!json_variant_is_unsigned(variant)) {
-                json_log(variant, flags, 0, "JSON field '%s' is not an unsigned integer.", strna(name));
-                return -EINVAL;
-        }
+        if (!json_variant_is_unsigned(variant))
+                return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an unsigned integer.", strna(name));
 
-        if (json_variant_unsigned(variant) > UINT32_MAX) {
-                json_log(variant, flags, 0, "JSON field '%s' out of bounds.", strna(name));
-                return -ERANGE;
-        }
+        if (json_variant_unsigned(variant) > UINT32_MAX)
+                return json_log(variant, flags, SYNTHETIC_ERRNO(ERANGE), "JSON field '%s' out of bounds.", strna(name));
 
         *u = (uint32_t) json_variant_unsigned(variant);
         return 0;
@@ -3377,15 +3365,11 @@ int json_dispatch_int32(const char *name, JsonVariant *variant, JsonDispatchFlag
         assert(variant);
         assert(i);
 
-        if (!json_variant_is_integer(variant)) {
-                json_log(variant, flags, 0, "JSON field '%s' is not an integer.", strna(name));
-                return -EINVAL;
-        }
+        if (!json_variant_is_integer(variant))
+                return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an integer.", strna(name));
 
-        if (json_variant_integer(variant) < INT32_MIN || json_variant_integer(variant) > INT32_MAX) {
-                json_log(variant, flags, 0, "JSON field '%s' out of bounds.", strna(name));
-                return -ERANGE;
-        }
+        if (json_variant_integer(variant) < INT32_MIN || json_variant_integer(variant) > INT32_MAX)
+                return json_log(variant, flags, SYNTHETIC_ERRNO(ERANGE), "JSON field '%s' out of bounds.", strna(name));
 
         *i = (int32_t) json_variant_integer(variant);
         return 0;
@@ -3403,10 +3387,8 @@ int json_dispatch_string(const char *name, JsonVariant *variant, JsonDispatchFla
                 return 0;
         }
 
-        if (!json_variant_is_string(variant)) {
-                json_log(variant, flags, 0, "JSON field '%s' is not a string.", strna(name));
-                return -EINVAL;
-        }
+        if (!json_variant_is_string(variant))
+                return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name));
 
         r = free_and_strdup(s, json_variant_string(variant));
         if (r < 0)
@@ -3429,20 +3411,16 @@ int json_dispatch_strv(const char *name, JsonVariant *variant, JsonDispatchFlags
                 return 0;
         }
 
-        if (!json_variant_is_array(variant)) {
-                json_log(variant, 0, flags, "JSON field '%s' is not an array.", strna(name));
-                return -EINVAL;
-        }
+        if (!json_variant_is_array(variant))
+                return json_log(variant, SYNTHETIC_ERRNO(EINVAL), flags, "JSON field '%s' is not an array.", strna(name));
 
         for (i = 0; i < json_variant_elements(variant); i++) {
                 JsonVariant *e;
 
                 assert_se(e = json_variant_by_index(variant, i));
 
-                if (!json_variant_is_string(e)) {
-                        json_log(e, 0, flags, "JSON array element is not a string.");
-                        return -EINVAL;
-                }
+                if (!json_variant_is_string(e))
+                        return json_log(e, flags, SYNTHETIC_ERRNO(EINVAL), "JSON array element is not a string.");
 
                 r = strv_extend(&l, json_variant_string(e));
                 if (r < 0)
index c5d6feee7e1cdea199979ba21994f2b4847932c3..ee87d7c65c72b3244325c1b131a2176f118eb43c 100644 (file)
@@ -1645,8 +1645,7 @@ static bool match_key(UdevRules *rules, struct token *token, const char *val) {
         char *pos;
         bool match = false;
 
-        if (!val)
-                val = "";
+        val = strempty(val);
 
         switch (token->key.glob) {
         case GL_PLAIN: