return i >= 0 && i <= sched_get_priority_max(SCHED_RR);
}
+#define PID_AUTOMATIC ((pid_t) INT_MIN) /* special value indicating "acquire pid from connection peer */
+#define PID_INVALID ((pid_t) 0) /* default value for "invalid pid" */
+
static inline bool pid_is_valid(pid_t p) {
return p > 0;
}
+static inline bool pid_is_automatic(pid_t p) {
+ return p == PID_AUTOMATIC;
+}
+
+static inline bool pid_is_valid_or_automatic(pid_t p) {
+ return pid_is_valid(p) || pid_is_automatic(p);
+}
+
pid_t getpid_cached(void);
void reset_cached_pid(void);
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;
#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"
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;
int sd_json_dispatch_uint8(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
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_pid(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);