summaryrefslogtreecommitdiffstats
path: root/src/libsystemd
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-10-11 12:15:56 +0200
committerGitHub <noreply@github.com>2024-10-11 12:15:56 +0200
commit373c810e04c45836fe820df0482d4f3274962246 (patch)
tree65993fb66caed1b2a576822cf9f2d64cb2be0a82 /src/libsystemd
parentseccomp: allowlist uretprobe() syscall (diff)
parentmachine: use sd_json_dispatch_pid() in varlink code (diff)
downloadsystemd-373c810e04c45836fe820df0482d4f3274962246.tar.xz
systemd-373c810e04c45836fe820df0482d4f3274962246.zip
Merge pull request #34681 from ikruglov/ikruglov/io-systemd-Machine-post-merge-review
machine: address post-merge review #34623
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/libsystemd.sym2
-rw-r--r--src/libsystemd/sd-json/sd-json.c63
2 files changed, 65 insertions, 0 deletions
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
index acee085f2f..d642ef2581 100644
--- a/src/libsystemd/libsystemd.sym
+++ b/src/libsystemd/libsystemd.sym
@@ -864,10 +864,12 @@ global:
sd_json_dispatch_strv;
sd_json_dispatch_tristate;
sd_json_dispatch_uid_gid;
+ sd_json_dispatch_pid;
sd_json_dispatch_uint16;
sd_json_dispatch_uint32;
sd_json_dispatch_uint64;
sd_json_dispatch_uint8;
+ sd_json_dispatch_signal;
sd_json_dispatch_unsupported;
sd_json_dispatch_variant;
sd_json_dispatch_variant_noref;
diff --git a/src/libsystemd/sd-json/sd-json.c b/src/libsystemd/sd-json/sd-json.c
index 33ccdcac5a..58ae134e16 100644
--- a/src/libsystemd/sd-json/sd-json.c
+++ b/src/libsystemd/sd-json/sd-json.c
@@ -29,7 +29,9 @@
#include "memory-util.h"
#include "memstream-util.h"
#include "path-util.h"
+#include "process-util.h"
#include "set.h"
+#include "signal-util.h"
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
@@ -5506,6 +5508,44 @@ _public_ int sd_json_dispatch_uid_gid(const char *name, sd_json_variant *variant
return 0;
}
+_public_ int sd_json_dispatch_pid(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
+ /* pid_t is a signed type, but we don't consider negative values as valid.
+ * There is a special treatment for 0 if SD_JSON_RELAX flag present. */
+
+ pid_t *pid = userdata;
+ uint32_t k;
+ int r;
+
+ assert_return(variant, -EINVAL);
+ assert_cc(sizeof(pid_t) == sizeof(uint32_t));
+
+ if (sd_json_variant_is_null(variant)) {
+ *pid = PID_INVALID;
+ return 0;
+ }
+
+ r = sd_json_dispatch_uint32(name, variant, flags, &k);
+ if (r < 0)
+ return r;
+
+ if (k == 0) {
+ if (!FLAGS_SET(flags, SD_JSON_RELAX))
+ goto invalid_value;
+
+ *pid = PID_AUTOMATIC;
+ return 0;
+ }
+
+ if (!pid_is_valid(k))
+ goto invalid_value;
+
+ *pid = k;
+ return 0;
+
+invalid_value:
+ return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid PID.", strna(name));
+}
+
_public_ int sd_json_dispatch_id128(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
sd_id128_t *uuid = userdata;
int r;
@@ -5527,6 +5567,29 @@ _public_ int sd_json_dispatch_id128(const char *name, sd_json_variant *variant,
return 0;
}
+_public_ int sd_json_dispatch_signal(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
+ int *signo = userdata;
+ uint32_t k;
+ int r;
+
+ assert_return(variant, -EINVAL);
+
+ if (sd_json_variant_is_null(variant)) {
+ *signo = SIGNO_INVALID;
+ return 0;
+ }
+
+ r = sd_json_dispatch_uint32(name, variant, flags, &k);
+ if (r < 0)
+ return r;
+
+ if (!SIGNAL_VALID(k))
+ return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid signal.", strna(name));
+
+ *signo = k;
+ return 0;
+}
+
_public_ int sd_json_dispatch_unsupported(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not allowed in this object.", strna(name));
}