diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-10-14 12:31:57 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-10-14 12:44:36 +0200 |
commit | de34ec188c4d4f682a337445aa7753259cd7f821 (patch) | |
tree | c9b0b4c8d6716185324158c150f9b49a3233f4fe /src/libsystemd | |
parent | Merge pull request #34716 from dvdhrm/pr/derand (diff) | |
download | systemd-de34ec188c4d4f682a337445aa7753259cd7f821.tar.xz systemd-de34ec188c4d4f682a337445aa7753259cd7f821.zip |
pidref: hookup PID_AUTOMATIC special pid_t value with PidRef
The PID_AUTOMATIC value is now properly recognized by the PidRef logic
too. This needed some massaging of header includes, to ensure pidref.h
can access process-util.h's definitions and vice versa.
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-json/json-util.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/libsystemd/sd-json/json-util.c b/src/libsystemd/sd-json/json-util.c index 2ff4587565..0c1dea566a 100644 --- a/src/libsystemd/sd-json/json-util.c +++ b/src/libsystemd/sd-json/json-util.c @@ -185,7 +185,13 @@ int json_dispatch_pidref(const char *name, sd_json_variant *variant, sd_json_dis * above. If SD_JSON_STRICT is set this will acquire a pidfd for the process, and validate that the * auxiliary fields match it. Otherwise, this will just store the pid and the pidfd inode number (the * latter not if the provided boot id differs from the local one), and not attempt to get a pidfd for - * it, or authenticate it. */ + * it, or authenticate it. + * + * If SD_JSON_RELAX is specified, a specified but zero/empty PID will be mapped to PIDREF_AUTOMATIC, + * which is supposed to indicate that the PID shall be automatically derived, typically from the + * connection peer. + * + * Note that SD_JSON_RELAX and SD_JSON_STRICT can be combined. */ if (sd_json_variant_is_null(variant)) { pidref_done(p); @@ -220,6 +226,13 @@ int json_dispatch_pidref(const char *name, sd_json_variant *variant, sd_json_dis } else return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is neither a numeric PID nor a PID object.", strna(name)); + /* If SD_JSON_RELAX is set then we'll take a specified but zero field as request for "automic" PID derivation */ + if ((flags & SD_JSON_RELAX) && data.pid == 0 && data.fd_id == 0 && sd_id128_is_null(data.boot_id)) { + pidref_done(p); + *p = PIDREF_AUTOMATIC; + return 0; + } + /* Before casting the 64bit data.pid field to pid_t, let's ensure it fits the pid_t range. */ if (data.pid > PID_T_MAX || !pid_is_valid(data.pid)) return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' does not contain a valid PID.", strna(name)); |