mirror of
https://github.com/systemd/systemd.git
synced 2024-11-07 01:27:11 +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 "bus-util.h"
|
||||||
#include "dbus-kill.h"
|
#include "dbus-kill.h"
|
||||||
|
#include "dbus-util.h"
|
||||||
#include "kill.h"
|
#include "kill.h"
|
||||||
#include "signal-util.h"
|
#include "signal-util.h"
|
||||||
|
|
||||||
@ -34,6 +35,9 @@ const sd_bus_vtable bus_kill_vtable[] = {
|
|||||||
SD_BUS_VTABLE_END
|
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(
|
int bus_kill_context_set_transient_property(
|
||||||
Unit *u,
|
Unit *u,
|
||||||
KillContext *c,
|
KillContext *c,
|
||||||
@ -42,8 +46,6 @@ int bus_kill_context_set_transient_property(
|
|||||||
UnitWriteFlags flags,
|
UnitWriteFlags flags,
|
||||||
sd_bus_error *error) {
|
sd_bus_error *error) {
|
||||||
|
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(u);
|
assert(u);
|
||||||
assert(c);
|
assert(c);
|
||||||
assert(name);
|
assert(name);
|
||||||
@ -51,75 +53,17 @@ int bus_kill_context_set_transient_property(
|
|||||||
|
|
||||||
flags |= UNIT_PRIVATE;
|
flags |= UNIT_PRIVATE;
|
||||||
|
|
||||||
if (streq(name, "KillMode")) {
|
if (streq(name, "KillMode"))
|
||||||
const char *m;
|
return bus_set_transient_kill_mode(u, name, &c->kill_mode, message, flags, error);
|
||||||
KillMode k;
|
|
||||||
|
|
||||||
r = sd_bus_message_read(message, "s", &m);
|
if (streq(name, "SendSIGHUP"))
|
||||||
if (r < 0)
|
return bus_set_transient_bool(u, name, &c->send_sighup, message, flags, error);
|
||||||
return r;
|
|
||||||
|
|
||||||
k = kill_mode_from_string(m);
|
if (streq(name, "SendSIGKILL"))
|
||||||
if (k < 0)
|
return bus_set_transient_bool(u, name, &c->send_sigkill, message, flags, error);
|
||||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Kill mode '%s' not known.", m);
|
|
||||||
|
|
||||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
if (streq(name, "KillSignal"))
|
||||||
c->kill_mode = k;
|
return bus_set_transient_kill_signal(u, name, &c->kill_signal, message, flags, error);
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user