mirror of
https://github.com/systemd/systemd
synced 2024-09-06 16:56:43 +00:00
core/dbus-execute: modernize a bit
This commit is contained in:
parent
21b366121f
commit
ccbb85a58b
|
@ -1306,18 +1306,24 @@ int bus_set_transient_exec_command(
|
|||
sd_bus_message *message,
|
||||
UnitWriteFlags flags,
|
||||
sd_bus_error *error) {
|
||||
bool is_ex_prop = endswith(name, "Ex");
|
||||
unsigned n = 0;
|
||||
|
||||
const char *ex_prop = endswith(ASSERT_PTR(name), "Ex");
|
||||
size_t n = 0;
|
||||
int r;
|
||||
|
||||
/* Drop Ex from the written setting. E.g. ExecStart=, not ExecStartEx=. */
|
||||
const char *written_name = is_ex_prop ? strndupa_safe(name, strlen(name) - 2) : name;
|
||||
assert(u);
|
||||
assert(exec_command);
|
||||
assert(message);
|
||||
assert(error);
|
||||
|
||||
r = sd_bus_message_enter_container(message, 'a', is_ex_prop ? "(sasas)" : "(sasb)");
|
||||
/* Drop Ex from the written setting. E.g. ExecStart=, not ExecStartEx=. */
|
||||
const char *written_name = ex_prop ? strndupa_safe(name, ex_prop - name) : name;
|
||||
|
||||
r = sd_bus_message_enter_container(message, 'a', ex_prop ? "(sasas)" : "(sasb)");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
while ((r = sd_bus_message_enter_container(message, 'r', is_ex_prop ? "sasas" : "sasb")) > 0) {
|
||||
while ((r = sd_bus_message_enter_container(message, 'r', ex_prop ? "sasas" : "sasb")) > 0) {
|
||||
_cleanup_strv_free_ char **argv = NULL, **ex_opts = NULL;
|
||||
const char *path;
|
||||
int b;
|
||||
|
@ -1339,7 +1345,7 @@ int bus_set_transient_exec_command(
|
|||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
|
||||
"\"%s\" argv cannot be empty", name);
|
||||
|
||||
r = is_ex_prop ? sd_bus_message_read_strv(message, &ex_opts) : sd_bus_message_read(message, "b", &b);
|
||||
r = ex_prop ? sd_bus_message_read_strv(message, &ex_opts) : sd_bus_message_read(message, "b", &b);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -1362,7 +1368,7 @@ int bus_set_transient_exec_command(
|
|||
|
||||
c->argv = TAKE_PTR(argv);
|
||||
|
||||
if (is_ex_prop) {
|
||||
if (ex_prop) {
|
||||
r = exec_command_flags_from_strv(ex_opts, &c->flags);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
|
Loading…
Reference in a new issue