mirror of
https://github.com/systemd/systemd.git
synced 2024-11-06 16:59:03 +03:00
dbus-kill: simplify bus_kill_context_set_transient_property()
This commit is contained in:
parent
b3f1d5400b
commit
886295990b
@ -20,6 +20,7 @@
|
||||
|
||||
#include "bus-util.h"
|
||||
#include "dbus-kill.h"
|
||||
#include "dbus-util.h"
|
||||
#include "kill.h"
|
||||
#include "signal-util.h"
|
||||
|
||||
@ -34,6 +35,9 @@ const sd_bus_vtable bus_kill_vtable[] = {
|
||||
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,
|
||||
@ -42,8 +46,6 @@ int bus_kill_context_set_transient_property(
|
||||
UnitWriteFlags flags,
|
||||
sd_bus_error *error) {
|
||||
|
||||
int r;
|
||||
|
||||
assert(u);
|
||||
assert(c);
|
||||
assert(name);
|
||||
@ -51,75 +53,17 @@ int bus_kill_context_set_transient_property(
|
||||
|
||||
flags |= UNIT_PRIVATE;
|
||||
|
||||
if (streq(name, "KillMode")) {
|
||||
const char *m;
|
||||
KillMode k;
|
||||
if (streq(name, "KillMode"))
|
||||
return bus_set_transient_kill_mode(u, name, &c->kill_mode, message, flags, error);
|
||||
|
||||
r = sd_bus_message_read(message, "s", &m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (streq(name, "SendSIGHUP"))
|
||||
return bus_set_transient_bool(u, name, &c->send_sighup, message, flags, error);
|
||||
|
||||
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 (streq(name, "SendSIGKILL"))
|
||||
return bus_set_transient_bool(u, name, &c->send_sigkill, message, flags, error);
|
||||
|
||||
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;
|
||||
|
||||
unit_write_settingf(u, flags, name, "SendSIGKILL=%s", yes_no(b));
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
if (streq(name, "KillSignal"))
|
||||
return bus_set_transient_kill_signal(u, name, &c->kill_signal, message, flags, error);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user