From: Yu Watanabe Date: Wed, 14 Dec 2022 04:34:15 +0000 (+0900) Subject: sd-id128: allow sd_id128_get_machine() and friend to be called with NULL X-Git-Tag: v253-rc1~287^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=786b652c8989834f9218ec82b2d824d5b753fad3;p=thirdparty%2Fsystemd.git sd-id128: allow sd_id128_get_machine() and friend to be called with NULL It may be useful to check if the machine ID or friends is set or not. --- diff --git a/src/libsystemd/sd-id128/sd-id128.c b/src/libsystemd/sd-id128/sd-id128.c index 146c379398d..9fac1bb3fc3 100644 --- a/src/libsystemd/sd-id128/sd-id128.c +++ b/src/libsystemd/sd-id128/sd-id128.c @@ -124,8 +124,6 @@ _public_ int sd_id128_get_machine(sd_id128_t *ret) { static thread_local sd_id128_t saved_machine_id = {}; int r; - assert_return(ret, -EINVAL); - if (sd_id128_is_null(saved_machine_id)) { r = id128_read("/etc/machine-id", ID128_FORMAT_PLAIN, &saved_machine_id); if (r < 0) @@ -135,7 +133,8 @@ _public_ int sd_id128_get_machine(sd_id128_t *ret) { return -ENOMEDIUM; } - *ret = saved_machine_id; + if (ret) + *ret = saved_machine_id; return 0; } @@ -143,8 +142,6 @@ _public_ int sd_id128_get_boot(sd_id128_t *ret) { static thread_local sd_id128_t saved_boot_id = {}; int r; - assert_return(ret, -EINVAL); - if (sd_id128_is_null(saved_boot_id)) { r = id128_read("/proc/sys/kernel/random/boot_id", ID128_FORMAT_UUID, &saved_boot_id); if (r == -ENOENT && proc_mounted() == 0) @@ -156,7 +153,8 @@ _public_ int sd_id128_get_boot(sd_id128_t *ret) { return -ENOMEDIUM; } - *ret = saved_boot_id; + if (ret) + *ret = saved_boot_id; return 0; } @@ -276,26 +274,20 @@ _public_ int sd_id128_get_invocation(sd_id128_t *ret) { static thread_local sd_id128_t saved_invocation_id = {}; int r; - assert_return(ret, -EINVAL); - if (sd_id128_is_null(saved_invocation_id)) { /* We first check the environment. The environment variable is primarily relevant for user * services, and sufficiently safe as long as no privilege boundary is involved. */ r = get_invocation_from_environment(&saved_invocation_id); - if (r >= 0) { - *ret = saved_invocation_id; - return 0; - } else if (r != -ENXIO) - return r; - - /* The kernel keyring is relevant for system services (as for user services we don't store - * the invocation ID in the keyring, as there'd be no trust benefit in that). */ - r = get_invocation_from_keyring(&saved_invocation_id); + if (r == -ENXIO) + /* The kernel keyring is relevant for system services (as for user services we don't + * store the invocation ID in the keyring, as there'd be no trust benefit in that). */ + r = get_invocation_from_keyring(&saved_invocation_id); if (r < 0) return r; } - *ret = saved_invocation_id; + if (ret) + *ret = saved_invocation_id; return 0; }