#include "sleep-config.h"
#include "special.h"
#include "serialize.h"
+#include "signal-util.h"
#include "stdio-util.h"
#include "strv.h"
#include "terminal-util.h"
return RET_GATHER(k, r);
}
+static int strdup_job(sd_bus_message *reply, char **ret) {
+ const char *j;
+ char *job;
+ int r;
+
+ assert(reply);
+ assert(ret);
+
+ r = sd_bus_message_read_basic(reply, 'o', &j);
+ if (r < 0)
+ return r;
+
+ job = strdup(j);
+ if (!job)
+ return -ENOMEM;
+
+ *ret = job;
+ return 0;
+}
+
static int execute_shutdown_or_sleep(
Manager *m,
const HandleActionData *a,
sd_bus_error *error) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
- const char *p;
int r;
assert(m);
&reply,
"ss", a->target, "replace-irreversibly");
if (r < 0)
- goto error;
+ goto fail;
- r = sd_bus_message_read(reply, "o", &p);
+ r = strdup_job(reply, &m->action_job);
if (r < 0)
- goto error;
-
- m->action_job = strdup(p);
- if (!m->action_job) {
- r = -ENOMEM;
- goto error;
- }
+ goto fail;
m->delayed_action = a;
return 0;
-error:
+fail:
/* Tell people that they now may take a lock again */
(void) send_prepare_for(m, a, false);
l);
}
-static int strdup_job(sd_bus_message *reply, char **job) {
- const char *j;
- char *copy;
- int r;
-
- r = sd_bus_message_read(reply, "o", &j);
- if (r < 0)
- return r;
-
- copy = strdup(j);
- if (!copy)
- return -ENOMEM;
-
- *job = copy;
- return 1;
-}
-
int manager_start_scope(
Manager *manager,
const char *scope,
return strdup_job(reply, ret_job);
}
-int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job) {
+int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **ret_job) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
int r;
assert(manager);
assert(unit);
- assert(job);
+ assert(ret_job);
r = bus_call_method(
manager->bus,
if (r < 0)
return r;
- return strdup_job(reply, job);
+ return strdup_job(reply, ret_job);
}
-int manager_stop_unit(Manager *manager, const char *unit, const char *job_mode, sd_bus_error *error, char **ret_job) {
+int manager_stop_unit(
+ Manager *manager,
+ const char *unit,
+ const char *job_mode,
+ sd_bus_error *ret_error,
+ char **ret_job) {
+
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
int r;
assert(manager);
manager->bus,
bus_systemd_mgr,
"StopUnit",
- error,
+ &error,
&reply,
"ss", unit, job_mode ?: "fail");
if (r < 0) {
- if (sd_bus_error_has_names(error, BUS_ERROR_NO_SUCH_UNIT,
- BUS_ERROR_LOAD_FAILED)) {
-
+ if (sd_bus_error_has_names(&error, BUS_ERROR_NO_SUCH_UNIT, BUS_ERROR_LOAD_FAILED)) {
*ret_job = NULL;
- sd_bus_error_free(error);
return 0;
}
+ sd_bus_error_move(ret_error, &error);
return r;
}
- return strdup_job(reply, ret_job);
+ r = strdup_job(reply, ret_job);
+ if (r < 0)
+ return r;
+
+ return 1;
}
int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *ret_error) {
int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error) {
assert(manager);
assert(unit);
+ assert(SIGNAL_VALID(signo));
return bus_call_method(
manager->bus,
"KillUnit",
error,
NULL,
- "ssi", unit, who == KILL_LEADER ? "main" : "all", signo);
+ "ssi",
+ unit,
+ who == KILL_LEADER ? "main" : "all",
+ signo);
}
int manager_unit_is_active(Manager *manager, const char *unit, sd_bus_error *ret_error) {