systemctl: modernization
This commit is contained in:
parent
8c7c140fca
commit
31e767f73a
|
@ -3329,12 +3329,13 @@ static int switch_root(DBusConnection *bus, char **args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_environment(DBusConnection *bus, char **args) {
|
static int set_environment(DBusConnection *bus, char **args) {
|
||||||
DBusMessage *m = NULL, *reply = NULL;
|
_cleanup_dbus_message_unref_ DBusMessage *m = NULL, *reply = NULL;
|
||||||
DBusError error;
|
DBusError error;
|
||||||
int r;
|
|
||||||
const char *method;
|
const char *method;
|
||||||
DBusMessageIter iter, sub;
|
DBusMessageIter iter;
|
||||||
char **name;
|
int r;
|
||||||
|
|
||||||
|
assert(bus);
|
||||||
|
|
||||||
dbus_error_init(&error);
|
dbus_error_init(&error);
|
||||||
|
|
||||||
|
@ -3342,38 +3343,22 @@ static int set_environment(DBusConnection *bus, char **args) {
|
||||||
? "SetEnvironment"
|
? "SetEnvironment"
|
||||||
: "UnsetEnvironment";
|
: "UnsetEnvironment";
|
||||||
|
|
||||||
if (!(m = dbus_message_new_method_call(
|
m = dbus_message_new_method_call(
|
||||||
"org.freedesktop.systemd1",
|
"org.freedesktop.systemd1",
|
||||||
"/org/freedesktop/systemd1",
|
"/org/freedesktop/systemd1",
|
||||||
"org.freedesktop.systemd1.Manager",
|
"org.freedesktop.systemd1.Manager",
|
||||||
method))) {
|
method);
|
||||||
|
if (!m)
|
||||||
log_error("Could not allocate message.");
|
return log_oom();
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_message_iter_init_append(m, &iter);
|
dbus_message_iter_init_append(m, &iter);
|
||||||
|
|
||||||
if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub)) {
|
r = bus_append_strv_iter(&iter, args + 1);
|
||||||
log_error("Could not append arguments to message.");
|
if (r < 0)
|
||||||
r = -ENOMEM;
|
return log_oom();
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
STRV_FOREACH(name, args+1)
|
reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
|
||||||
if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, name)) {
|
if (!reply) {
|
||||||
log_error("Could not append arguments to message.");
|
|
||||||
r = -ENOMEM;
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dbus_message_iter_close_container(&iter, &sub)) {
|
|
||||||
log_error("Could not append arguments to message.");
|
|
||||||
r = -ENOMEM;
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error))) {
|
|
||||||
log_error("Failed to issue method call: %s", bus_error_message(&error));
|
log_error("Failed to issue method call: %s", bus_error_message(&error));
|
||||||
r = -EIO;
|
r = -EIO;
|
||||||
goto finish;
|
goto finish;
|
||||||
|
@ -3382,14 +3367,7 @@ static int set_environment(DBusConnection *bus, char **args) {
|
||||||
r = 0;
|
r = 0;
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
if (m)
|
|
||||||
dbus_message_unref(m);
|
|
||||||
|
|
||||||
if (reply)
|
|
||||||
dbus_message_unref(reply);
|
|
||||||
|
|
||||||
dbus_error_free(&error);
|
dbus_error_free(&error);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue