#include "bus-util.h"
#include "dbus-kill.h"
+#include "dbus-util.h"
#include "kill.h"
#include "signal-util.h"
SD_BUS_VTABLE_END
};
+static BUS_DEFINE_SET_TRANSIENT_PARSE(kill_mode, KillMode, kill_mode_from_string);
+static BUS_DEFINE_SET_TRANSIENT_TO_STRING(kill_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check);
+
int bus_kill_context_set_transient_property(
Unit *u,
KillContext *c,
UnitWriteFlags flags,
sd_bus_error *error) {
- int r;
-
assert(u);
assert(c);
assert(name);
flags |= UNIT_PRIVATE;
- if (streq(name, "KillMode")) {
- const char *m;
- KillMode k;
-
- r = sd_bus_message_read(message, "s", &m);
- if (r < 0)
- return r;
-
- k = kill_mode_from_string(m);
- if (k < 0)
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Kill mode '%s' not known.", m);
-
- if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
- c->kill_mode = k;
-
- unit_write_settingf(u, flags, name, "KillMode=%s", kill_mode_to_string(k));
- }
-
- return 1;
-
- } else if (streq(name, "KillSignal")) {
- int sig;
-
- r = sd_bus_message_read(message, "i", &sig);
- if (r < 0)
- return r;
-
- if (!SIGNAL_VALID(sig))
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Signal %i out of range", sig);
-
- if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
- c->kill_signal = sig;
-
- unit_write_settingf(u, flags, name, "KillSignal=%s", signal_to_string(sig));
- }
-
- return 1;
-
- } else if (streq(name, "SendSIGHUP")) {
- int b;
-
- r = sd_bus_message_read(message, "b", &b);
- if (r < 0)
- return r;
-
- if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
- c->send_sighup = b;
-
- unit_write_settingf(u, flags, name, "SendSIGHUP=%s", yes_no(b));
- }
-
- return 1;
-
- } else if (streq(name, "SendSIGKILL")) {
- int b;
-
- r = sd_bus_message_read(message, "b", &b);
- if (r < 0)
- return r;
-
- if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
- c->send_sigkill = b;
+ if (streq(name, "KillMode"))
+ return bus_set_transient_kill_mode(u, name, &c->kill_mode, message, flags, error);
- unit_write_settingf(u, flags, name, "SendSIGKILL=%s", yes_no(b));
- }
+ if (streq(name, "SendSIGHUP"))
+ return bus_set_transient_bool(u, name, &c->send_sighup, message, flags, error);
- return 1;
+ if (streq(name, "SendSIGKILL"))
+ return bus_set_transient_bool(u, name, &c->send_sigkill, message, flags, error);
- }
+ if (streq(name, "KillSignal"))
+ return bus_set_transient_kill_signal(u, name, &c->kill_signal, message, flags, error);
return 0;
}