]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-json: add sd_json_dispatch_signal()
authorIvan Kruglov <mail@ikruglov.com>
Wed, 9 Oct 2024 11:35:14 +0000 (13:35 +0200)
committerIvan Kruglov <mail@ikruglov.com>
Thu, 10 Oct 2024 11:40:45 +0000 (13:40 +0200)
src/basic/signal-util.h
src/libsystemd/libsystemd.sym
src/libsystemd/sd-json/sd-json.c
src/systemd/sd-json.h

index 633993ca00ee5635c49aa1f8e273073385593116..5739fe055930f697a773dda00e6e3f5d7496f446 100644 (file)
@@ -46,6 +46,7 @@ static inline void block_signals_reset(sigset_t *ss) {
                 assert_se(sigprocmask_many(SIG_BLOCK, &_t, __VA_ARGS__) >= 0);     \
                 _t;                                                                \
         })
+#define SIGNO_INVALID (-EINVAL)
 
 static inline bool SIGNAL_VALID(int signo) {
         return signo > 0 && signo < _NSIG;
index acee085f2f18d177b44560f24dc62708c22c3e24..b3f46f90f19ff25f6624f8dcf3c0dcbe6b82256d 100644 (file)
@@ -868,6 +868,7 @@ global:
         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;
index 33ccdcac5aad0f4e5ac5dbfabd5a8e881637f65d..3c6f6b140b188e0aaac428b7b50beba8341028f4 100644 (file)
@@ -30,6 +30,7 @@
 #include "memstream-util.h"
 #include "path-util.h"
 #include "set.h"
+#include "signal-util.h"
 #include "string-table.h"
 #include "string-util.h"
 #include "strv.h"
@@ -5527,6 +5528,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));
 }
index b0b171dcb62676ab34639870d2732f6c87bac345..f3c9a272572e3da0c94e54ad1292104ad019dd08 100644 (file)
@@ -329,6 +329,7 @@ int sd_json_dispatch_uint8(const char *name, sd_json_variant *variant, sd_json_d
 int sd_json_dispatch_double(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
 int sd_json_dispatch_uid_gid(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
 int sd_json_dispatch_id128(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
+int sd_json_dispatch_signal(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
 int sd_json_dispatch_unsupported(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
 
 #define sd_json_dispatch_uint sd_json_dispatch_uint32