summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-11-21 19:34:37 +0100
committerLennart Poettering <lennart@poettering.net>2013-11-21 21:12:36 +0100
commitebcf1f97de4f6b1580ae55eb56b1a3939fe6b602 (patch)
treedef5185990acebac842ed8fca253531d88897a4a
parent0ccad099d4c08dc5a16c87cdd6eefc05e9d4b670 (diff)
bus: rework message handlers to always take an error argument
Message handler callbacks can be simplified drastically if the dispatcher automatically replies to method calls if errors are returned. Thus: add an sd_bus_error argument to all message handlers. When we dispatch a message handler and it returns negative or a set sd_bus_error we send this as message error back to the client. This means errors returned by handlers by default are given back to clients instead of rippling all the way up to the event loop, which is desirable to make things robust. As a side-effect we can now easily turn the SELinux checks into normal function calls, since the method call dispatcher will generate the right error replies automatically now. Also, make sure we always pass the error structure to all property and method handlers as last argument to follow the usual style of passing variables for return values as last argument.
-rw-r--r--TODO4
-rw-r--r--src/core/dbus-cgroup.c12
-rw-r--r--src/core/dbus-client-track.c7
-rw-r--r--src/core/dbus-execute.c52
-rw-r--r--src/core/dbus-execute.h4
-rw-r--r--src/core/dbus-job.c12
-rw-r--r--src/core/dbus-manager.c559
-rw-r--r--src/core/dbus-mount.c12
-rw-r--r--src/core/dbus-path.c8
-rw-r--r--src/core/dbus-snapshot.c7
-rw-r--r--src/core/dbus-snapshot.h2
-rw-r--r--src/core/dbus-socket.c4
-rw-r--r--src/core/dbus-swap.c4
-rw-r--r--src/core/dbus-timer.c12
-rw-r--r--src/core/dbus-unit.c166
-rw-r--r--src/core/dbus-unit.h10
-rw-r--r--src/core/dbus.c8
-rw-r--r--src/core/selinux-access.c4
-rw-r--r--src/core/selinux-access.h32
-rw-r--r--src/hostname/hostnamed.c83
-rw-r--r--src/libsystemd-bus/bus-match.c7
-rw-r--r--src/libsystemd-bus/bus-message.c2
-rw-r--r--src/libsystemd-bus/bus-objects.c100
-rw-r--r--src/libsystemd-bus/bus-util.c161
-rw-r--r--src/libsystemd-bus/bus-util.h16
-rw-r--r--src/libsystemd-bus/sd-bus.c26
-rw-r--r--src/libsystemd-bus/test-bus-chat.c6
-rw-r--r--src/libsystemd-bus/test-bus-introspect.c4
-rw-r--r--src/libsystemd-bus/test-bus-match.c2
-rw-r--r--src/libsystemd-bus/test-bus-objects.c20
-rw-r--r--src/locale/localed.c52
-rw-r--r--src/login/logind-dbus.c475
-rw-r--r--src/login/logind-seat-dbus.c42
-rw-r--r--src/login/logind-session-dbus.c98
-rw-r--r--src/login/logind-user-dbus.c36
-rw-r--r--src/login/logind.h10
-rw-r--r--src/machine/machine-dbus.c22
-rw-r--r--src/machine/machined-dbus.c123
-rw-r--r--src/machine/machined.h8
-rw-r--r--src/systemctl/systemctl.c4
-rw-r--r--src/systemd/sd-bus.h20
-rw-r--r--src/timedate/timedated.c99
42 files changed, 1202 insertions, 1133 deletions
diff --git a/TODO b/TODO
index 66f99a9ea8..f84a24727b 100644
--- a/TODO
+++ b/TODO
@@ -43,6 +43,8 @@ CGroup Rework Completion:
Features:
+* add API to clone sd_bus_message objects
+
* sd-bus: synthesized messages should get serial number (uint32_t) -1
* sd-event: allow multiple signal handlers per signal
@@ -62,8 +64,6 @@ Features:
* sd-bus: enforce signatures on response messages
-* sd-bus: make message handlers take an sd_bus_error and generate error replies automatically if they are set
-
* sd-bus: see if we can drop more message validation on the sending side
* sd-bus: introduce sd_bus_creds object and attach it to messages as well as allow querying it for names
diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
index 4dbb83a769..39865a96da 100644
--- a/src/core/dbus-cgroup.c
+++ b/src/core/dbus-cgroup.c
@@ -33,8 +33,8 @@ static int property_get_blockio_device_weight(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
CGroupContext *c = userdata;
CGroupBlockIODeviceWeight *w;
@@ -63,8 +63,8 @@ static int property_get_blockio_device_bandwidths(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
CGroupContext *c = userdata;
CGroupBlockIODeviceBandwidth *b;
@@ -97,8 +97,8 @@ static int property_get_device_allow(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
CGroupContext *c = userdata;
CGroupDeviceAllow *a;
diff --git a/src/core/dbus-client-track.c b/src/core/dbus-client-track.c
index ce514b577c..4a5bdef040 100644
--- a/src/core/dbus-client-track.c
+++ b/src/core/dbus-client-track.c
@@ -19,6 +19,7 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "bus-util.h"
#include "dbus-client-track.h"
static unsigned tracked_client_hash(const void *a) {
@@ -43,7 +44,7 @@ static int tracked_client_compare(const void *a, const void *b) {
return 0;
}
-static int on_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int on_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
BusTrackedClient *c = userdata;
const char *name, *old, *new;
int r;
@@ -53,8 +54,8 @@ static int on_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *use
r = sd_bus_message_read(message, "sss", &name, &old, &new);
if (r < 0) {
- log_debug("Failed to parse NameOwnerChanged message.");
- return 0;
+ bus_log_parse_error(r);
+ return r;
}
bus_client_untrack(c->set, bus, name);
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
index ca7ee5c10b..90556274d3 100644
--- a/src/core/dbus-execute.c
+++ b/src/core/dbus-execute.c
@@ -40,8 +40,8 @@ static int property_get_environment_files(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
ExecContext *c = userdata;
char **j;
@@ -72,8 +72,8 @@ static int property_get_rlimit(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
struct rlimit *rl;
uint64_t u;
@@ -106,8 +106,8 @@ static int property_get_oom_score_adjust(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
ExecContext *c = userdata;
@@ -136,8 +136,8 @@ static int property_get_nice(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
ExecContext *c = userdata;
@@ -165,8 +165,8 @@ static int property_get_ioprio(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
ExecContext *c = userdata;
@@ -193,8 +193,8 @@ static int property_get_cpu_sched_policy(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
ExecContext *c = userdata;
int32_t n;
@@ -220,8 +220,8 @@ static int property_get_cpu_sched_priority(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
ExecContext *c = userdata;
int32_t n;
@@ -250,8 +250,8 @@ static int property_get_cpu_affinity(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
ExecContext *c = userdata;
@@ -271,8 +271,8 @@ static int property_get_timer_slack_nsec(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
ExecContext *c = userdata;
uint64_t u;
@@ -295,8 +295,8 @@ static int property_get_capability_bounding_set(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
ExecContext *c = userdata;
@@ -315,8 +315,8 @@ static int property_get_capabilities(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
ExecContext *c = userdata;
char *t = NULL;
@@ -349,8 +349,8 @@ static int property_get_syscall_filter(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
ExecContext *c = userdata;
@@ -434,8 +434,8 @@ int bus_property_get_exec_command(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *ret_error) {
ExecCommand *c = *(ExecCommand**) userdata;
int r;
diff --git a/src/core/dbus-execute.h b/src/core/dbus-execute.h
index 957742beee..1574c309de 100644
--- a/src/core/dbus-execute.h
+++ b/src/core/dbus-execute.h
@@ -36,5 +36,5 @@
extern const sd_bus_vtable bus_exec_vtable[];
-int bus_property_get_exec_output(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata);
-int bus_property_get_exec_command(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata);
+int bus_property_get_exec_output(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *ret_error);
+int bus_property_get_exec_command(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *ret_error);
diff --git a/src/core/dbus-job.c b/src/core/dbus-job.c
index bdb9096e42..923d545a02 100644
--- a/src/core/dbus-job.c
+++ b/src/core/dbus-job.c
@@ -35,8 +35,8 @@ static int property_get_unit(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
Job *j = userdata;
@@ -52,14 +52,18 @@ static int property_get_unit(
return sd_bus_message_append(reply, "(so)", j->unit->id, p);
}
-static int method_cancel(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_cancel(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Job *j = userdata;
+ int r;
assert(bus);
assert(message);
assert(j);
- SELINUX_UNIT_ACCESS_CHECK(j->unit, bus, message, "stop");
+ r = selinux_unit_access_check(j->unit, bus, message, "stop", error);
+ if (r < 0)
+ return r;
+
job_finish_and_invalidate(j, JOB_CANCELED, true);
return sd_bus_reply_method_return(message, NULL);
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 12b24c123b..d7936fff20 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -46,8 +46,8 @@ static int property_get_version(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
assert(bus);
assert(reply);
@@ -61,8 +61,8 @@ static int property_get_features(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
assert(bus);
assert(reply);
@@ -76,8 +76,8 @@ static int property_get_virtualization(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
const char *id = NULL;
@@ -95,10 +95,10 @@ static int property_get_tainted(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
- char buf[LINE_MAX] = "", *e = buf;
+ char buf[sizeof("split-usr:mtab-not-symlink:cgroups-missing:local-hwclock:")] = "", *e = buf;
_cleanup_free_ char *p = NULL;
Manager *m = userdata;
@@ -131,8 +131,8 @@ static int property_get_log_target(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
assert(bus);
assert(reply);
@@ -146,8 +146,8 @@ static int property_set_log_target(
const char *interface,
const char *property,
sd_bus_message *value,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
const char *t;
int r;
@@ -168,8 +168,8 @@ static int property_get_log_level(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
_cleanup_free_ char *t = NULL;
int r;
@@ -190,8 +190,8 @@ static int property_set_log_level(
const char *interface,
const char *property,
sd_bus_message *value,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
const char *t;
int r;
@@ -212,8 +212,8 @@ static int property_get_n_names(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Manager *m = userdata;
@@ -230,8 +230,8 @@ static int property_get_n_jobs(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Manager *m = userdata;
@@ -248,8 +248,8 @@ static int property_get_progress(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Manager *m = userdata;
double d;
@@ -272,8 +272,8 @@ static int property_set_runtime_watchdog(
const char *interface,
const char *property,
sd_bus_message *value,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
usec_t *t = userdata;
int r;
@@ -290,7 +290,7 @@ static int property_set_runtime_watchdog(
return watchdog_set_timeout(t);
}
-static int method_get_unit(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_get_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *path = NULL;
Manager *m = userdata;
const char *name;
@@ -303,22 +303,24 @@ static int method_get_unit(sd_bus *bus, sd_bus_message *message, void *userdata)
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
u = manager_get_unit(m, name);
if (!u)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", name);
- SELINUX_UNIT_ACCESS_CHECK(u, bus, message, "status");
+ r = selinux_unit_access_check(u, bus, message, "status", error);
+ if (r < 0)
+ return r;
path = unit_dbus_path(u);
if (!path)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
return sd_bus_reply_method_return(message, "o", path);
}
-static int method_get_unit_by_pid(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_get_unit_by_pid(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *path = NULL;
Manager *m = userdata;
pid_t pid;
@@ -333,29 +335,30 @@ static int method_get_unit_by_pid(sd_bus *bus, sd_bus_message *message, void *us
r = sd_bus_message_read(message, "u", &pid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (pid == 0) {
r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
}
u = manager_get_unit_by_pid(m, pid);
if (!u)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_UNIT_FOR_PID, "PID %u does not belong to any loaded unit.", pid);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_UNIT_FOR_PID, "PID %u does not belong to any loaded unit.", pid);
- SELINUX_UNIT_ACCESS_CHECK(u, bus, message, "status");
+ r = selinux_unit_access_check(u, bus, message, "status", error);
+ if (r < 0)
+ return r;
path = unit_dbus_path(u);
if (!path)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
return sd_bus_reply_method_return(message, "o", path);
}
-static int method_load_unit(sd_bus *bus, sd_bus_message *message, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_load_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *path = NULL;
Manager *m = userdata;
const char *name;
@@ -368,23 +371,24 @@ static int method_load_unit(sd_bus *bus, sd_bus_message *message, void *userdata
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
- r = manager_load_unit(m, name, NULL, &error, &u);
+ r = manager_load_unit(m, name, NULL, error, &u);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
- SELINUX_UNIT_ACCESS_CHECK(u, bus, message, "status");
+ r = selinux_unit_access_check(u, bus, message, "status", error);
+ if (r < 0)
+ return r;
path = unit_dbus_path(u);
if (!path)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
return sd_bus_reply_method_return(message, "o", path);
}
-static int method_start_unit_generic(sd_bus *bus, sd_bus_message *message, Manager *m, JobType job_type, bool reload_if_possible) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_start_unit_generic(sd_bus *bus, sd_bus_message *message, Manager *m, JobType job_type, bool reload_if_possible, sd_bus_error *error) {
const char *name;
Unit *u;
int r;
@@ -395,44 +399,44 @@ static int method_start_unit_generic(sd_bus *bus, sd_bus_message *message, Manag
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
- r = manager_load_unit(m, name, NULL, &error, &u);
+ r = manager_load_unit(m, name, NULL, error, &u);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
- return bus_unit_method_start_generic(bus, message, u, job_type, reload_if_possible);
+ return bus_unit_method_start_generic(bus, message, u, job_type, reload_if_possible, error);
}
-static int method_start_unit(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return method_start_unit_generic(bus, message, userdata, JOB_START, false);
+static int method_start_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return method_start_unit_generic(bus, message, userdata, JOB_START, false, error);
}
-static int method_stop_unit(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return method_start_unit_generic(bus, message, userdata, JOB_STOP, false);
+static int method_stop_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return method_start_unit_generic(bus, message, userdata, JOB_STOP, false, error);
}
-static int method_reload_unit(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return method_start_unit_generic(bus, message, userdata, JOB_RELOAD, false);
+static int method_reload_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return method_start_unit_generic(bus, message, userdata, JOB_RELOAD, false, error);
}
-static int method_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return method_start_unit_generic(bus, message, userdata, JOB_RESTART, false);
+static int method_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return method_start_unit_generic(bus, message, userdata, JOB_RESTART, false, error);
}
-static int method_try_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return method_start_unit_generic(bus, message, userdata, JOB_TRY_RESTART, false);
+static int method_try_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return method_start_unit_generic(bus, message, userdata, JOB_TRY_RESTART, false, error);
}
-static int method_reload_or_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return method_start_unit_generic(bus, message, userdata, JOB_RESTART, true);
+static int method_reload_or_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return method_start_unit_generic(bus, message, userdata, JOB_RESTART, true, error);
}
-static int method_reload_or_try_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return method_start_unit_generic(bus, message, userdata, JOB_TRY_RESTART, true);
+static int method_reload_or_try_restart_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return method_start_unit_generic(bus, message, userdata, JOB_TRY_RESTART, true, error);
}
-static int method_start_unit_replace(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_start_unit_replace(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
const char *old_name;
Unit *u;
@@ -444,16 +448,16 @@ static int method_start_unit_replace(sd_bus *bus, sd_bus_message *message, void
r = sd_bus_message_read(message, "s", &old_name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
u = manager_get_unit(m, old_name);
if (!u || !u->job || u->job->type != JOB_START)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name);
- return method_start_unit_generic(bus, message, m, JOB_START, false);
+ return method_start_unit_generic(bus, message, m, JOB_START, false, error);
}
-static int method_kill_unit(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_kill_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
const char *name;
Unit *u;
@@ -465,16 +469,16 @@ static int method_kill_unit(sd_bus *bus, sd_bus_message *message, void *userdata
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
u = manager_get_unit(m, name);
if (!u)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
- return bus_unit_method_kill(bus, message, u);
+ return bus_unit_method_kill(bus, message, u, error);
}
-static int method_reset_failed_unit(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_reset_failed_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
const char *name;
Unit *u;
@@ -486,16 +490,16 @@ static int method_reset_failed_unit(sd_bus *bus, sd_bus_message *message, void *
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
u = manager_get_unit(m, name);
if (!u)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
- return bus_unit_method_reset_failed(bus, message, u);
+ return bus_unit_method_reset_failed(bus, message, u, error);
}
-static int method_set_unit_properties(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_set_unit_properties(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
const char *name;
Unit *u;
@@ -507,17 +511,16 @@ static int method_set_unit_properties(sd_bus *bus, sd_bus_message *message, void
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
u = manager_get_unit(m, name);
if (!u)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
- return bus_unit_method_set_properties(bus, message, u);
+ return bus_unit_method_set_properties(bus, message, u, error);
}
-static int method_start_transient_unit(sd_bus *bus, sd_bus_message *message, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_start_transient_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *name, *smode;
Manager *m = userdata;
JobMode mode;
@@ -531,51 +534,53 @@ static int method_start_transient_unit(sd_bus *bus, sd_bus_message *message, voi
r = sd_bus_message_read(message, "ss", &name, &smode);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
t = unit_name_to_type(name);
if (t < 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid unit type.");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid unit type.");
if (!unit_vtable[t]->can_transient)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Unit type %s does not support transient units.");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit type %s does not support transient units.");
mode = job_mode_from_string(smode);
if (mode < 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s is invalid.", smode);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s is invalid.", smode);
- r = manager_load_unit(m, name, NULL, &error, &u);
+ r = manager_load_unit(m, name, NULL, error, &u);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
- SELINUX_UNIT_ACCESS_CHECK(u, bus, message, "start");
+ r = selinux_unit_access_check(u, bus, message, "start", error);
+ if (r < 0)
+ return r;
if (u->load_state != UNIT_NOT_FOUND || set_size(u->dependencies[UNIT_REFERENCED_BY]) > 0)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_UNIT_EXISTS, "Unit %s already exists.", name);
+ return sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, "Unit %s already exists.", name);
/* OK, the unit failed to load and is unreferenced, now let's
* fill in the transient data instead */
r = unit_make_transient(u);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
/* Set our properties */
- r = bus_unit_set_properties(u, message, UNIT_RUNTIME, false, &error);
+ r = bus_unit_set_properties(u, message, UNIT_RUNTIME, false, error);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
/* And load this stub fully */
r = unit_load(u);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
manager_dispatch_load_queue(m);
/* Finally, start it */
- return bus_unit_queue_job(bus, message, u, JOB_START, mode, false);
+ return bus_unit_queue_job(bus, message, u, JOB_START, mode, false, error);
}
-static int method_get_job(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_get_job(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *path = NULL;
Manager *m = userdata;
uint32_t id;
@@ -588,22 +593,24 @@ static int method_get_job(sd_bus *bus, sd_bus_message *message, void *userdata)
r = sd_bus_message_read(message, "u", &id);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
j = manager_get_job(m, id);
if (!j)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
- SELINUX_UNIT_ACCESS_CHECK(j->unit, bus, message, "status");
+ r = selinux_unit_access_check(j->unit, bus, message, "status", error);
+ if (r < 0)
+ return r;
path = job_dbus_path(j);
if (!path)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
return sd_bus_reply_method_return(message, "o", path);
}
-static int method_cancel_job(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_cancel_job(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
uint32_t id;
Job *j;
@@ -615,46 +622,56 @@ static int method_cancel_job(sd_bus *bus, sd_bus_message *message, void *userdat
r = sd_bus_message_read(message, "u", &id);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
j = manager_get_job(m, id);
if (!j)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
- SELINUX_UNIT_ACCESS_CHECK(j->unit, bus, message, "stop");
+ r = selinux_unit_access_check(j->unit, bus, message, "stop", error);
+ if (r < 0)
+ return r;
job_finish_and_invalidate(j, JOB_CANCELED, true);
return sd_bus_reply_method_return(message, NULL);
}
-static int method_clear_jobs(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_clear_jobs(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
+ int r;
assert(bus);
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "reboot");
+ r = selinux_access_check(bus, message, "reboot", error);
+ if (r < 0)
+ return r;
+
manager_clear_jobs(m);
return sd_bus_reply_method_return(message, NULL);
}
-static int method_reset_failed(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_reset_failed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
+ int r;
assert(bus);
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "reload");
+ r = selinux_access_check(bus, message, "reload", error);
+ if (r < 0)
+ return r;
+
manager_reset_failed(m);
return sd_bus_reply_method_return(message, NULL);
}
-static int method_list_units(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_list_units(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
Manager *m = userdata;
const char *k;
@@ -666,15 +683,17 @@ static int method_list_units(sd_bus *bus, sd_bus_message *message, void *userdat
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "status");
+ r = selinux_access_check(bus, message, "status", error);
+ if (r < 0)
+ return r;
r = sd_bus_message_new_method_return(message, &reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)");
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
HASHMAP_FOREACH_KEY(u, k, m->units, i) {
_cleanup_free_ char *unit_path = NULL, *job_path = NULL;
@@ -687,12 +706,12 @@ static int method_list_units(sd_bus *bus, sd_bus_message *message, void *userdat
unit_path = unit_dbus_path(u);
if (!unit_path)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
if (u->job) {
job_path = job_dbus_path(u->job);
if (!job_path)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
}
r = sd_bus_message_append(
@@ -708,17 +727,17 @@ static int method_list_units(sd_bus *bus, sd_bus_message *message, void *userdat
u->job ? job_type_to_string(u->job->type) : "",
job_path ? job_path : "/");
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
}
r = sd_bus_message_close_container(reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_send(bus, reply, NULL);
}
-static int method_list_jobs(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_list_jobs(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
Manager *m = userdata;
Iterator i;
@@ -729,26 +748,28 @@ static int method_list_jobs(sd_bus *bus, sd_bus_message *message, void *userdata
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "status");
+ r = selinux_access_check(bus, message, "status", error);
+ if (r < 0)
+ return r;
r = sd_bus_message_new_method_return(message, &reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = sd_bus_message_open_container(reply, 'a', "(usssoo)");
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
HASHMAP_FOREACH(j, m->jobs, i) {
_cleanup_free_ char *unit_path = NULL, *job_path = NULL;
job_path = job_dbus_path(j);
if (!job_path)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
unit_path = unit_dbus_path(j->unit);
if (!unit_path)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
r = sd_bus_message_append(
reply, "(usssoo)",
@@ -758,17 +779,17 @@ static int method_list_jobs(sd_bus *bus, sd_bus_message *message, void *userdata
job_path,
unit_path);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
}
r = sd_bus_message_close_container(reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_send(bus, reply, NULL);
}
-static int method_subscribe(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_subscribe(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
int r;
@@ -776,18 +797,20 @@ static int method_subscribe(sd_bus *bus, sd_bus_message *message, void *userdata
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "status");
+ r = selinux_access_check(bus, message, "status", error);
+ if (r < 0)
+ return r;
r = bus_client_track(&m->subscribed, bus, sd_bus_message_get_sender(message));
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (r == 0)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_ALREADY_SUBSCRIBED, "Client is already subscribed.");
+ return sd_bus_error_setf(error, BUS_ERROR_ALREADY_SUBSCRIBED, "Client is already subscribed.");
return sd_bus_reply_method_return(message, NULL);
}
-static int method_unsubscribe(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_unsubscribe(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
int r;
@@ -795,32 +818,37 @@ static int method_unsubscribe(sd_bus *bus, sd_bus_message *message, void *userda
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "status");
+ r = selinux_access_check(bus, message, "status", error);
+ if (r < 0)
+ return r;
r = bus_client_untrack(m->subscribed, bus, sd_bus_message_get_sender(message));
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (r == 0)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
+ return sd_bus_error_setf(error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
return sd_bus_reply_method_return(message, NULL);
}
-static int method_dump(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_dump(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *dump = NULL;
_cleanup_fclose_ FILE *f = NULL;
Manager *m = userdata;
size_t size;
+ int r;
assert(bus);
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "status");
+ r = selinux_access_check(bus, message, "status", error);
+ if (r < 0)
+ return r;
f = open_memstream(&dump, &size);
if (!f)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
manager_dump_units(m, f, NULL);
manager_dump_jobs(m, f, NULL);
@@ -828,13 +856,12 @@ static int method_dump(sd_bus *bus, sd_bus_message *message, void *userdata) {
fflush(f);
if (ferror(f))
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
return sd_bus_reply_method_return(message, "s", dump);
}
-static int method_create_snapshot(sd_bus *bus, sd_bus_message *message, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_create_snapshot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *path = NULL;
Manager *m = userdata;
const char *name;
@@ -846,27 +873,29 @@ static int method_create_snapshot(sd_bus *bus, sd_bus_message *message, void *us
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "start");
+ r = selinux_access_check(bus, message, "start", error);
+ if (r < 0)
+ return r;
r = sd_bus_message_read(message, "sb", &name, &cleanup);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (isempty(name))
name = NULL;
- r = snapshot_create(m, name, cleanup, &error, &s);
+ r = snapshot_create(m, name, cleanup, error, &s);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
path = unit_dbus_path(UNIT(s));
if (!path)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
return sd_bus_reply_method_return(message, "o", path);
}
-static int method_remove_snapshot(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_remove_snapshot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
const char *name;
Unit *u;
@@ -876,23 +905,25 @@ static int method_remove_snapshot(sd_bus *bus, sd_bus_message *message, void *us
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "start");
+ r = selinux_access_check(bus, message, "stop", error);
+ if (r < 0)
+ return r;
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
u = manager_get_unit(m, name);
if (!u)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_UNIT, "Unit %s does not exist.", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s does not exist.", name);
if (u->type != UNIT_SNAPSHOT)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not a snapshot", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not a snapshot", name);
- return bus_snapshot_method_remove(bus, message, u);
+ return bus_snapshot_method_remove(bus, message, u, error);
}
-static int method_reload(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_reload(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
int r;
@@ -900,7 +931,9 @@ static int method_reload(sd_bus *bus, sd_bus_message *message, void *userdata) {
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "reload");
+ r = selinux_access_check(bus, message, "reload", error);
+ if (r < 0)
+ return r;
/* Instead of sending the reply back right away, we just
* remember that we need to and then send it after the reload
@@ -910,7 +943,7 @@ static int method_reload(sd_bus *bus, sd_bus_message *message, void *userdata) {
assert(!m->queued_message);
r = sd_bus_message_new_method_return(message, &m->queued_message);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
m->queued_message_bus = sd_bus_ref(bus);
m->exit_code = MANAGER_RELOAD;
@@ -918,14 +951,17 @@ static int method_reload(sd_bus *bus, sd_bus_message *message, void *userdata) {
return 1;
}
-static int method_reexecute(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_reexecute(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
+ int r;
assert(bus);
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "reload");
+ r = selinux_access_check(bus, message, "reload", error);
+ if (r < 0)
+ return r;
/* We don't send a reply back here, the client should
* just wait for us disconnecting. */
@@ -934,34 +970,40 @@ static int method_reexecute(sd_bus *bus, sd_bus_message *message, void *userdata
return 1;
}
-static int method_exit(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_exit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
+ int r;
assert(bus);
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "halt");
+ r = selinux_access_check(bus, message, "halt", error);
+ if (r < 0)
+ return r;
if (m->running_as == SYSTEMD_SYSTEM)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for user service managers.");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for user service managers.");
m->exit_code = MANAGER_EXIT;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_reboot(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_reboot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
+ int r;
assert(bus);
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "reboot");
+ r = selinux_access_check(bus, message, "reboot", error);
+ if (r < 0)
+ return r;
if (m->running_as != SYSTEMD_SYSTEM)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers.");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers.");
m->exit_code = MANAGER_REBOOT;
@@ -969,58 +1011,67 @@ static int method_reboot(sd_bus *bus, sd_bus_message *message, void *userdata) {
}
-static int method_poweroff(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_poweroff(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
+ int r;
assert(bus);
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "halt");
+ r = selinux_access_check(bus, message, "halt", error);
+ if (r < 0)
+ return r;
if (m->running_as != SYSTEMD_SYSTEM)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
m->exit_code = MANAGER_POWEROFF;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_halt(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_halt(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
+ int r;
assert(bus);
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "halt");
+ r = selinux_access_check(bus, message, "halt", error);
+ if (r < 0)
+ return r;
if (m->running_as != SYSTEMD_SYSTEM)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_NOT_SUPPORTED, "Halt is only supported for system managers.");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Halt is only supported for system managers.");
m->exit_code = MANAGER_HALT;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_kexec(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_kexec(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
+ int r;
assert(bus);
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "reboot");
+ r = selinux_access_check(bus, message, "reboot", error);
+ if (r < 0)
+ return r;
if (m->running_as != SYSTEMD_SYSTEM)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers.");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers.");
m->exit_code = MANAGER_KEXEC;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_switch_root(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_switch_root(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
char *ri = NULL, *rt = NULL;
const char *root, *init;
Manager *m = userdata;
@@ -1030,45 +1081,47 @@ static int method_switch_root(sd_bus *bus, sd_bus_message *message, void *userda
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "reboot");
+ r = selinux_access_check(bus, message, "reboot", error);
+ if (r < 0)
+ return r;
if (m->running_as != SYSTEMD_SYSTEM)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers.");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers.");
r = sd_bus_message_read(message, "ss", &root, &init);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (path_equal(root, "/") || !path_is_absolute(root))
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid switch root path %s", root);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid switch root path %s", root);
/* Safety check */
if (isempty(init)) {
if (! path_is_os_tree(root))
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Specified switch root path %s does not seem to be an OS tree. /etc/os-release is missing.", root);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified switch root path %s does not seem to be an OS tree. /etc/os-release is missing.", root);
} else {
_cleanup_free_ char *p = NULL;
if (!path_is_absolute(init))
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid init path %s", init);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid init path %s", init);
p = strappend(root, init);
if (!p)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
if (access(p, X_OK) < 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Specified init binary %s does not exist.", p);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified init binary %s does not exist.", p);
}
rt = strdup(root);
if (!rt)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
if (!isempty(init)) {
ri = strdup(init);
if (!ri) {
free(ri);
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
}
}
@@ -1081,7 +1134,7 @@ static int method_switch_root(sd_bus *bus, sd_bus_message *message, void *userda
return sd_bus_reply_method_return(message, NULL);
}
-static int method_set_environment(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_set_environment(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_strv_free_ char **plus = NULL;
Manager *m = userdata;
int r;
@@ -1090,22 +1143,24 @@ static int method_set_environment(sd_bus *bus, sd_bus_message *message, void *us
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "reload");
+ r = selinux_access_check(bus, message, "reload", error);
+ if (r < 0)
+ return r;
r = sd_bus_message_read_strv(message, &plus);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (!strv_env_is_valid(plus))
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments");
r = manager_environment_add(m, NULL, plus);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_unset_environment(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_unset_environment(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_strv_free_ char **minus = NULL;
Manager *m = userdata;
int r;
@@ -1114,23 +1169,25 @@ static int method_unset_environment(sd_bus *bus, sd_bus_message *message, void *
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "reload");
+ r = selinux_access_check(bus, message, "reload", error);
+ if (r < 0)
+ return r;
r = sd_bus_message_read_strv(message, &minus);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (!strv_env_name_or_assignment_is_valid(minus))
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments");
r = manager_environment_add(m, minus, NULL);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_unset_and_set_environment(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_unset_and_set_environment(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_strv_free_ char **minus = NULL, **plus = NULL;
Manager *m = userdata;
int r;
@@ -1139,29 +1196,31 @@ static int method_unset_and_set_environment(sd_bus *bus, sd_bus_message *message
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "reload");
+ r = selinux_access_check(bus, message, "reload", error);
+ if (r < 0)
+ return r;
r = sd_bus_message_read_strv(message, &plus);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = sd_bus_message_read_strv(message, &minus);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (!strv_env_is_valid(plus))
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments");
if (!strv_env_name_or_assignment_is_valid(minus))
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment variable names or assignments");
r = manager_environment_add(m, minus, plus);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_list_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_list_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
Manager *m = userdata;
UnitFileList *item;
@@ -1173,42 +1232,38 @@ static int method_list_unit_files(sd_bus *bus, sd_bus_message *message, void *us
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "status");
+ r = selinux_access_check(bus, message, "status", error);
+ if (r < 0)
+ return r;
r = sd_bus_message_new_method_return(message, &reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
h = hashmap_new(string_hash_func, string_compare_func);
if (!h)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
r = unit_file_get_list(m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, h);
- if (r < 0) {
- r = sd_bus_reply_method_errno(message, r, NULL);
+ if (r < 0)
goto fail;
- }
r = sd_bus_message_open_container(reply, 'a', "(ss)");
- if (r < 0) {
- r = sd_bus_reply_method_errno(message, r, NULL);
+ if (r < 0)
goto fail;
- }
HASHMAP_FOREACH(item, h, i) {
r = sd_bus_message_append(reply, "(ss)", item->path, unit_file_state_to_string(item->state));
- if (r < 0) {
- r = sd_bus_reply_method_errno(message, r, NULL);
+ if (r < 0)
goto fail;
- }
}
unit_file_list_free(h);
r = sd_bus_message_close_container(reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_send(bus, reply, NULL);
@@ -1217,7 +1272,7 @@ fail:
return r;
}
-static int method_get_unit_file_state(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_get_unit_file_state(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
const char *name;
UnitFileState state;
@@ -1228,22 +1283,24 @@ static int method_get_unit_file_state(sd_bus *bus, sd_bus_message *message, void
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "status");
+ r = selinux_access_check(bus, message, "status", error);
+ if (r < 0)
+ return r;
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
state = unit_file_get_state(scope, NULL, name);
if (state < 0)
- return sd_bus_reply_method_errno(message, state, NULL);
+ return state;
return sd_bus_reply_method_return(message, "s", unit_file_state_to_string(state));
}
-static int method_get_default_target(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_get_default_target(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *default_target = NULL;
Manager *m = userdata;
UnitFileScope scope;
@@ -1253,13 +1310,15 @@ static int method_get_default_target(sd_bus *bus, sd_bus_message *message, void
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "status");
+ r = selinux_access_check(bus, message, "status", error);
+ if (r < 0)
+ return r;
scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
r = unit_file_get_default(scope, NULL, &default_target);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, "s", default_target);
}
@@ -1324,7 +1383,7 @@ static int reply_unit_file_changes_and_free(
fail:
unit_file_changes_free(changes, n_changes);
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
}
static int method_enable_unit_files_generic(
@@ -1333,7 +1392,8 @@ static int method_enable_unit_files_generic(
Manager *m, const
char *verb,
int (*call)(UnitFileScope scope, bool runtime, const char *root_dir, char *files[], bool force, UnitFileChange **changes, unsigned *n_changes),
- bool carries_install_info) {
+ bool carries_install_info,
+ sd_bus_error *error) {
_cleanup_strv_free_ char **l = NULL;
UnitFileChange *changes = NULL;
@@ -1345,43 +1405,45 @@ static int method_enable_unit_files_generic(
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, verb);
+ r = selinux_access_check(bus, message, verb, error);
+ if (r < 0)
+ return r;
r = sd_bus_message_read_strv(message, &l);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = sd_bus_message_read(message, "bb", &runtime, &force);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
r = call(scope, runtime, NULL, l, force, &changes, &n_changes);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return reply_unit_file_changes_and_free(m, bus, message, carries_install_info ? r : -1, changes, n_changes);
}
-static int method_enable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_enable, true);
+static int method_enable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_enable, true, error);
}
-static int method_reenable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_reenable, true);
+static int method_reenable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_reenable, true, error);
}
-static int method_link_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_link, false);
+static int method_link_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_link, false, error);
}
-static int method_preset_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_preset, true);
+static int method_preset_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return method_enable_unit_files_generic(bus, message, userdata, "enable", unit_file_preset, true, error);
}
-static int method_mask_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return method_enable_unit_files_generic(bus, message, userdata, "disable", unit_file_mask, false);
+static int method_mask_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return method_enable_unit_files_generic(bus, message, userdata, "disable", unit_file_mask, false, error);
}
static int method_disable_unit_files_generic(
@@ -1389,7 +1451,8 @@ static int method_disable_unit_files_generic(
sd_bus_message *message,
Manager *m, const
char *verb,
- int (*call)(UnitFileScope scope, bool runtime, const char *root_dir, char *files[], UnitFileChange **changes, unsigned *n_changes)) {
+ int (*call)(UnitFileScope scope, bool runtime, const char *root_dir, char *files[], UnitFileChange **changes, unsigned *n_changes),
+ sd_bus_error *error) {
_cleanup_strv_free_ char **l = NULL;
UnitFileChange *changes = NULL;
@@ -1401,34 +1464,36 @@ static int method_disable_unit_files_generic(
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, verb);
+ r = selinux_access_check(bus, message, verb, error);
+ if (r < 0)
+ return r;
r = sd_bus_message_read_strv(message, &l);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = sd_bus_message_read(message, "b", &runtime);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
r = call(scope, runtime, NULL, l, &changes, &n_changes);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return reply_unit_file_changes_and_free(m, bus, message, -1, changes, n_changes);
}
-static int method_disable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return method_disable_unit_files_generic(bus, message, userdata, "disable", unit_file_disable);
+static int method_disable_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return method_disable_unit_files_generic(bus, message, userdata, "disable", unit_file_disable, error);
}
-static int method_unmask_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return method_disable_unit_files_generic(bus, message, userdata, "enable", unit_file_unmask);
+static int method_unmask_unit_files(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return method_disable_unit_files_generic(bus, message, userdata, "enable", unit_file_unmask, error);
}
-static int method_set_default_target(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_set_default_target(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
UnitFileChange *changes = NULL;
unsigned n_changes = 0;
Manager *m = userdata;
@@ -1440,17 +1505,19 @@ static int method_set_default_target(sd_bus *bus, sd_bus_message *message, void
assert(message);
assert(m);
- SELINUX_ACCESS_CHECK(bus, message, "enable");
+ r = selinux_access_check(bus, message, "enable", error);
+ if (r < 0)
+ return r;
r = sd_bus_message_read(message, "sb", &name, &force);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
r = unit_file_set_default(scope, NULL, name, force, &changes, &n_changes);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return reply_unit_file_changes_and_free(m, bus, message, -1, changes, n_changes);
}
diff --git a/src/core/dbus-mount.c b/src/core/dbus-mount.c
index 2056eab11e..eb3c0387cd 100644
--- a/src/core/dbus-mount.c
+++ b/src/core/dbus-mount.c
@@ -34,8 +34,8 @@ static int property_get_what(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Mount *m = userdata;
const char *d;
@@ -60,8 +60,8 @@ static int property_get_options(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Mount *m = userdata;
const char *d;
@@ -86,8 +86,8 @@ static int property_get_type(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Mount *m = userdata;
const char *d;
diff --git a/src/core/dbus-path.c b/src/core/dbus-path.c
index a206f49020..cf1de44d85 100644
--- a/src/core/dbus-path.c
+++ b/src/core/dbus-path.c
@@ -33,8 +33,8 @@ static int property_get_paths(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Path *p = userdata;
PathSpec *k;
@@ -63,8 +63,8 @@ static int property_get_unit(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *p = userdata, *trigger;
diff --git a/src/core/dbus-snapshot.c b/src/core/dbus-snapshot.c
index 1e53fefc66..a54dc8cf89 100644
--- a/src/core/dbus-snapshot.c
+++ b/src/core/dbus-snapshot.c
@@ -25,14 +25,17 @@
#include "dbus-unit.h"
#include "dbus-snapshot.h"
-int bus_snapshot_method_remove(sd_bus *bus, sd_bus_message *message, void *userdata) {
+int bus_snapshot_method_remove(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Snapshot *s = userdata;
+ int r;
assert(bus);
assert(message);
assert(s);
- SELINUX_UNIT_ACCESS_CHECK(UNIT(s), bus, message, "stop");
+ r = selinux_unit_access_check(UNIT(s), bus, message, "stop", error);
+ if (r < 0)
+ return r;
snapshot_remove(s);
diff --git a/src/core/dbus-snapshot.h b/src/core/dbus-snapshot.h
index f6f432240d..d7551cbcdc 100644
--- a/src/core/dbus-snapshot.h
+++ b/src/core/dbus-snapshot.h
@@ -25,4 +25,4 @@
extern const sd_bus_vtable bus_snapshot_vtable[];
-int bus_snapshot_method_remove(sd_bus *bus, sd_bus_message *message, void *userdata);
+int bus_snapshot_method_remove(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
diff --git a/src/core/dbus-socket.c b/src/core/dbus-socket.c
index e9fa24d1a3..19a44849a3 100644
--- a/src/core/dbus-socket.c
+++ b/src/core/dbus-socket.c
@@ -37,8 +37,8 @@ static int property_get_listen(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Socket *s = SOCKET(userdata);
diff --git a/src/core/dbus-swap.c b/src/core/dbus-swap.c
index 15292cd192..09c00b3f90 100644
--- a/src/core/dbus-swap.c
+++ b/src/core/dbus-swap.c
@@ -35,8 +35,8 @@ static int property_get_priority(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Swap *s = SWAP(userdata);
int p;
diff --git a/src/core/dbus-timer.c b/src/core/dbus-timer.c
index 113c63faa0..9e4070a1a3 100644
--- a/src/core/dbus-timer.c
+++ b/src/core/dbus-timer.c
@@ -33,8 +33,8 @@ static int property_get_monotonic_timers(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Timer *t = userdata;
TimerValue *v;
@@ -82,8 +82,8 @@ static int property_get_calendar_timers(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Timer *t = userdata;
TimerValue *v;
@@ -121,8 +121,8 @@ static int property_get_unit(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *u = userdata, *trigger;
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index 759fc4a869..5fca7653e0 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -39,8 +39,8 @@ static int property_get_names(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *u = userdata;
Iterator i;
@@ -70,8 +70,8 @@ static int property_get_following(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *u = userdata, *f;
@@ -89,8 +89,8 @@ static int property_get_dependencies(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Set *s = *(Set**) userdata;
Iterator j;
@@ -119,8 +119,8 @@ static int property_get_description(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *u = userdata;
@@ -137,8 +137,8 @@ static int property_get_active_state(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *u = userdata;
@@ -155,8 +155,8 @@ static int property_get_sub_state(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *u = userdata;
@@ -173,8 +173,8 @@ static int property_get_unit_file_state(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *u = userdata;
@@ -191,8 +191,8 @@ static int property_get_can_start(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *u = userdata;
@@ -209,8 +209,8 @@ static int property_get_can_stop(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *u = userdata;
@@ -230,8 +230,8 @@ static int property_get_can_reload(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *u = userdata;
@@ -248,8 +248,8 @@ static int property_get_can_isolate(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *u = userdata;
@@ -266,8 +266,8 @@ static int property_get_job(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
Unit *u = userdata;
@@ -292,8 +292,8 @@ static int property_get_need_daemon_reload(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *u = userdata;
@@ -310,8 +310,8 @@ static int property_get_conditions(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *u = userdata;
Condition *c;
@@ -341,8 +341,8 @@ static int property_get_load_error(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
_cleanup_bus_error_free_ sd_bus_error e = SD_BUS_ERROR_NULL;
Unit *u = userdata;
@@ -357,7 +357,7 @@ static int property_get_load_error(
return sd_bus_message_append(reply, "(ss)", e.name, e.message);
}
-int bus_unit_method_start_generic(sd_bus *bus, sd_bus_message *message, Unit *u, JobType job_type, bool reload_if_possible) {
+int bus_unit_method_start_generic(sd_bus *bus, sd_bus_message *message, Unit *u, JobType job_type, bool reload_if_possible, sd_bus_error *error) {
const char *smode;
JobMode mode;
int r;
@@ -369,45 +369,44 @@ int bus_unit_method_start_generic(sd_bus *bus, sd_bus_message *message, Unit *u,
r = sd_bus_message_read(message, "s", &smode);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
mode = job_mode_from_string(smode);
if (mode < 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s invalid", smode);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s invalid", smode);
- return bus_unit_queue_job(bus, message, u, job_type, mode, reload_if_possible);
+ return bus_unit_queue_job(bus, message, u, job_type, mode, reload_if_possible, error);
}
-static int method_start(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return bus_unit_method_start_generic(bus, message, userdata, JOB_START, false);
+static int method_start(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return bus_unit_method_start_generic(bus, message, userdata, JOB_START, false, error);
}
-static int method_stop(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return bus_unit_method_start_generic(bus, message, userdata, JOB_STOP, false);
+static int method_stop(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return bus_unit_method_start_generic(bus, message, userdata, JOB_STOP, false, error);
}
-static int method_reload(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return bus_unit_method_start_generic(bus, message, userdata, JOB_RELOAD, false);
+static int method_reload(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return bus_unit_method_start_generic(bus, message, userdata, JOB_RELOAD, false, error);
}
-static int method_restart(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return bus_unit_method_start_generic(bus, message, userdata, JOB_RESTART, false);
+static int method_restart(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return bus_unit_method_start_generic(bus, message, userdata, JOB_RESTART, false, error);
}
-static int method_try_restart(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return bus_unit_method_start_generic(bus, message, userdata, JOB_TRY_RESTART, false);
+static int method_try_restart(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return bus_unit_method_start_generic(bus, message, userdata, JOB_TRY_RESTART, false, error);
}
-static int method_reload_or_restart(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return bus_unit_method_start_generic(bus, message, userdata, JOB_RESTART, true);
+static int method_reload_or_restart(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return bus_unit_method_start_generic(bus, message, userdata, JOB_RESTART, true, error);
}
-static int method_reload_or_try_restart(sd_bus *bus, sd_bus_message *message, void *userdata) {
- return bus_unit_method_start_generic(bus, message, userdata, JOB_TRY_RESTART, true);
+static int method_reload_or_try_restart(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return bus_unit_method_start_generic(bus, message, userdata, JOB_TRY_RESTART, true, error);
}
-int bus_unit_method_kill(sd_bus *bus, sd_bus_message *message, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+int bus_unit_method_kill(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Unit *u = userdata;
const char *swho;
int32_t signo;
@@ -420,44 +419,48 @@ int bus_unit_method_kill(sd_bus *bus, sd_bus_message *message, void *userdata) {
r = sd_bus_message_read(message, "si", &swho, &signo);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (isempty(swho))
who = KILL_ALL;
else {
who = kill_who_from_string(swho);
if (who < 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid who argument %s", swho);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid who argument %s", swho);
}
if (signo <= 0 || signo >= _NSIG)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Signal number out of range.");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Signal number out of range.");
- SELINUX_UNIT_ACCESS_CHECK(u, bus, message, "stop");
+ r = selinux_unit_access_check(u, bus, message, "stop", error);
+ if (r < 0)
+ return r;
- r = unit_kill(u, who, signo, &error);
+ r = unit_kill(u, who, signo, error);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-int bus_unit_method_reset_failed(sd_bus *bus, sd_bus_message *message, void *userdata) {
+int bus_unit_method_reset_failed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Unit *u = userdata;
+ int r;
assert(bus);
assert(message);
assert(u);
- SELINUX_UNIT_ACCESS_CHECK(u, bus, message, "reload");
+ r = selinux_unit_access_check(u, bus, message, "reload", error);
+ if (r < 0)
+ return r;
unit_reset_failed(u);
return sd_bus_reply_method_return(message, NULL);
}
-int bus_unit_method_set_properties(sd_bus *bus, sd_bus_message *message, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+int bus_unit_method_set_properties(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Unit *u = userdata;
int runtime, r;
@@ -467,21 +470,23 @@ int bus_unit_method_set_properties(sd_bus *bus, sd_bus_message *message, void *u
r = sd_bus_message_read(message, "b", &runtime);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
- SELINUX_UNIT_ACCESS_CHECK(u, bus, message, "start");
+ r = selinux_unit_access_check(u, bus, message, "start", error);
+ if (r < 0)
+ return r;
r = sd_bus_message_enter_container(message, 'a', "(sv)");
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
- r = bus_unit_set_properties(u, message, runtime ? UNIT_RUNTIME : UNIT_PERSISTENT, true, &error);
+ r = bus_unit_set_properties(u, message, runtime ? UNIT_RUNTIME : UNIT_PERSISTENT, true, error);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
r = sd_bus_message_exit_container(message);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
@@ -568,8 +573,8 @@ static int property_get_slice(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Unit *u = userdata;
@@ -728,9 +733,9 @@ int bus_unit_queue_job(
Unit *u,
JobType type,
JobMode mode,
- bool reload_if_possible) {
+ bool reload_if_possible,
+ sd_bus_error *error) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_free_ char *path = NULL;
Job *j;
int r;
@@ -748,31 +753,34 @@ int bus_unit_queue_job(
type = JOB_RELOAD;
}
- SELINUX_UNIT_ACCESS_CHECK(u, bus, message,
- (type == JOB_START || type == JOB_RESTART || type == JOB_TRY_RESTART) ? "start" :
- type == JOB_STOP ? "stop" : "reload");
+ r = selinux_unit_access_check(
+ u, bus, message,
+ (type == JOB_START || type == JOB_RESTART || type == JOB_TRY_RESTART) ? "start" :
+ type == JOB_STOP ? "stop" : "reload", error);
+ if (r < 0)
+ return r;
if (type == JOB_STOP &&
(u->load_state == UNIT_NOT_FOUND || u->load_state == UNIT_ERROR) &&
unit_active_state(u) == UNIT_INACTIVE)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", u->id);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", u->id);
if ((type == JOB_START && u->refuse_manual_start) ||
(type == JOB_STOP && u->refuse_manual_stop) ||
((type == JOB_RESTART || type == JOB_TRY_RESTART) && (u->refuse_manual_start || u->refuse_manual_stop)))
- return sd_bus_reply_method_errorf(message, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, unit %s may be requested by dependency only.", u->id);
+ return sd_bus_error_setf(error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, unit %s may be requested by dependency only.", u->id);
- r = manager_add_job(u->manager, type, u, mode, true, &error, &j);
+ r = manager_add_job(u->manager, type, u, mode, true, error, &j);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
r = bus_client_track(&j->subscribed, bus, sd_bus_message_get_sender(message));
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
path = job_dbus_path(j);
if (!path)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, "o", path);
}
diff --git a/src/core/dbus-unit.h b/src/core/dbus-unit.h
index 859de102b6..57a5e19744 100644
--- a/src/core/dbus-unit.h
+++ b/src/core/dbus-unit.h
@@ -30,10 +30,10 @@ extern const sd_bus_vtable bus_unit_cgroup_vtable[];
void bus_unit_send_change_signal(Unit *u);
void bus_unit_send_removed_signal(Unit *u);
-int bus_unit_method_start_generic(sd_bus *bus, sd_bus_message *message, Unit *u, JobType job_type, bool reload_if_possible);
-int bus_unit_method_kill(sd_bus *bus, sd_bus_message *message, void *userdata);
-int bus_unit_method_reset_failed(sd_bus *bus, sd_bus_message *message, void *userdata);
+int bus_unit_method_start_generic(sd_bus *bus, sd_bus_message *message, Unit *u, JobType job_type, bool reload_if_possible, sd_bus_error *error);
+int bus_unit_method_kill(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
+int bus_unit_method_reset_failed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
-int bus_unit_queue_job(sd_bus *bus, sd_bus_message *message, Unit *u, JobType type, JobMode mode, bool reload_if_possible);
+int bus_unit_queue_job(sd_bus *bus, sd_bus_message *message, Unit *u, JobType type, JobMode mode, bool reload_if_possible, sd_bus_error *error);
int bus_unit_set_properties(Unit *u, sd_bus_message *message, UnitSetPropertiesMode mode, bool commit, sd_bus_error *error);
-int bus_unit_method_set_properties(sd_bus *bus, sd_bus_message *message, void *userdata);
+int bus_unit_method_set_properties(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
diff --git a/src/core/dbus.c b/src/core/dbus.c
index b6124b3b22..3d8da1e6ad 100644
--- a/src/core/dbus.c
+++ b/src/core/dbus.c
@@ -71,7 +71,7 @@ int bus_send_queued_message(Manager *m) {
return 0;
}
-static int signal_agent_released(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int signal_agent_released(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
const char *cgroup;
int r;
@@ -100,7 +100,7 @@ static int signal_agent_released(sd_bus *bus, sd_bus_message *message, void *use
return 0;
}
-static int signal_disconnected(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int signal_disconnected(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
assert(bus);
@@ -119,7 +119,7 @@ static int signal_disconnected(sd_bus *bus, sd_bus_message *message, void *userd
return 0;
}
-static int signal_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int signal_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *name, *old_owner, *new_owner;
Manager *m = userdata;
int r;
@@ -142,7 +142,7 @@ static int signal_name_owner_changed(sd_bus *bus, sd_bus_message *message, void
return 0;
}
-static int signal_activation_request(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int signal_activation_request(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *ret_error) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
Manager *m = userdata;
diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c
index 282cfd21ee..cca3df652a 100644
--- a/src/core/selinux-access.c
+++ b/src/core/selinux-access.c
@@ -314,7 +314,7 @@ static int get_calling_context(
If the machine is in permissive mode it will return ok. Audit messages will
still be generated if the access would be denied in enforcing mode.
*/
-int selinux_access_check(
+int selinux_generic_access_check(
sd_bus *bus,
sd_bus_message *message,
const char *path,
@@ -391,7 +391,7 @@ finish:
#else
-int selinux_access_check(
+int selinux_generic_access_check(
sd_bus *bus,
sd_bus_message *message,
const char *path,
diff --git a/src/core/selinux-access.h b/src/core/selinux-access.h
index 3404f62166..9e89064819 100644
--- a/src/core/selinux-access.h
+++ b/src/core/selinux-access.h
@@ -27,36 +27,18 @@
void selinux_access_free(void);
-int selinux_access_check(sd_bus *bus, sd_bus_message *message, const char *path, const char *permission, sd_bus_error *error);
+int selinux_generic_access_check(sd_bus *bus, sd_bus_message *message, const char *path, const char *permission, sd_bus_error *error);
#ifdef HAVE_SELINUX
-#define SELINUX_ACCESS_CHECK(bus, message, permission) \
- do { \
- _cleanup_bus_error_free_ sd_bus_error _error = SD_BUS_ERROR_NULL; \
- sd_bus_message *_m = (message); \
- sd_bus *_b = (bus); \
- int _r; \
- _r = selinux_access_check(_b, _m, NULL, (permission), &_error); \
- if (_r < 0) \
- return sd_bus_reply_method_errno(_m, _r, &_error); \
- } while (false)
-
-#define SELINUX_UNIT_ACCESS_CHECK(unit, bus, message, permission) \
- do { \
- _cleanup_bus_error_free_ sd_bus_error _error = SD_BUS_ERROR_NULL; \
- sd_bus_message *_m = (message); \
- sd_bus *_b = (bus); \
- Unit *_u = (unit); \
- int _r; \
- _r = selinux_access_check(_b, _m, _u->source_path ?: _u->fragment_path, (permission), &_error); \
- if (_r < 0) \
- return sd_bus_reply_method_errno(_m, _r, &_error); \
- } while (false)
+#define selinux_access_check(bus, message, permission, error) \
+ selinux_generic_access_check(bus, message, NULL, permission, error)
+#define selinux_unit_access_check(unit, bus, message, permission, error) \
+ ({ Unit *_unit = (unit); selinux_generic_access_check(bus, message, _unit->fragment_path ?: _unit->fragment_path, permission, error); })
#else
-#define SELINUX_ACCESS_CHECK(bus, message, permission) do { } while (false)
-#define SELINUX_UNIT_ACCESS_CHECK(unit, bus, message, permission) do { } while (false)
+#define selinux_access_check(bus, message, permission, error) 0
+#define selinux_unit_access_check(unit, bus, message, permission, error) 0
#endif
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index c874ea2f6c..e98bd42f2d 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -315,13 +315,12 @@ static int property_get_icon_name(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
_cleanup_free_ char *n = NULL;
Context *c = userdata;
const char *name;
- int r;
if (isempty(c->data[PROP_ICON_NAME]))
name = n = context_fallback_icon_name(c);
@@ -331,11 +330,7 @@ static int property_get_icon_name(
if (!name)
return -ENOMEM;
- r = sd_bus_message_append(reply, "s", name);
- if (r < 0)
- return r;
-
- return 1;
+ return sd_bus_message_append(reply, "s", name);
}
static int property_get_chassis(
@@ -344,27 +339,21 @@ static int property_get_chassis(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Context *c = userdata;
const char *name;
- int r;
if (isempty(c->data[PROP_CHASSIS]))
name = fallback_chassis();
else
name = c->data[PROP_CHASSIS];
- r = sd_bus_message_append(reply, "s", name);
- if (r < 0)
- return r;
-
- return 1;
+ return sd_bus_message_append(reply, "s", name);
}
-static int method_set_hostname(sd_bus *bus, sd_bus_message *m, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_set_hostname(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
Context *c = userdata;
const char *name;
int interactive;
@@ -373,7 +362,7 @@ static int method_set_hostname(sd_bus *bus, sd_bus_message *m, void *userdata) {
r = sd_bus_message_read(m, "sb", &name, &interactive);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, NULL);
+ return r;
if (isempty(name))
name = c->data[PROP_STATIC_HOSTNAME];
@@ -382,20 +371,20 @@ static int method_set_hostname(sd_bus *bus, sd_bus_message *m, void *userdata) {
name = "localhost";
if (!hostname_is_valid(name))
- return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Invalid hostname '%s'", name);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid hostname '%s'", name);
if (streq_ptr(name, c->data[PROP_HOSTNAME]))
return sd_bus_reply_method_return(m, NULL);
- r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.hostname1.set-hostname", interactive, &error, method_set_hostname, c);
+ r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.hostname1.set-hostname", interactive, error, method_set_hostname, c);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, &error);
+ return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
h = strdup(name);
if (!h)
- return log_oom();
+ return -ENOMEM;
free(c->data[PROP_HOSTNAME]);
c->data[PROP_HOSTNAME] = h;
@@ -403,7 +392,7 @@ static int method_set_hostname(sd_bus *bus, sd_bus_message *m, void *userdata) {
r = context_write_data_hostname(c);
if (r < 0) {
log_error("Failed to set host name: %s", strerror(-r));
- return sd_bus_reply_method_errnof(m, r, "Failed to set hostname: %s", strerror(-r));
+ return sd_bus_error_set_errnof(error, r, "Failed to set hostname: %s", strerror(-r));
}
log_info("Changed host name to '%s'", strna(c->data[PROP_HOSTNAME]));
@@ -413,8 +402,7 @@ static int method_set_hostname(sd_bus *bus, sd_bus_message *m, void *userdata) {
return sd_bus_reply_method_return(m, NULL);
}
-static int method_set_static_hostname(sd_bus *bus, sd_bus_message *m, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_set_static_hostname(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
Context *c = userdata;
const char *name;
int interactive;
@@ -422,7 +410,7 @@ static int method_set_static_hostname(sd_bus *bus, sd_bus_message *m, void *user
r = sd_bus_message_read(m, "sb", &name, &interactive);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, NULL);
+ return r;
if (isempty(name))
name = NULL;
@@ -430,9 +418,9 @@ static int method_set_static_hostname(sd_bus *bus, sd_bus_message *m, void *user
if (streq_ptr(name, c->data[PROP_STATIC_HOSTNAME]))
return sd_bus_reply_method_return(m, NULL);
- r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.hostname1.set-static-hostname", interactive, &error, method_set_static_hostname, c);
+ r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.hostname1.set-static-hostname", interactive, error, method_set_static_hostname, c);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, &error);
+ return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
@@ -443,11 +431,11 @@ static int method_set_static_hostname(sd_bus *bus, sd_bus_message *m, void *user
char *h;
if (!hostname_is_valid(name))
- return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Invalid static hostname '%s'", name);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid static hostname '%s'", name);
h = strdup(name);
if (!h)
- return log_oom();
+ return -ENOMEM;
free(c->data[PROP_STATIC_HOSTNAME]);
c->data[PROP_STATIC_HOSTNAME] = h;
@@ -456,7 +444,7 @@ static int method_set_static_hostname(sd_bus *bus, sd_bus_message *m, void *user
r = context_write_data_static_hostname(c);
if (r < 0) {
log_error("Failed to write static host name: %s", strerror(-r));
- return sd_bus_reply_method_errnof(m, r, "Failed to set static hostname: %s", strerror(-r));
+ return sd_bus_error_set_errnof(error, r, "Failed to set static hostname: %s", strerror(-r));
}
log_info("Changed static host name to '%s'", strna(c->data[PROP_STATIC_HOSTNAME]));
@@ -466,8 +454,7 @@ static int method_set_static_hostname(sd_bus *bus, sd_bus_message *m, void *user
return sd_bus_reply_method_return(m, NULL);
}
-static int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop, sd_bus_message_handler_t cb) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop, sd_bus_message_handler_t cb, sd_bus_error *error) {
int interactive;
const char *name;
int r;
@@ -478,7 +465,7 @@ static int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop
r = sd_bus_message_read(m, "sb", &name, &interactive);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, NULL);
+ return r;
if (isempty(name))
name = NULL;
@@ -492,9 +479,9 @@ static int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop
r = bus_verify_polkit_async(bus, &c->polkit_registry, m, prop == PROP_PRETTY_HOSTNAME ?
"org.freedesktop.hostname1.set-static-hostname" :
- "org.freedesktop.hostname1.set-machine-info", interactive, &error, cb, c);
+ "org.freedesktop.hostname1.set-machine-info", interactive, error, cb, c);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, &error);
+ return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
@@ -508,16 +495,16 @@ static int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop
* name, so better be safe than sorry */
if (prop == PROP_ICON_NAME && !filename_is_safe(name))
- return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Invalid icon name '%s'", name);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid icon name '%s'", name);
if (prop == PROP_PRETTY_HOSTNAME &&
(string_has_cc(name) || chars_intersect(name, "\t")))
- return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Invalid pretty host name '%s'", name);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid pretty host name '%s'", name);
if (prop == PROP_CHASSIS && !valid_chassis(name))
- return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Invalid chassis '%s'", name);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid chassis '%s'", name);
h = strdup(name);
if (!h)
- return log_oom();
+ return -ENOMEM;
free(c->data[prop]);
c->data[prop] = h;
@@ -526,7 +513,7 @@ static int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop
r = context_write_data_other(c);
if (r < 0) {
log_error("Failed to write machine info: %s", strerror(-r));
- return sd_bus_reply_method_errnof(m, r, "Failed to write machine info: %s", strerror(-r));
+ return sd_bus_error_set_errnof(error, r, "Failed to write machine info: %s", strerror(-r));
}
log_info("Changed %s to '%s'",
@@ -540,16 +527,16 @@ static int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop
return sd_bus_reply_method_return(m, NULL);
}
-static int method_set_pretty_hostname(sd_bus *bus, sd_bus_message *m, void *userdata) {
- return set_machine_info(userdata, bus, m, PROP_PRETTY_HOSTNAME, method_set_pretty_hostname);
+static int method_set_pretty_hostname(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
+ return set_machine_info(userdata, bus, m, PROP_PRETTY_HOSTNAME, method_set_pretty_hostname, error);
}
-static int method_set_icon_name(sd_bus *bus, sd_bus_message *m, void *userdata) {
- return set_machine_info(userdata, bus, m, PROP_ICON_NAME, method_set_icon_name);
+static int method_set_icon_name(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
+ return set_machine_info(userdata, bus, m, PROP_ICON_NAME, method_set_icon_name, error);
}
-static int method_set_chassis(sd_bus *bus, sd_bus_message *m, void *userdata) {
- return set_machine_info(userdata, bus, m, PROP_CHASSIS, method_set_chassis);
+static int method_set_chassis(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
+ return set_machine_info(userdata, bus, m, PROP_CHASSIS, method_set_chassis, error);
}
static const sd_bus_vtable hostname_vtable[] = {
diff --git a/src/libsystemd-bus/bus-match.c b/src/libsystemd-bus/bus-match.c
index 61b8a5cd88..f7fca5f573 100644
--- a/src/libsystemd-bus/bus-match.c
+++ b/src/libsystemd-bus/bus-match.c
@@ -22,6 +22,8 @@
#include "bus-internal.h"
#include "bus-message.h"
#include "bus-match.h"
+#include "bus-error.h"
+#include "bus-util.h"
/* Example:
*
@@ -272,7 +274,10 @@ int bus_match_run(
/* Run the callback. And then invoke siblings. */
if (node->leaf.callback) {
- r = node->leaf.callback(bus, m, node->leaf.userdata);
+ _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
+
+ r = node->leaf.callback(bus, m, node->leaf.userdata, &error_buffer);
+ r = bus_maybe_reply_error(m, r, &error_buffer);
if (r != 0)
return r;
}
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index f698b2ee99..a0e4e2cbe2 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -2133,7 +2133,7 @@ int bus_message_append_ap(
return r;
}
- return 0;
+ return 1;
}
_public_ int sd_bus_message_append(sd_bus_message *m, const char *types, ...) {
diff --git a/src/libsystemd-bus/bus-objects.c b/src/libsystemd-bus/bus-objects.c
index d9be3ddbfc..8413023d6f 100644
--- a/src/libsystemd-bus/bus-objects.c
+++ b/src/libsystemd-bus/bus-objects.c
@@ -223,6 +223,8 @@ static int node_callbacks_run(
assert(found_object);
LIST_FOREACH(callbacks, c, first) {
+ _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
+
if (bus->nodes_modified)
return 0;
@@ -240,7 +242,8 @@ static int node_callbacks_run(
if (r < 0)
return r;
- r = c->callback(bus, m, c->userdata);
+ r = c->callback(bus, m, c->userdata, &error_buffer);
+ r = bus_maybe_reply_error(m, r, &error_buffer);
if (r != 0)
return r;
}
@@ -299,8 +302,13 @@ static int method_callbacks_run(
return 1;
}
- if (c->vtable->x.method.handler)
- return c->vtable->x.method.handler(bus, m, u);
+ if (c->vtable->x.method.handler) {
+ _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
+
+ r = c->vtable->x.method.handler(bus, m, u, &error_buffer);
+
+ return bus_maybe_reply_error(m, r, &error_buffer);
+ }
/* If the method callback is NULL, make this a successful NOP */
r = sd_bus_reply_method_return(m, NULL);
@@ -316,9 +324,9 @@ static int invoke_property_get(
const char *path,
const char *interface,
const char *property,
- sd_bus_message *m,
- sd_bus_error *error,
- void *userdata) {
+ sd_bus_message *reply,
+ void *userdata,
+ sd_bus_error *error) {
const void *p;
@@ -327,15 +335,15 @@ static int invoke_property_get(
assert(path);
assert(interface);
assert(property);
- assert(m);
+ assert(reply);
if (v->x.property.get)
- return v->x.property.get(bus, path, interface, property, m, error, userdata);
+ return v->x.property.get(bus, path, interface, property, reply, userdata, error);
/* Automatic handling if no callback is defined. */
if (streq(v->x.property.signature, "as"))
- return sd_bus_message_append_strv(m, *(char***) userdata);
+ return sd_bus_message_append_strv(reply, *(char***) userdata);
assert(signature_is_single(v->x.property.signature, false));
assert(bus_type_is_basic(v->x.property.signature[0]));
@@ -357,7 +365,7 @@ static int invoke_property_get(
break;
}
- return sd_bus_message_append_basic(m, v->x.property.signature[0], p);
+ return sd_bus_message_append_basic(reply, v->x.property.signature[0], p);
}
static int invoke_property_set(
@@ -367,8 +375,8 @@ static int invoke_property_set(
const char *interface,
const char *property,
sd_bus_message *value,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
int r;
@@ -380,7 +388,7 @@ static int invoke_property_set(
assert(value);
if (v->x.property.set)
- return v->x.property.set(bus, path, interface, property, value, error, userdata);
+ return v->x.property.set(bus, path, interface, property, value, userdata, error);
/* Automatic handling if no callback is defined. */
@@ -428,8 +436,8 @@ static int property_get_set_callbacks_run(
bool is_get,
bool *found_object) {
- _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
void *u;
int r;
@@ -465,17 +473,11 @@ static int property_get_set_callbacks_run(
if (r < 0)
return r;
- r = invoke_property_get(bus, c->vtable, m->path, c->interface, c->member, reply, &error, u);
+ r = invoke_property_get(bus, c->vtable, m->path, c->interface, c->member, reply, u, &error);
if (r < 0)
- return r;
-
- if (sd_bus_error_is_set(&error)) {
- r = sd_bus_reply_method_error(m, &error);
- if (r < 0)
- return r;
-
- return 1;
- }
+ return sd_bus_reply_method_errno(m, r, &error);
+ if (sd_bus_error_is_set(&error))
+ return sd_bus_reply_method_error(m, &error);
if (bus->nodes_modified)
return 0;
@@ -486,33 +488,25 @@ static int property_get_set_callbacks_run(
} else {
if (c->vtable->type != _SD_BUS_VTABLE_WRITABLE_PROPERTY)
- sd_bus_error_setf(&error, SD_BUS_ERROR_PROPERTY_READ_ONLY, "Property '%s' is not writable.", c->member);
- else {
- /* Avoid that we call the set routine more
- * than once if the processing of this message
- * got restarted because the node tree
- * changed. */
- if (c->last_iteration == bus->iteration_counter)
- return 0;
-
- c->last_iteration = bus->iteration_counter;
+ return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_PROPERTY_READ_ONLY, "Property '%s' is not writable.", c->member);
- r = sd_bus_message_enter_container(m, 'v', c->vtable->x.property.signature);
- if (r < 0)
- return r;
+ /* Avoid that we call the set routine more than once
+ * if the processing of this message got restarted
+ * because the node tree changed. */
+ if (c->last_iteration == bus->iteration_counter)
+ return 0;
- r = invoke_property_set(bus, c->vtable, m->path, c->interface, c->member, m, &error, u);
- if (r < 0)
- return r;
- }
+ c->last_iteration = bus->iteration_counter;
- if (sd_bus_error_is_set(&error)) {
- r = sd_bus_reply_method_error(m, &error);
- if (r < 0)
- return r;
+ r = sd_bus_message_enter_container(m, 'v', c->vtable->x.property.signature);
+ if (r < 0)
+ return r;
- return 1;
- }
+ r = invoke_property_set(bus, c->vtable, m->path, c->interface, c->member, m, u, &error);
+ if (r < 0)
+ return sd_bus_reply_method_errno(m, r, &error);
+ if (sd_bus_error_is_set(&error))
+ return sd_bus_reply_method_error(m, &error);
if (bus->nodes_modified)
return 0;
@@ -561,11 +555,13 @@ static int vtable_append_all_properties(
if (r < 0)
return r;
- r = invoke_property_get(bus, v, path, c->interface, v->x.property.member, reply, error, vtable_property_convert_userdata(v, userdata));
- if (r < 0)
- return r;
+ r = invoke_property_get(bus, v, path, c->interface, v->x.property.member, reply, vtable_property_convert_userdata(v, userdata), error);
if (sd_bus_error_is_set(error))
return 0;
+ if (r < 0) {
+ sd_bus_error_set_errno(error, r);
+ return 0;
+ }
if (bus->nodes_modified)
return 0;
@@ -1944,9 +1940,11 @@ static int emit_properties_changed_on_interface(
if (r < 0)
return r;
- r = invoke_property_get(bus, v->vtable, m->path, interface, *property, m, &error, vtable_property_convert_userdata(v->vtable, u));
+ r = invoke_property_get(bus, v->vtable, m->path, interface, *property, m, vtable_property_convert_userdata(v->vtable, u), &error);
if (r < 0)
return r;
+ if (sd_bus_error_is_set(&error))
+ return sd_bus_error_get_errno(&error);
if (bus->nodes_modified)
return 0;
diff --git a/src/libsystemd-bus/bus-util.c b/src/libsystemd-bus/bus-util.c
index 65323d0081..4d73df5853 100644
--- a/src/libsystemd-bus/bus-util.c
+++ b/src/libsystemd-bus/bus-util.c
@@ -31,10 +31,10 @@
#include "sd-bus.h"
#include "bus-error.h"
#include "bus-message.h"
-
#include "bus-util.h"
+#include "bus-internal.h"
-static int quit_callback(sd_bus *bus, sd_bus_message *m, void *userdata) {
+static int quit_callback(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
sd_event *e = userdata;
assert(bus);
@@ -103,25 +103,6 @@ int bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t
return 0;
}
-int bus_property_get_tristate(
- sd_bus *bus,
- const char *path,
- const char *interface,
- const char *property,
- sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
-
- int *tristate = userdata;
- int r;
-
- r = sd_bus_message_append(reply, "b", *tristate > 0);
- if (r < 0)
- return r;
-
- return 1;
-}
-
int bus_verify_polkit(
sd_bus *bus,
sd_bus_message *m,
@@ -203,11 +184,30 @@ typedef struct AsyncPolkitQuery {
sd_bus_message_handler_t callback;
void *userdata;
uint64_t serial;
+ Hashmap *registry;
} AsyncPolkitQuery;
-static int async_polkit_callback(sd_bus *bus, sd_bus_message *reply, void *userdata) {
- AsyncPolkitQuery *q = userdata;
+static void async_polkit_query_free(sd_bus *b, AsyncPolkitQuery *q) {
+
+ if (!q)
+ return;
+
+ if (q->serial > 0 && b)
+ sd_bus_call_async_cancel(b, q->serial);
+
+ if (q->registry && q->request)
+ hashmap_remove(q->registry, q->request);
+
+ sd_bus_message_unref(q->request);
+ sd_bus_message_unref(q->reply);
+
+ free(q);
+}
+
+static int async_polkit_callback(sd_bus *bus, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
+ _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
+ AsyncPolkitQuery *q = userdata;
int r;
assert(bus);
@@ -217,30 +217,18 @@ static int async_polkit_callback(sd_bus *bus, sd_bus_message *reply, void *userd
q->reply = sd_bus_message_ref(reply);
q->serial = 0;
- m = sd_bus_message_ref(q->request);
-
- r = sd_bus_message_rewind(m, true);
- if (r < 0)
- return r;
-
- r = q->callback(bus, m, q->userdata);
- if (r < 0)
- return r;
-
- return 1;
-}
-
-static void async_polkit_query_free(sd_bus *b, AsyncPolkitQuery *q) {
+ r = sd_bus_message_rewind(q->request, true);
+ if (r < 0) {
+ r = sd_bus_reply_method_errno(q->request, r, NULL);
+ goto finish;
+ }
- if (!q)
- return;
+ r = q->callback(bus, q->request, q->userdata, &error_buffer);
+ r = bus_maybe_reply_error(q->request, r, &error_buffer);
- if (q->serial > 0 && b)
- sd_bus_call_async_cancel(b, q->serial);
-
- sd_bus_message_unref(q->request);
- sd_bus_message_unref(q->reply);
- free(q);
+finish:
+ async_polkit_query_free(bus, q);
+ return r;
}
#endif
@@ -269,7 +257,7 @@ int bus_verify_polkit_async(
assert(action);
#ifdef ENABLE_POLKIT
- q = hashmap_remove(*registry, m);
+ q = hashmap_get(*registry, m);
if (q) {
int authorized, challenge;
@@ -281,26 +269,21 @@ int bus_verify_polkit_async(
if (sd_bus_message_is_method_error(q->reply, NULL)) {
const sd_bus_error *e;
- /* Treat no PK available as access denied */
- if (sd_bus_message_is_method_error(q->reply, SD_BUS_ERROR_SERVICE_UNKNOWN)) {
- async_polkit_query_free(bus, q);
- return -EACCES;
- }
-
+ /* Copy error from polkit reply */
e = sd_bus_message_get_error(q->reply);
sd_bus_error_copy(error, e);
- r = sd_bus_error_get_errno(e);
- async_polkit_query_free(bus, q);
- return r;
+ /* Treat no PK available as access denied */
+ if (sd_bus_error_has_name(e, SD_BUS_ERROR_SERVICE_UNKNOWN))
+ return -EACCES;
+
+ return sd_bus_error_get_errno(e);
}
r = sd_bus_message_enter_container(q->reply, 'r', "bba{ss}");
if (r >= 0)
r = sd_bus_message_read(q->reply, "bb", &authorized, &challenge);
- async_polkit_query_free(bus, q);
-
if (r < 0)
return r;
@@ -344,7 +327,7 @@ int bus_verify_polkit_async(
action,
0,
interactive ? 1 : 0,
- "");
+ NULL);
if (r < 0)
return r;
@@ -362,9 +345,13 @@ int bus_verify_polkit_async(
return r;
}
+ q->registry = *registry;
+
r = sd_bus_call_async(bus, pk, async_polkit_callback, q, 0, &q->serial);
- if (r < 0)
+ if (r < 0) {
+ async_polkit_query_free(bus, q);
return r;
+ }
return 0;
#endif
@@ -1000,14 +987,28 @@ int bus_open_transport_systemd(BusTransport transport, const char *host, bool us
return r;
}
+int bus_property_get_tristate(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ void *userdata,
+ sd_bus_error *error) {
+
+ int *tristate = userdata;
+
+ return sd_bus_message_append(reply, "b", *tristate > 0);
+}
+
int bus_property_get_bool(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
int b = *(bool*) userdata;
@@ -1021,8 +1022,8 @@ int bus_property_get_size(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
uint64_t sz = *(size_t*) userdata;
@@ -1037,8 +1038,8 @@ int bus_property_get_long(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
int64_t l = *(long*) userdata;
@@ -1051,8 +1052,8 @@ int bus_property_get_ulong(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
uint64_t ul = *(unsigned long*) userdata;
@@ -1088,3 +1089,29 @@ int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u) {
&u->job_type,
&u->job_path);
}
+
+int bus_maybe_reply_error(sd_bus_message *m, int r, sd_bus_error *error) {
+ assert(m);
+
+ if (r < 0) {
+ if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL)
+ sd_bus_reply_method_errno(m, r, error);
+
+ } else if (sd_bus_error_is_set(error)) {
+ if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL)
+ sd_bus_reply_method_error(m, error);
+
+ } else
+ return r;
+
+ log_debug("Failed to process message [type=%s sender=%s path=%s interface=%s member=%s signature=%s]: %s",
+ bus_message_type_to_string(m->header->type),
+ strna(m->sender),
+ strna(m->path),
+ strna(m->interface),
+ strna(m->member),
+ strna(m->root_container.signature),
+ bus_error_message(error, r));
+
+ return 1;
+}
diff --git a/src/libsystemd-bus/bus-util.h b/src/libsystemd-bus/bus-util.h
index c8d5dd982e..38533be66d 100644
--- a/src/libsystemd-bus/bus-util.h
+++ b/src/libsystemd-bus/bus-util.h
@@ -72,8 +72,8 @@ int bus_open_transport_systemd(BusTransport transport, const char *host, bool us
int bus_print_property(const char *name, sd_bus_message *property, bool all);
int bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, char **filter, bool all);
-int bus_property_get_tristate(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata);
-int bus_property_get_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata);
+int bus_property_get_tristate(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
+int bus_property_get_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
#define bus_property_get_usec ((sd_bus_property_get_t) NULL)
#define bus_property_set_usec ((sd_bus_property_set_t) NULL)
@@ -89,15 +89,15 @@ assert_cc(sizeof(unsigned) == sizeof(unsigned));
#if __SIZEOF_SIZE_T__ == 8
#define bus_property_get_size ((sd_bus_property_get_t) NULL)
#else
-int bus_property_get_size(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata);
+int bus_property_get_size(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
#endif
#if __SIZEOF_LONG__ == 8
#define bus_property_get_long ((sd_bus_property_get_t) NULL)
#define bus_property_get_ulong ((sd_bus_property_get_t) NULL)
#else
-int bus_property_get_long(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata);
-int bus_property_get_ulong(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata);
+int bus_property_get_long(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
+int bus_property_get_ulong(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
#endif
/* uid_t and friends on Linux 32 bit. This means we can just use the
@@ -146,8 +146,8 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_message*, sd_bus_message_unref);
const char *interface, \
const char *property, \
sd_bus_message *reply, \
- sd_bus_error *error, \
- void *userdata) { \
+ void *userdata, \
+ sd_bus_error *error) { \
\
const char *value; \
type *field = userdata; \
@@ -170,3 +170,5 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_message*, sd_bus_message_unref);
#define BUS_PROPERTY_DUAL_TIMESTAMP(name, offset, flags) \
SD_BUS_PROPERTY(name, "t", bus_property_get_usec, offset + offsetof(struct dual_timestamp, realtime), flags), \
SD_BUS_PROPERTY(name "Monotonic", "t", bus_property_get_usec, offset + offsetof(struct dual_timestamp, monotonic), flags)
+
+int bus_maybe_reply_error(sd_bus_message *m, int r, sd_bus_error *error);
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 7f00eee6e1..2604434467 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -365,7 +365,7 @@ _public_ int sd_bus_set_anonymous(sd_bus *bus, int b) {
return 0;
}
-static int hello_callback(sd_bus *bus, sd_bus_message *reply, void *userdata) {
+static int hello_callback(sd_bus *bus, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
const char *s;
int r;
@@ -1824,6 +1824,7 @@ _public_ int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec) {
}
static int process_timeout(sd_bus *bus) {
+ _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
_cleanup_bus_message_unref_ sd_bus_message* m = NULL;
struct reply_callback *c;
usec_t n;
@@ -1857,12 +1858,13 @@ static int process_timeout(sd_bus *bus) {
bus->current = m;
bus->iteration_counter ++;
- r = c->callback(bus, m, c->userdata);
+ r = c->callback(bus, m, c->userdata, &error_buffer);
+ r = bus_maybe_reply_error(m, r, &error_buffer);
free(c);
bus->current = NULL;
- return r < 0 ? r : 1;
+ return r;
}
static int process_hello(sd_bus *bus, sd_bus_message *m) {
@@ -1888,6 +1890,7 @@ static int process_hello(sd_bus *bus, sd_bus_message *m) {
}
static int process_reply(sd_bus *bus, sd_bus_message *m) {
+ _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
struct reply_callback *c;
int r;
@@ -1909,13 +1912,15 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) {
if (r < 0)
return r;
- r = c->callback(bus, m, c->userdata);
+ r = c->callback(bus, m, c->userdata, &error_buffer);
+ r = bus_maybe_reply_error(m, r, &error_buffer);
free(c);
- return r < 0 ? r : 1;
+ return r;
}
static int process_filter(sd_bus *bus, sd_bus_message *m) {
+ _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
struct filter_callback *l;
int r;
@@ -1940,7 +1945,8 @@ static int process_filter(sd_bus *bus, sd_bus_message *m) {
if (r < 0)
return r;
- r = l->callback(bus, m, l->userdata);
+ r = l->callback(bus, m, &error_buffer, l->userdata);
+ r = bus_maybe_reply_error(m, r, &error_buffer);
if (r != 0)
return r;
@@ -2123,6 +2129,8 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) {
c = hashmap_first(bus->reply_callbacks);
if (c) {
+ _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
+
/* First, fail all outstanding method calls */
r = bus_message_new_synthetic_error(
bus,
@@ -2144,12 +2152,10 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) {
bus->current = m;
bus->iteration_counter++;
- r = c->callback(bus, m, c->userdata);
+ r = c->callback(bus, m, c->userdata, &error_buffer);
+ r = bus_maybe_reply_error(m, r, &error_buffer);
free(c);
- if (r >= 0)
- r = 1;
-
goto finish;
}
diff --git a/src/libsystemd-bus/test-bus-chat.c b/src/libsystemd-bus/test-bus-chat.c
index 0c66dc794a..66a5df9b57 100644
--- a/src/libsystemd-bus/test-bus-chat.c
+++ b/src/libsystemd-bus/test-bus-chat.c
@@ -36,12 +36,12 @@
#include "bus-internal.h"
#include "bus-util.h"
-static int match_callback(sd_bus *bus, sd_bus_message *m, void *userdata) {
+static int match_callback(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
log_info("Match triggered! interface=%s member=%s", strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member(m)));
return 0;
}
-static int object_callback(sd_bus *bus, sd_bus_message *m, void *userdata) {
+static int object_callback(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
int r;
assert(bus);
@@ -361,7 +361,7 @@ finish:
return INT_TO_PTR(r);
}
-static int quit_callback(sd_bus *b, sd_bus_message *m, void *userdata) {
+static int quit_callback(sd_bus *b, sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
bool *x = userdata;
log_error("Quit callback: %s", strerror(sd_bus_message_get_errno(m)));
diff --git a/src/libsystemd-bus/test-bus-introspect.c b/src/libsystemd-bus/test-bus-introspect.c
index b9865349ac..50c4c2d871 100644
--- a/src/libsystemd-bus/test-bus-introspect.c
+++ b/src/libsystemd-bus/test-bus-introspect.c
@@ -23,11 +23,11 @@
#include "log.h"
#include "bus-introspect.h"
-static int prop_get(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata) {
+static int prop_get(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
return -EINVAL;
}
-static int prop_set(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata) {
+static int prop_set(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
return -EINVAL;
}
diff --git a/src/libsystemd-bus/test-bus-match.c b/src/libsystemd-bus/test-bus-match.c
index 7d7c55247f..af42f0baa7 100644
--- a/src/libsystemd-bus/test-bus-match.c
+++ b/src/libsystemd-bus/test-bus-match.c
@@ -31,7 +31,7 @@
static bool mask[32];
-static int filter(sd_bus *b, sd_bus_message *m, void *userdata) {
+static int filter(sd_bus *b, sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
log_info("Ran %i", PTR_TO_INT(userdata));
mask[PTR_TO_INT(userdata)] = true;
return 0;
diff --git a/src/libsystemd-bus/test-bus-objects.c b/src/libsystemd-bus/test-bus-objects.c
index 0e9ef57da1..043aa90b3c 100644
--- a/src/libsystemd-bus/test-bus-objects.c
+++ b/src/libsystemd-bus/test-bus-objects.c
@@ -44,7 +44,7 @@ struct context {
uint32_t automatic_integer_property;
};
-static int something_handler(sd_bus *bus, sd_bus_message *m, void *userdata) {
+static int something_handler(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
struct context *c = userdata;
const char *s;
char *n = NULL;
@@ -67,7 +67,7 @@ static int something_handler(sd_bus *bus, sd_bus_message *m, void *userdata) {
return 1;
}
-static int exit_handler(sd_bus *bus, sd_bus_message *m, void *userdata) {
+static int exit_handler(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
struct context *c = userdata;
int r;
@@ -81,11 +81,11 @@ static int exit_handler(sd_bus *bus, sd_bus_message *m, void *userdata) {
return 1;
}
-static int get_handler(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata) {
+static int get_handler(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
struct context *c = userdata;
int r;
- log_info("property get for %s called", property);
+ log_info("property get for %s called, returning \"%s\".", property, c->something);
r = sd_bus_message_append(reply, "s", c->something);
assert_se(r >= 0);
@@ -93,7 +93,7 @@ static int get_handler(sd_bus *bus, const char *path, const char *interface, con
return 1;
}
-static int set_handler(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, sd_bus_error *error, void *userdata) {
+static int set_handler(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, void *userdata, sd_bus_error *error) {
struct context *c = userdata;
const char *s;
char *n;
@@ -113,7 +113,7 @@ static int set_handler(sd_bus *bus, const char *path, const char *interface, con
return 1;
}
-static int value_handler(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata) {
+static int value_handler(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *s = NULL;
const char *x;
int r;
@@ -129,7 +129,7 @@ static int value_handler(sd_bus *bus, const char *path, const char *interface, c
return 1;
}
-static int notify_test(sd_bus *bus, sd_bus_message *m, void *userdata) {
+static int notify_test(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
int r;
assert_se(sd_bus_emit_properties_changed(bus, m->path, "org.freedesktop.systemd.ValueTest", "Value", NULL) >= 0);
@@ -140,7 +140,7 @@ static int notify_test(sd_bus *bus, sd_bus_message *m, void *userdata) {
return 1;
}
-static int emit_interfaces_added(sd_bus *bus, sd_bus_message *m, void *userdata) {
+static int emit_interfaces_added(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
int r;
assert_se(sd_bus_emit_interfaces_added(bus, m->path, "org.freedesktop.systemd.test", NULL) >= 0);
@@ -151,7 +151,7 @@ static int emit_interfaces_added(sd_bus *bus, sd_bus_message *m, void *userdata)
return 1;
}
-static int emit_interfaces_removed(sd_bus *bus, sd_bus_message *m, void *userdata) {
+static int emit_interfaces_removed(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
int r;
assert_se(sd_bus_emit_interfaces_removed(bus, m->path, "org.freedesktop.systemd.test", NULL) >= 0);
@@ -435,7 +435,7 @@ static int client(struct context *c) {
}
int main(int argc, char *argv[]) {
- struct context c;
+ struct context c = {};
pthread_t s;
void *p;
int r, q;
diff --git a/src/locale/localed.c b/src/locale/localed.c
index 7bf80fbf2b..7ef4d13079 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -787,8 +787,15 @@ static int x11_convert_to_vconsole(Context *c, sd_bus *bus) {
return 0;
}
-static int property_get_locale(sd_bus *bus, const char *path, const char *interface,
- const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata) {
+static int property_get_locale(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ void *userdata,
+ sd_bus_error *error) {
+
Context *c = userdata;
_cleanup_strv_free_ char **l = NULL;
int p, q;
@@ -812,9 +819,8 @@ static int property_get_locale(sd_bus *bus, const char *path, const char *interf
return sd_bus_message_append_strv(reply, l);
}
-static int method_set_locale(sd_bus *bus, sd_bus_message *m, void *userdata) {
+static int method_set_locale(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
Context *c = userdata;
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_strv_free_ char **l = NULL;
char **i;
int interactive;
@@ -825,11 +831,11 @@ static int method_set_locale(sd_bus *bus, sd_bus_message *m, void *userdata) {
r = bus_message_read_strv_extend(m, &l);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, NULL);
+ return r;
r = sd_bus_message_read_basic(m, 'b', &interactive);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, NULL);
+ return r;
/* Check whether a variable changed and if so valid */
STRV_FOREACH(i, l) {
@@ -853,7 +859,7 @@ static int method_set_locale(sd_bus *bus, sd_bus_message *m, void *userdata) {
}
if (!valid)
- sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Invalid Locale data.");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid Locale data.");
}
/* Check whether a variable is unset */
@@ -868,9 +874,9 @@ static int method_set_locale(sd_bus *bus, sd_bus_message *m, void *userdata) {
if (modified) {
r = bus_verify_polkit_async(bus, &c->polkit_registry, m,
"org.freedesktop.locale1.set-locale", interactive,
- &error, method_set_locale, c);
+ error, method_set_locale, c);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, &error);
+ return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
@@ -905,7 +911,7 @@ static int method_set_locale(sd_bus *bus, sd_bus_message *m, void *userdata) {
r = locale_write_data(c);
if (r < 0) {
log_error("Failed to set locale: %s", strerror(-r));
- return sd_bus_reply_method_errnof(m, r, "Failed to set locale: %s", strerror(-r));
+ return sd_bus_error_set_errnof(error, r, "Failed to set locale: %s", strerror(-r));
}
locale_update_system_manager(c, bus);
@@ -921,16 +927,15 @@ static int method_set_locale(sd_bus *bus, sd_bus_message *m, void *userdata) {
return sd_bus_reply_method_return(m, NULL);
}
-static int method_set_vc_keyboard(sd_bus *bus, sd_bus_message *m, void *userdata) {
+static int method_set_vc_keyboard(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
Context *c = userdata;
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
const char *keymap, *keymap_toggle;
int convert, interactive;
int r;
r = sd_bus_message_read(m, "ssbb", &keymap, &keymap_toggle, &convert, &interactive);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, NULL);
+ return r;
if (isempty(keymap))
keymap = NULL;
@@ -943,13 +948,13 @@ static int method_set_vc_keyboard(sd_bus *bus, sd_bus_message *m, void *userdata
if ((keymap && (!filename_is_safe(keymap) || !string_is_safe(keymap))) ||
(keymap_toggle && (!filename_is_safe(keymap_toggle) || !string_is_safe(keymap_toggle))))
- return sd_bus_reply_method_errnof(m, r, "Received invalid keymap data: %s", -EINVAL);
+ return sd_bus_error_set_errnof(error, r, "Received invalid keymap data: %s", -EINVAL);
r = bus_verify_polkit_async(bus, &c->polkit_registry, m,
"org.freedesktop.locale1.set-keyboard",
- interactive, &error, method_set_vc_keyboard, c);
+ interactive, error, method_set_vc_keyboard, c);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, &error);
+ return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
@@ -960,7 +965,7 @@ static int method_set_vc_keyboard(sd_bus *bus, sd_bus_message *m, void *userdata
r = vconsole_write_data(c);
if (r < 0) {
log_error("Failed to set virtual console keymap: %s", strerror(-r));
- return sd_bus_reply_method_errnof(m, r, "Failed to set virtual console keymap: %s", strerror(-r));
+ return sd_bus_error_set_errnof(error, r, "Failed to set virtual console keymap: %s", strerror(-r));
}
log_info("Changed virtual console keymap to '%s'", strempty(c->vc_keymap));
@@ -984,16 +989,15 @@ static int method_set_vc_keyboard(sd_bus *bus, sd_bus_message *m, void *userdata
return sd_bus_reply_method_return(m, NULL);
}
-static int method_set_x11_keyboard(sd_bus *bus, sd_bus_message *m, void *userdata) {
+static int method_set_x11_keyboard(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
Context *c = userdata;
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
const char *layout, *model, *variant, *options;
int convert, interactive;
int r;
r = sd_bus_message_read(m, "ssssbb", &layout, &model, &variant, &options, &convert, &interactive);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, NULL);
+ return r;
if (isempty(layout))
layout = NULL;
@@ -1016,13 +1020,13 @@ static int method_set_x11_keyboard(sd_bus *bus, sd_bus_message *m, void *userdat
(model && !string_is_safe(model)) ||
(variant && !string_is_safe(variant)) ||
(options && !string_is_safe(options)))
- return sd_bus_reply_method_errnof(m, r, "Received invalid keyboard data: %s", -EINVAL);
+ return sd_bus_error_set_errnof(error, r, "Received invalid keyboard data: %s", -EINVAL);
r = bus_verify_polkit_async(bus, &c->polkit_registry, m,
"org.freedesktop.locale1.set-keyboard",
- interactive, &error, method_set_x11_keyboard, c);
+ interactive, error, method_set_x11_keyboard, c);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, &error);
+ return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
@@ -1035,7 +1039,7 @@ static int method_set_x11_keyboard(sd_bus *bus, sd_bus_message *m, void *userdat
r = write_data_x11(c);
if (r < 0) {
log_error("Failed to set X11 keyboard layout: %s", strerror(-r));
- return sd_bus_reply_method_errnof(m, r, "Failed to set X11 keyboard layout: %s", strerror(-r));
+ return sd_bus_error_set_errnof(error, r, "Failed to set X11 keyboard layout: %s", strerror(-r));
}
log_info("Changed X11 keyboard layout to '%s'", strempty(c->x11_layout));
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 984235c4e5..b1c2ef19b1 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -48,8 +48,8 @@ static int property_get_idle_hint(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Manager *m = userdata;
@@ -66,8 +66,8 @@ static int property_get_idle_since_hint(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Manager *m = userdata;
dual_timestamp t;
@@ -87,8 +87,8 @@ static int property_get_inhibited(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Manager *m = userdata;
InhibitWhat w;
@@ -108,8 +108,8 @@ static int property_get_preparing(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Manager *m = userdata;
bool b;
@@ -128,7 +128,7 @@ static int property_get_preparing(
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_handle_action, handle_action, HandleAction);
-static int method_get_session(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_get_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
Manager *m = userdata;
const char *name;
@@ -141,20 +141,20 @@ static int method_get_session(sd_bus *bus, sd_bus_message *message, void *userda
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
session = hashmap_get(m->sessions, name);
if (!session)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
p = session_bus_path(session);
if (!p)
- return sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ return -ENOMEM;
return sd_bus_reply_method_return(message, "o", p);
}
-static int method_get_session_by_pid(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_get_session_by_pid(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
Session *session = NULL;
Manager *m = userdata;
@@ -169,28 +169,28 @@ static int method_get_session_by_pid(sd_bus *bus, sd_bus_message *message, void
r = sd_bus_message_read(message, "u", &pid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (pid == 0) {
r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
}
r = manager_get_session_by_pid(m, pid, &session);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (!session)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SESSION_FOR_PID, "PID %lu does not belong to any known session", (unsigned long) pid);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SESSION_FOR_PID, "PID %lu does not belong to any known session", (unsigned long) pid);
p = session_bus_path(session);
if (!p)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
return sd_bus_reply_method_return(message, "o", p);
}
-static int method_get_user(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_get_user(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
Manager *m = userdata;
uint32_t uid;
@@ -203,20 +203,20 @@ static int method_get_user(sd_bus *bus, sd_bus_message *message, void *userdata)
r = sd_bus_message_read(message, "u", &uid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
if (!user)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
p = user_bus_path(user);
if (!p)
- return sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ return -ENOMEM;
return sd_bus_reply_method_return(message, "o", p);
}
-static int method_get_user_by_pid(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_get_user_by_pid(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
Manager *m = userdata;
User *user = NULL;
@@ -231,28 +231,28 @@ static int method_get_user_by_pid(sd_bus *bus, sd_bus_message *message, void *us
r = sd_bus_message_read(message, "u", &pid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (pid == 0) {
r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
}
r = manager_get_user_by_pid(m, pid, &user);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (!user)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_USER_FOR_PID, "PID %lu does not belong to any known or logged in user", (unsigned long) pid);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_USER_FOR_PID, "PID %lu does not belong to any known or logged in user", (unsigned long) pid);
p = user_bus_path(user);
if (!p)
- return sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ return -ENOMEM;
return sd_bus_reply_method_return(message, "o", p);
}
-static int method_get_seat(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_get_seat(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
Manager *m = userdata;
const char *name;
@@ -265,20 +265,20 @@ static int method_get_seat(sd_bus *bus, sd_bus_message *message, void *userdata)
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
seat = hashmap_get(m->seats, name);
if (!seat)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SEAT, "No seat '%s' known", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SEAT, "No seat '%s' known", name);
p = seat_bus_path(seat);
if (!p)
- return sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ return -ENOMEM;
return sd_bus_reply_method_return(message, "o", p);
}
-static int method_list_sessions(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_list_sessions(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
Manager *m = userdata;
Session *session;
@@ -291,18 +291,18 @@ static int method_list_sessions(sd_bus *bus, sd_bus_message *message, void *user
r = sd_bus_message_new_method_return(message, &reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = sd_bus_message_open_container(reply, 'a', "(susso)");
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
HASHMAP_FOREACH(session, m->sessions, i) {
_cleanup_free_ char *p = NULL;
p = session_bus_path(session);
if (!p)
- return sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ return -ENOMEM;
r = sd_bus_message_append(reply, "(susso)",
session->id,
@@ -311,17 +311,17 @@ static int method_list_sessions(sd_bus *bus, sd_bus_message *message, void *user
session->seat ? session->seat->id : "",
p);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
}
r = sd_bus_message_close_container(reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_send(bus, reply, NULL);
}
-static int method_list_users(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_list_users(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
Manager *m = userdata;
User *user;
@@ -334,35 +334,35 @@ static int method_list_users(sd_bus *bus, sd_bus_message *message, void *userdat
r = sd_bus_message_new_method_return(message, &reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = sd_bus_message_open_container(reply, 'a', "(uso)");
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
HASHMAP_FOREACH(user, m->users, i) {
_cleanup_free_ char *p = NULL;
p = user_bus_path(user);
if (!p)
- return sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ return -ENOMEM;
r = sd_bus_message_append(reply, "(uso)",
(uint32_t) user->uid,
user->name,
p);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
}
r = sd_bus_message_close_container(reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_send(bus, reply, NULL);
}
-static int method_list_seats(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_list_seats(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
Manager *m = userdata;
Seat *seat;
@@ -375,32 +375,32 @@ static int method_list_seats(sd_bus *bus, sd_bus_message *message, void *userdat
r = sd_bus_message_new_method_return(message, &reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = sd_bus_message_open_container(reply, 'a', "(so)");
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
HASHMAP_FOREACH(seat, m->seats, i) {
_cleanup_free_ char *p = NULL;
p = seat_bus_path(seat);
if (!p)
- return sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ return -ENOMEM;
r = sd_bus_message_append(reply, "(so)", seat->id, p);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
}
r = sd_bus_message_close_container(reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_send(bus, reply, NULL);
}
-static int method_list_inhibitors(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_list_inhibitors(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
Manager *m = userdata;
Inhibitor *inhibitor;
@@ -409,11 +409,11 @@ static int method_list_inhibitors(sd_bus *bus, sd_bus_message *message, void *us
r = sd_bus_message_new_method_return(message, &reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = sd_bus_message_open_container(reply, 'a', "(ssssuu)");
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
HASHMAP_FOREACH(inhibitor, m->inhibitors, i) {
@@ -425,17 +425,17 @@ static int method_list_inhibitors(sd_bus *bus, sd_bus_message *message, void *us
(uint32_t) inhibitor->uid,
(uint32_t) inhibitor->pid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
}
r = sd_bus_message_close_container(reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_send(bus, reply, NULL);
}
-static int method_create_session(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_create_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *service, *type, *class, *cseat, *tty, *display, *remote_user, *remote_host;
uint32_t uid, leader, audit_id = 0;
_cleanup_free_ char *id = NULL;
@@ -455,17 +455,17 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
r = sd_bus_message_read(message, "uussssussbss", &uid, &leader, &service, &type, &class, &cseat, &vtnr, &tty, &display, &remote, &remote_user, &remote_host);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (leader == 1)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid leader PID");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid leader PID");
if (isempty(type))
t = _SESSION_TYPE_INVALID;
else {
t = session_type_from_string(type);
if (t < 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid session type %s", type);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid session type %s", type);
}
if (isempty(class))
@@ -473,7 +473,7 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
else {
c = session_class_from_string(class);
if (c < 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid session class %s", class);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid session class %s", class);
}
if (isempty(cseat))
@@ -481,7 +481,7 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
else {
seat = hashmap_get(m->seats, cseat);
if (!seat)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SEAT, "No seat '%s' known", seat);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SEAT, "No seat '%s' known", seat);
}
if (tty_is_vc(tty)) {
@@ -490,41 +490,41 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
if (!seat)
seat = m->seat0;
else if (seat != m->seat0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "TTY %s is virtual console but seat %s is not seat0", tty, seat);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "TTY %s is virtual console but seat %s is not seat0", tty, seat);
v = vtnr_from_tty(tty);
if (v <= 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Cannot determine VT number from virtual console TTY %s", tty);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Cannot determine VT number from virtual console TTY %s", tty);
if (vtnr <= 0)
vtnr = (uint32_t) v;
else if (vtnr != (uint32_t) v)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Specified TTY and VT number do not match");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified TTY and VT number do not match");
} else if (tty_is_console(tty)) {
if (!seat)
seat = m->seat0;
else if (seat != m->seat0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Console TTY specified but seat is not seat0");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Console TTY specified but seat is not seat0");
if (vtnr != 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Console TTY specified but VT number is not 0");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Console TTY specified but VT number is not 0");
}
if (seat) {
if (seat_has_vts(seat)) {
if (vtnr > 63)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "VT number out of range");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "VT number out of range");
} else {
if (vtnr != 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Seat has no VTs but VT number not 0");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Seat has no VTs but VT number not 0");
}
}
r = sd_bus_message_enter_container(message, 'a', "(sv)");
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (t == _SESSION_TYPE_INVALID) {
if (!isempty(display))
@@ -547,7 +547,7 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), (pid_t*) &leader);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
}
manager_get_session_by_pid(m, leader, &session);
@@ -561,11 +561,11 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
fifo_fd = session_create_fifo(session);
if (fifo_fd < 0)
- return sd_bus_reply_method_errno(message, fifo_fd, NULL);
+ return fifo_fd;
path = session_bus_path(session);
if (!path)
- return sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ return -ENOMEM;
return sd_bus_reply_method_return(
message, "soshsub",
@@ -583,7 +583,7 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
/* Keep our session IDs and the audit session IDs in sync */
if (asprintf(&id, "%lu", (unsigned long) audit_id) < 0)
- return sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ return -ENOMEM;
/* Wut? There's already a session by this name and we
* didn't find it above? Weird, then let's not trust
@@ -604,22 +604,18 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
id = NULL;
if (asprintf(&id, "c%lu", ++m->session_counter) < 0)
- return sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ return -ENOMEM;
} while (hashmap_get(m->sessions, id));
}
r = manager_add_user_by_uid(m, uid, &user);
- if (r < 0) {
- r = sd_bus_reply_method_errno(message, r, NULL);
+ if (r < 0)
goto fail;
- }
r = manager_add_session(m, id, &session);
- if (r < 0) {
- r = sd_bus_reply_method_errno(message, r, NULL);
+ if (r < 0)
goto fail;
- }
session_set_user(session, user);
@@ -633,7 +629,7 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
if (!isempty(tty)) {
session->tty = strdup(tty);
if (!session->tty) {
- r = sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ r = -ENOMEM;
goto fail;
}
}
@@ -641,7 +637,7 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
if (!isempty(display)) {
session->display = strdup(display);
if (!session->display) {
- r = sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ r = -ENOMEM;
goto fail;
}
}
@@ -649,7 +645,7 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
if (!isempty(remote_user)) {
session->remote_user = strdup(remote_user);
if (!session->remote_user) {
- r = sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ r = -ENOMEM;
goto fail;
}
}
@@ -657,7 +653,7 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
if (!isempty(remote_host)) {
session->remote_host = strdup(remote_host);
if (!session->remote_host) {
- r = sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ r = -ENOMEM;
goto fail;
}
}
@@ -665,24 +661,20 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
if (!isempty(service)) {
session->service = strdup(service);
if (!session->service) {
- r = sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ r = -ENOMEM;
goto fail;
}
}
if (seat) {
r = seat_attach_session(seat, session);
- if (r < 0) {
- r = sd_bus_reply_method_errno(message, r, NULL);
+ if (r < 0)
goto fail;
- }
}
r = session_start(session);
- if (r < 0) {
- r = sd_bus_reply_method_errno(message, r, NULL);
+ if (r < 0)
goto fail;
- }
session->create_message = sd_bus_message_ref(message);
@@ -702,7 +694,7 @@ fail:
return r;
}
-static int method_release_session(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_release_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
Session *session;
const char *name;
@@ -714,11 +706,11 @@ static int method_release_session(sd_bus *bus, sd_bus_message *message, void *us
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
session = hashmap_get(m->sessions, name);
if (!session)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
/* We use the FIFO to detect stray sessions where the process
invoking PAM dies abnormally. We need to make sure that
@@ -733,7 +725,7 @@ static int method_release_session(sd_bus *bus, sd_bus_message *message, void *us
return sd_bus_reply_method_return(message, NULL);
}
-static int method_activate_session(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_activate_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
Session *session;
const char *name;
@@ -745,20 +737,20 @@ static int method_activate_session(sd_bus *bus, sd_bus_message *message, void *u
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
session = hashmap_get(m->sessions, name);
if (!session)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
r = session_activate(session);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_activate_session_on_seat(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_activate_session_on_seat(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *session_name, *seat_name;
Manager *m = userdata;
Session *session;
@@ -774,27 +766,27 @@ static int method_activate_session_on_seat(sd_bus *bus, sd_bus_message *message,
r = sd_bus_message_read(message, "ss", &session_name, &seat_name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
session = hashmap_get(m->sessions, session_name);
if (!session)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", session_name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", session_name);
seat = hashmap_get(m->seats, seat_name);
if (!seat)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SEAT, "No seat '%s' known", seat_name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SEAT, "No seat '%s' known", seat_name);
if (session->seat != seat)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_SESSION_NOT_ON_SEAT, "Session %s not on seat %s", session_name, seat_name);
+ return sd_bus_error_setf(error, BUS_ERROR_SESSION_NOT_ON_SEAT, "Session %s not on seat %s", session_name, seat_name);
r = session_activate(session);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_lock_session(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_lock_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
Session *session;
const char *name;
@@ -806,20 +798,20 @@ static int method_lock_session(sd_bus *bus, sd_bus_message *message, void *userd
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
session = hashmap_get(m->sessions, name);
if (!session)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
r = session_send_lock(session, streq(sd_bus_message_get_member(message), "LockSession"));
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_lock_sessions(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_lock_sessions(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
int r;
@@ -829,12 +821,12 @@ static int method_lock_sessions(sd_bus *bus, sd_bus_message *message, void *user
r = session_send_lock_all(m, streq(sd_bus_message_get_member(message), "LockSessions"));
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_kill_session(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_kill_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *name, *swho;
Manager *m = userdata;
Session *session;
@@ -848,31 +840,31 @@ static int method_kill_session(sd_bus *bus, sd_bus_message *message, void *userd
r = sd_bus_message_read(message, "ssi", &name, &swho, &signo);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (isempty(swho))
who = KILL_ALL;
else {
who = kill_who_from_string(swho);
if (who < 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
}
if (signo <= 0 || signo >= _NSIG)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
session = hashmap_get(m->sessions, name);
if (!session)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
r = session_kill(session, who, signo);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_kill_user(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_kill_user(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
uint32_t uid;
int32_t signo;
@@ -885,23 +877,23 @@ static int method_kill_user(sd_bus *bus, sd_bus_message *message, void *userdata
r = sd_bus_message_read(message, "ui", &uid, &signo);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (signo <= 0 || signo >= _NSIG)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
if (!user)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
r = user_kill(user, signo);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_terminate_session(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_terminate_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
const char *name;
Session *session;
@@ -913,20 +905,20 @@ static int method_terminate_session(sd_bus *bus, sd_bus_message *message, void *
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
session = hashmap_get(m->sessions, name);
if (!session)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
r = session_stop(session);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_terminate_user(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_terminate_user(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
uint32_t uid;
User *user;
@@ -938,20 +930,20 @@ static int method_terminate_user(sd_bus *bus, sd_bus_message *message, void *use
r = sd_bus_message_read(message, "u", &uid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
if (!user)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
r = user_stop(user);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_terminate_seat(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_terminate_seat(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
const char *name;
Seat *seat;
@@ -963,21 +955,20 @@ static int method_terminate_seat(sd_bus *bus, sd_bus_message *message, void *use
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
seat = hashmap_get(m->seats, name);
if (!seat)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SEAT, "No seat '%s' known", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SEAT, "No seat '%s' known", name);
r = seat_stop_sessions(seat);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_set_user_linger(sd_bus *bus, sd_bus_message *message, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_set_user_linger(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *cc = NULL;
Manager *m = userdata;
int b, r;
@@ -992,22 +983,22 @@ static int method_set_user_linger(sd_bus *bus, sd_bus_message *message, void *us
r = sd_bus_message_read(message, "ubb", &uid, &b, &interactive);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
errno = 0;
pw = getpwuid(uid);
if (!pw)
- return sd_bus_reply_method_errno(message, errno ? errno : ENOENT, NULL);
+ return errno ? -errno : -ENOENT;
r = bus_verify_polkit_async(bus,
&m->polkit_registry,
message,
"org.freedesktop.login1.set-user-linger",
interactive,
- &error,
+ error,
method_set_user_linger, m);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
@@ -1015,11 +1006,11 @@ static int method_set_user_linger(sd_bus *bus, sd_bus_message *message, void *us
r = mkdir_safe_label("/var/lib/systemd/linger", 0755, 0, 0);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
cc = cescape(pw->pw_name);
if (!cc)
- return sd_bus_reply_method_errno(message, ENOMEM, NULL);
+ return -ENOMEM;
path = strappenda("/var/lib/systemd/linger/", cc);
if (b) {
@@ -1027,7 +1018,7 @@ static int method_set_user_linger(sd_bus *bus, sd_bus_message *message, void *us
r = touch(path);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (manager_add_user_by_uid(m, uid, &u) >= 0)
user_start(u);
@@ -1037,7 +1028,7 @@ static int method_set_user_linger(sd_bus *bus, sd_bus_message *message, void *us
r = unlink(path);
if (r < 0 && errno != ENOENT)
- return sd_bus_reply_method_errno(message, errno, NULL);
+ return -errno;
u = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
if (u)
@@ -1178,8 +1169,7 @@ static int flush_devices(Manager *m) {
return trigger_device(m, NULL);
}
-static int method_attach_device(sd_bus *bus, sd_bus_message *message, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_attach_device(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *sysfs, *seat;
Manager *m = userdata;
int interactive, r;
@@ -1190,35 +1180,34 @@ static int method_attach_device(sd_bus *bus, sd_bus_message *message, void *user
r = sd_bus_message_read(message, "ssb", &seat, &sysfs, &interactive);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (!path_startswith(sysfs, "/sys"))
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not in /sys", sysfs);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not in /sys", sysfs);
if (!seat_name_is_valid(seat))
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Seat %s is not valid", seat);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Seat %s is not valid", seat);
r = bus_verify_polkit_async(bus,
&m->polkit_registry,
message,
"org.freedesktop.login1.attach-device",
interactive,
- &error,
+ error,
method_attach_device, m);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
r = attach_device(m, seat, sysfs);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_flush_devices(sd_bus *bus, sd_bus_message *message, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_flush_devices(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
int interactive, r;
@@ -1228,23 +1217,23 @@ static int method_flush_devices(sd_bus *bus, sd_bus_message *message, void *user
r = sd_bus_message_read(message, "b", &interactive);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = bus_verify_polkit_async(bus,
&m->polkit_registry,
message,
"org.freedesktop.login1.flush-devices",
interactive,
- &error,
+ error,
method_flush_devices, m);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
r = flush_devices(m);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
@@ -1432,9 +1421,9 @@ static int method_do_shutdown_or_sleep(
const char *action_multiple_sessions,
const char *action_ignore_inhibit,
const char *sleep_verb,
- sd_bus_message_handler_t method) {
+ sd_bus_message_handler_t method,
+ sd_bus_error *error) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
bool multiple_sessions, blocked;
int interactive, r;
uid_t uid;
@@ -1451,61 +1440,61 @@ static int method_do_shutdown_or_sleep(
r = sd_bus_message_read(message, "b", &interactive);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
/* Don't allow multiple jobs being executed at the same time */
if (m->action_what)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_OPERATION_IN_PROGRESS, "There's already a shutdown or sleep operation in progress");
+ return sd_bus_error_setf(error, BUS_ERROR_OPERATION_IN_PROGRESS, "There's already a shutdown or sleep operation in progress");
if (sleep_verb) {
r = can_sleep(sleep_verb);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (r == 0)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED, "Sleep verb not supported");
+ return sd_bus_error_setf(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED, "Sleep verb not supported");
}
r = sd_bus_get_owner_uid(m->bus, sd_bus_message_get_sender(message), &uid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = have_multiple_sessions(m, uid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
multiple_sessions = r > 0;
blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false, true, uid);
if (multiple_sessions) {
r = bus_verify_polkit_async(m->bus, &m->polkit_registry, message,
- action_multiple_sessions, interactive, &error, method, m);
+ action_multiple_sessions, interactive, error, method, m);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
}
if (blocked) {
r = bus_verify_polkit_async(m->bus, &m->polkit_registry, message,
- action_ignore_inhibit, interactive, &error, method, m);
+ action_ignore_inhibit, interactive, error, method, m);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
}
if (!multiple_sessions && !blocked) {
r = bus_verify_polkit_async(m->bus, &m->polkit_registry, message,
- action, interactive, &error, method, m);
+ action, interactive, error, method, m);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
}
- r = bus_manager_shutdown_or_sleep_now_or_later(m, unit_name, w, &error);
+ r = bus_manager_shutdown_or_sleep_now_or_later(m, unit_name, w, error);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_poweroff(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_poweroff(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
return method_do_shutdown_or_sleep(
@@ -1516,10 +1505,11 @@ static int method_poweroff(sd_bus *bus, sd_bus_message *message, void *userdata)
"org.freedesktop.login1.power-off-multiple-sessions",
"org.freedesktop.login1.power-off-ignore-inhibit",
NULL,
- method_poweroff);
+ method_poweroff,
+ error);
}
-static int method_reboot(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_reboot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
return method_do_shutdown_or_sleep(
@@ -1530,10 +1520,11 @@ static int method_reboot(sd_bus *bus, sd_bus_message *message, void *userdata) {
"org.freedesktop.login1.reboot-multiple-sessions",
"org.freedesktop.login1.reboot-ignore-inhibit",
NULL,
- method_reboot);
+ method_reboot,
+ error);
}
-static int method_suspend(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_suspend(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
return method_do_shutdown_or_sleep(
@@ -1544,10 +1535,11 @@ static int method_suspend(sd_bus *bus, sd_bus_message *message, void *userdata)
"org.freedesktop.login1.suspend-multiple-sessions",
"org.freedesktop.login1.suspend-ignore-inhibit",
"suspend",
- method_suspend);
+ method_suspend,
+ error);
}
-static int method_hibernate(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_hibernate(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
return method_do_shutdown_or_sleep(
@@ -1558,10 +1550,11 @@ static int method_hibernate(sd_bus *bus, sd_bus_message *message, void *userdata
"org.freedesktop.login1.hibernate-multiple-sessions",
"org.freedesktop.login1.hibernate-ignore-inhibit",
"hibernate",
- method_hibernate);
+ method_hibernate,
+ error);
}
-static int method_hybrid_sleep(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_hybrid_sleep(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
return method_do_shutdown_or_sleep(
@@ -1572,7 +1565,8 @@ static int method_hybrid_sleep(sd_bus *bus, sd_bus_message *message, void *userd
"org.freedesktop.login1.hibernate-multiple-sessions",
"org.freedesktop.login1.hibernate-ignore-inhibit",
"hybrid-sleep",
- method_hybrid_sleep);
+ method_hybrid_sleep,
+ error);
}
static int method_can_shutdown_or_sleep(
@@ -1582,9 +1576,9 @@ static int method_can_shutdown_or_sleep(
const char *action,
const char *action_multiple_sessions,
const char *action_ignore_inhibit,
- const char *sleep_verb) {
+ const char *sleep_verb,
+ sd_bus_error *error) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
bool multiple_sessions, challenge, blocked;
const char *result = NULL;
uid_t uid;
@@ -1601,26 +1595,26 @@ static int method_can_shutdown_or_sleep(
if (sleep_verb) {
r = can_sleep(sleep_verb);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (r == 0)
return sd_bus_reply_method_return(message, "s", "na");
}
r = sd_bus_get_owner_uid(m->bus, sd_bus_message_get_sender(message), &uid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = have_multiple_sessions(m, uid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
multiple_sessions = r > 0;
blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false, true, uid);
if (multiple_sessions) {
- r = bus_verify_polkit(m->bus, message, action_multiple_sessions, false, &challenge, &error);
+ r = bus_verify_polkit(m->bus, message, action_multiple_sessions, false, &challenge, error);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
if (r > 0)
result = "yes";
@@ -1631,9 +1625,9 @@ static int method_can_shutdown_or_sleep(
}
if (blocked) {
- r = bus_verify_polkit(m->bus, message, action_ignore_inhibit, false, &challenge, &error);
+ r = bus_verify_polkit(m->bus, message, action_ignore_inhibit, false, &challenge, error);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
if (r > 0 && !result)
result = "yes";
@@ -1647,9 +1641,9 @@ static int method_can_shutdown_or_sleep(
/* If neither inhibit nor multiple sessions
* apply then just check the normal policy */
- r = bus_verify_polkit(m->bus, message, action, false, &challenge, &error);
+ r = bus_verify_polkit(m->bus, message, action, false, &challenge, error);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
if (r > 0)
result = "yes";
@@ -1662,7 +1656,7 @@ static int method_can_shutdown_or_sleep(
return sd_bus_reply_method_return(message, "s", result);
}
-static int method_can_poweroff(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_can_poweroff(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
return method_can_shutdown_or_sleep(
@@ -1671,10 +1665,11 @@ static int method_can_poweroff(sd_bus *bus, sd_bus_message *message, void *userd
"org.freedesktop.login1.power-off",
"org.freedesktop.login1.power-off-multiple-sessions",
"org.freedesktop.login1.power-off-ignore-inhibit",
- NULL);
+ NULL,
+ error);
}
-static int method_can_reboot(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_can_reboot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
return method_can_shutdown_or_sleep(
@@ -1683,10 +1678,11 @@ static int method_can_reboot(sd_bus *bus, sd_bus_message *message, void *userdat
"org.freedesktop.login1.reboot",
"org.freedesktop.login1.reboot-multiple-sessions",
"org.freedesktop.login1.reboot-ignore-inhibit",
- NULL);
+ NULL,
+ error);
}
-static int method_can_suspend(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_can_suspend(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
return method_can_shutdown_or_sleep(
@@ -1695,10 +1691,11 @@ static int method_can_suspend(sd_bus *bus, sd_bus_message *message, void *userda
"org.freedesktop.login1.suspend",
"org.freedesktop.login1.suspend-multiple-sessions",
"org.freedesktop.login1.suspend-ignore-inhibit",
- "suspend");
+ "suspend",
+ error);
}
-static int method_can_hibernate(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_can_hibernate(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
return method_can_shutdown_or_sleep(
@@ -1707,10 +1704,11 @@ static int method_can_hibernate(sd_bus *bus, sd_bus_message *message, void *user
"org.freedesktop.login1.hibernate",
"org.freedesktop.login1.hibernate-multiple-sessions",
"org.freedesktop.login1.hibernate-ignore-inhibit",
- "hibernate");
+ "hibernate",
+ error);
}
-static int method_can_hybrid_sleep(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_can_hybrid_sleep(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
return method_can_shutdown_or_sleep(
@@ -1719,11 +1717,11 @@ static int method_can_hybrid_sleep(sd_bus *bus, sd_bus_message *message, void *u
"org.freedesktop.login1.hibernate",
"org.freedesktop.login1.hibernate-multiple-sessions",
"org.freedesktop.login1.hibernate-ignore-inhibit",
- "hybrid-sleep");
+ "hybrid-sleep",
+ error);
}
-static int method_inhibit(sd_bus *bus, sd_bus_message *message, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_inhibit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *who, *why, *what, *mode;
_cleanup_free_ char *id = NULL;
_cleanup_close_ int fifo_fd = -1;
@@ -1741,26 +1739,26 @@ static int method_inhibit(sd_bus *bus, sd_bus_message *message, void *userdata)
r = sd_bus_message_read(message, "ssss", &what, &who, &why, &mode);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
w = inhibit_what_from_string(what);
if (w <= 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid what specification %s", what);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid what specification %s", what);
mm = inhibit_mode_from_string(mode);
if (mm < 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid mode specification %s", mode);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid mode specification %s", mode);
/* Delay is only supported for shutdown/sleep */
if (mm == INHIBIT_DELAY && (w & ~(INHIBIT_SHUTDOWN|INHIBIT_SLEEP)))
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Delay inhibitors only supported for shutdown and sleep");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Delay inhibitors only supported for shutdown and sleep");
/* Don't allow taking delay locks while we are already
* executing the operation. We shouldn't create the impression
* that the lock was successful if the machine is about to go
* down/suspend any moment. */
if (m->action_what & w)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_OPERATION_IN_PROGRESS, "The operation inhibition has been requested for is already running");
+ return sd_bus_error_setf(error, BUS_ERROR_OPERATION_IN_PROGRESS, "The operation inhibition has been requested for is already running");
r = bus_verify_polkit_async(bus, &m->polkit_registry, message,
w == INHIBIT_SHUTDOWN ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-shutdown" : "org.freedesktop.login1.inhibit-delay-shutdown") :
@@ -1770,32 +1768,32 @@ static int method_inhibit(sd_bus *bus, sd_bus_message *message, void *userdata)
w == INHIBIT_HANDLE_SUSPEND_KEY ? "org.freedesktop.login1.inhibit-handle-suspend-key" :
w == INHIBIT_HANDLE_HIBERNATE_KEY ? "org.freedesktop.login1.inhibit-handle-hibernate-key" :
"org.freedesktop.login1.inhibit-handle-lid-switch",
- false, &error, method_inhibit, m);
+ false, error, method_inhibit, m);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, &error);
+ return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
r = sd_bus_get_owner_uid(m->bus, sd_bus_message_get_sender(message), &uid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = sd_bus_get_owner_pid(m->bus, sd_bus_message_get_sender(message), &pid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
do {
free(id);
id = NULL;
if (asprintf(&id, "%lu", ++m->inhibit_counter) < 0)
- return sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ return -ENOMEM;
} while (hashmap_get(m->inhibitors, id));
r = manager_add_inhibitor(m, id, &i);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
i->what = w;
i->mode = mm;
@@ -1805,13 +1803,13 @@ static int method_inhibit(sd_bus *bus, sd_bus_message *message, void *userdata)
i->who = strdup(who);
if (!i->why || !i->who) {
- r = sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ r = -ENOMEM;
goto fail;
}
fifo_fd = inhibitor_create_fifo(i);
if (fifo_fd < 0) {
- r = sd_bus_reply_method_errno(message, fifo_fd, NULL);
+ r = fifo_fd;
goto fail;
}
@@ -1897,7 +1895,7 @@ const sd_bus_vtable manager_vtable[] = {
SD_BUS_VTABLE_END
};
-int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
+int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *path, *result, *unit;
Manager *m = userdata;
Session *session;
@@ -1911,8 +1909,8 @@ int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
r = sd_bus_message_read(message, "uoss", &id, &path, &unit, &result);
if (r < 0) {
- log_error("Failed to parse JobRemoved message: %s", strerror(-r));
- return 0;
+ bus_log_parse_error(r);
+ return r;
}
if (m->action_job && streq(m->action_job, path)) {
@@ -1940,10 +1938,10 @@ int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
if (streq(result, "done"))
session_send_create_reply(session, NULL);
else {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_bus_error_free_ sd_bus_error e = SD_BUS_ERROR_NULL;
- sd_bus_error_setf(&error, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
- session_send_create_reply(session, &error);
+ sd_bus_error_setf(&e, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
+ session_send_create_reply(session, &e);
}
} else
session_save(session);
@@ -1971,7 +1969,7 @@ int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
return 0;
}
-int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
+int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *path, *unit;
Manager *m = userdata;
Session *session;
@@ -1984,8 +1982,8 @@ int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
r = sd_bus_message_read(message, "so", &unit, &path);
if (r < 0) {
- log_error("Failed to parse UnitRemoved message: %s", strerror(-r));
- return 0;
+ bus_log_parse_error(r);
+ return r;
}
session = hashmap_get(m->session_units, unit);
@@ -1999,12 +1997,13 @@ int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
return 0;
}
-int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata) {
+int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *unit = NULL;
Manager *m = userdata;
const char *path;
Session *session;
User *user;
+ int r;
assert(bus);
assert(message);
@@ -2014,9 +2013,9 @@ int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdat
if (!path)
return 0;
- unit_name_from_dbus_path(path, &unit);
- if (!unit)
- return 0;
+ r = unit_name_from_dbus_path(path, &unit);
+ if (r < 0)
+ return r;
session = hashmap_get(m->session_units, unit);
if (session)
@@ -2029,7 +2028,7 @@ int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdat
return 0;
}
-int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata) {
+int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
Session *session;
Iterator i;
@@ -2039,8 +2038,8 @@ int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata) {
r = sd_bus_message_read(message, "b", &b);
if (r < 0) {
- log_error("Failed to parse Reloading message: %s", strerror(-r));
- return 0;
+ bus_log_parse_error(r);
+ return r;
}
if (b)
@@ -2055,7 +2054,7 @@ int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata) {
return 0;
}
-int match_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata) {
+int match_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *name, *old, *new;
Manager *m = userdata;
Session *session;
@@ -2067,8 +2066,8 @@ int match_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdat
r = sd_bus_message_read(message, "sss", &name, &old, &new);
if (r < 0) {
- log_error("Failed to parse NameOwnerChanged message: %s", strerror(-r));
- return 0;
+ bus_log_parse_error(r);
+ return r;
}
if (isempty(old) || !isempty(new))
diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c
index 02dbc625ca..488d007c7e 100644
--- a/src/login/logind-seat-dbus.c
+++ b/src/login/logind-seat-dbus.c
@@ -35,8 +35,8 @@ static int property_get_active_session(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
Seat *s = userdata;
@@ -58,8 +58,8 @@ static int property_get_can_multi_session(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Seat *s = userdata;
@@ -76,8 +76,8 @@ static int property_get_can_tty(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Seat *s = userdata;
@@ -94,8 +94,8 @@ static int property_get_can_graphical(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Seat *s = userdata;
@@ -112,8 +112,8 @@ static int property_get_sessions(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Seat *s = userdata;
Session *session;
@@ -153,8 +153,8 @@ static int property_get_idle_hint(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Seat *s = userdata;
@@ -171,8 +171,8 @@ static int property_get_idle_since_hint(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Seat *s = userdata;
dual_timestamp t;
@@ -192,7 +192,7 @@ static int property_get_idle_since_hint(
return sd_bus_message_append(reply, "t", u);
}
-static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Seat *s = userdata;
int r;
@@ -202,12 +202,12 @@ static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata
r = seat_stop_sessions(s);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_activate_session(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_activate_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Seat *s = userdata;
const char *name;
Session *session;
@@ -219,18 +219,18 @@ static int method_activate_session(sd_bus *bus, sd_bus_message *message, void *u
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
session = hashmap_get(s->manager->sessions, name);
if (!session)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
if (session->seat != s)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_SESSION_NOT_ON_SEAT, "Session %s not on seat %s", name, s->id);
+ return sd_bus_error_setf(error, BUS_ERROR_SESSION_NOT_ON_SEAT, "Session %s not on seat %s", name, s->id);
r = session_activate(session);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
index bf4cccbd17..d2e2364fc2 100644
--- a/src/login/logind-session-dbus.c
+++ b/src/login/logind-session-dbus.c
@@ -37,8 +37,8 @@ static int property_get_user(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
Session *s = userdata;
@@ -60,8 +60,8 @@ static int property_get_name(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Session *s = userdata;
@@ -78,8 +78,8 @@ static int property_get_seat(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
Session *s = userdata;
@@ -104,8 +104,8 @@ static int property_get_active(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Session *s = userdata;
@@ -122,8 +122,8 @@ static int property_get_state(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Session *s = userdata;
@@ -140,8 +140,8 @@ static int property_get_idle_hint(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Session *s = userdata;
@@ -158,8 +158,8 @@ static int property_get_idle_since_hint(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Session *s = userdata;
dual_timestamp t;
@@ -179,7 +179,7 @@ static int property_get_idle_since_hint(
return sd_bus_message_append(reply, "t", u);
}
-static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Session *s = userdata;
int r;
@@ -189,12 +189,12 @@ static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata
r = session_stop(s);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_activate(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_activate(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Session *s = userdata;
int r;
@@ -204,12 +204,12 @@ static int method_activate(sd_bus *bus, sd_bus_message *message, void *userdata)
r = session_activate(s);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_lock(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_lock(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Session *s = userdata;
int r;
@@ -219,12 +219,12 @@ static int method_lock(sd_bus *bus, sd_bus_message *message, void *userdata) {
r = session_send_lock(s, streq(sd_bus_message_get_member(message), "Lock"));
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_set_idle_hint(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_set_idle_hint(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Session *s = userdata;
uid_t uid;
int r, b;
@@ -235,21 +235,21 @@ static int method_set_idle_hint(sd_bus *bus, sd_bus_message *message, void *user
r = sd_bus_message_read(message, "b", &b);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = sd_bus_get_owner_uid(bus, sd_bus_message_get_sender(message), &uid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (uid != 0 && uid != s->user->uid)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_ACCESS_DENIED, "Only owner of session my set idle hint");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED, "Only owner of session my set idle hint");
session_set_idle_hint(s, b);
return sd_bus_reply_method_return(message, NULL);
}
-static int method_kill(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_kill(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Session *s = userdata;
const char *swho;
int32_t signo;
@@ -262,27 +262,27 @@ static int method_kill(sd_bus *bus, sd_bus_message *message, void *userdata) {
r = sd_bus_message_read(message, "si", &swho, &signo);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (isempty(swho))
who = KILL_ALL;
else {
who = kill_who_from_string(swho);
if (who < 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
}
if (signo <= 0 || signo >= _NSIG)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
r = session_kill(s, who, signo);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_take_control(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_take_control(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Session *s = userdata;
int r, force;
uid_t uid;
@@ -293,23 +293,23 @@ static int method_take_control(sd_bus *bus, sd_bus_message *message, void *userd
r = sd_bus_message_read(message, "b", &force);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = sd_bus_get_owner_uid(bus, sd_bus_message_get_sender(message), &uid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (uid != 0 && (force || uid != s->user->uid))
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_ACCESS_DENIED, "Only owner of session may take control");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED, "Only owner of session may take control");
r = session_set_controller(s, sd_bus_message_get_sender(message), force);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_release_control(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_release_control(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Session *s = userdata;
assert(bus);
@@ -317,14 +317,14 @@ static int method_release_control(sd_bus *bus, sd_bus_message *message, void *us
assert(s);
if (!session_is_controller(s, sd_bus_message_get_sender(message)))
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
+ return sd_bus_error_setf(error, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
session_drop_controller(s);
return sd_bus_reply_method_return(message, NULL);
}
-static int method_take_device(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_take_device(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Session *s = userdata;
uint32_t major, minor;
SessionDevice *sd;
@@ -337,10 +337,10 @@ static int method_take_device(sd_bus *bus, sd_bus_message *message, void *userda
r = sd_bus_message_read(message, "uu", &major, &minor);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (!session_is_controller(s, sd_bus_message_get_sender(message)))
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
+ return sd_bus_error_setf(error, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
dev = makedev(major, minor);
sd = hashmap_get(s->devices, &dev);
@@ -350,11 +350,11 @@ static int method_take_device(sd_bus *bus, sd_bus_message *message, void *userda
* The caller should use dup() if it requires more
* than one fd (it would be functionally
* equivalent). */
- return sd_bus_reply_method_errorf(message, BUS_ERROR_DEVICE_IS_TAKEN, "Device already taken");
+ return sd_bus_error_setf(error, BUS_ERROR_DEVICE_IS_TAKEN, "Device already taken");
r = session_device_new(s, dev, &sd);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
r = sd_bus_reply_method_return(message, "hb", sd->fd, !sd->active);
if (r < 0)
@@ -363,7 +363,7 @@ static int method_take_device(sd_bus *bus, sd_bus_message *message, void *userda
return r;
}
-static int method_release_device(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_release_device(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Session *s = userdata;
uint32_t major, minor;
SessionDevice *sd;
@@ -376,21 +376,21 @@ static int method_release_device(sd_bus *bus, sd_bus_message *message, void *use
r = sd_bus_message_read(message, "uu", &major, &minor);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (!session_is_controller(s, sd_bus_message_get_sender(message)))
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
+ return sd_bus_error_setf(error, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
dev = makedev(major, minor);
sd = hashmap_get(s->devices, &dev);
if (!sd)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_DEVICE_NOT_TAKEN, "Device not taken");
+ return sd_bus_error_setf(error, BUS_ERROR_DEVICE_NOT_TAKEN, "Device not taken");
session_device_free(sd);
return sd_bus_reply_method_return(message, NULL);
}
-static int method_pause_device_complete(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_pause_device_complete(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Session *s = userdata;
uint32_t major, minor;
SessionDevice *sd;
@@ -403,15 +403,15 @@ static int method_pause_device_complete(sd_bus *bus, sd_bus_message *message, vo
r = sd_bus_message_read(message, "uu", &major, &minor);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (!session_is_controller(s, sd_bus_message_get_sender(message)))
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
+ return sd_bus_error_setf(error, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
dev = makedev(major, minor);
sd = hashmap_get(s->devices, &dev);
if (!sd)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_DEVICE_NOT_TAKEN, "Device not taken");
+ return sd_bus_error_setf(error, BUS_ERROR_DEVICE_NOT_TAKEN, "Device not taken");
session_device_complete_pause(sd);
diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c
index cf106c6013..3942fa9bec 100644
--- a/src/login/logind-user-dbus.c
+++ b/src/login/logind-user-dbus.c
@@ -34,8 +34,8 @@ static int property_get_display(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
User *u = userdata;
@@ -57,8 +57,8 @@ static int property_get_state(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
User *u = userdata;
@@ -75,8 +75,8 @@ static int property_get_sessions(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
User *u = userdata;
Session *session;
@@ -116,8 +116,8 @@ static int property_get_idle_hint(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
User *u = userdata;
@@ -134,8 +134,8 @@ static int property_get_idle_since_hint(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
User *u = userdata;
dual_timestamp t;
@@ -157,8 +157,8 @@ static int property_get_linger(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
User *u = userdata;
int r;
@@ -172,7 +172,7 @@ static int property_get_linger(
return sd_bus_message_append(reply, "b", r > 0);
}
-static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
User *u = userdata;
int r;
@@ -182,12 +182,12 @@ static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata
r = user_stop(u);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_kill(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_kill(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
User *u = userdata;
int32_t signo;
int r;
@@ -198,14 +198,14 @@ static int method_kill(sd_bus *bus, sd_bus_message *message, void *userdata) {
r = sd_bus_message_read(message, "i", &signo);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (signo <= 0 || signo >= _NSIG)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
r = user_kill(u, signo);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
diff --git a/src/login/logind.h b/src/login/logind.h
index 5c04d0a828..814964ff9d 100644
--- a/src/login/logind.h
+++ b/src/login/logind.h
@@ -150,11 +150,11 @@ int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
extern const sd_bus_vtable manager_vtable[];
-int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata);
-int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata);
-int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata);
-int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata);
-int match_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata);
+int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
+int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
+int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
+int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
+int match_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, const char *unit_name, InhibitWhat w, sd_bus_error *error);
diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c
index 8e671edba3..2c7f3a798e 100644
--- a/src/machine/machine-dbus.c
+++ b/src/machine/machine-dbus.c
@@ -32,8 +32,8 @@ static int property_get_id(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Machine *m = userdata;
int r;
@@ -55,8 +55,8 @@ static int property_get_state(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
Machine *m = userdata;
const char *state;
@@ -77,7 +77,7 @@ static int property_get_state(
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_class, machine_class, MachineClass);
-static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Machine *m = userdata;
int r;
@@ -87,12 +87,12 @@ static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata
r = machine_stop(m);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
-static int method_kill(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_kill(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Machine *m = userdata;
const char *swho;
int32_t signo;
@@ -105,22 +105,22 @@ static int method_kill(sd_bus *bus, sd_bus_message *message, void *userdata) {
r = sd_bus_message_read(message, "si", &swho, &signo);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (isempty(swho))
who = KILL_ALL;
else {
who = kill_who_from_string(swho);
if (who < 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
}
if (signo <= 0 || signo >= _NSIG)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
r = machine_kill(m, who, signo);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
return sd_bus_reply_method_return(message, NULL);
}
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index 2bf18a2b6e..eda582ae83 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -58,7 +58,7 @@ static bool valid_machine_name(const char *p) {
return true;
}
-static int method_get_machine(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_get_machine(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
Manager *m = userdata;
Machine *machine;
@@ -71,20 +71,20 @@ static int method_get_machine(sd_bus *bus, sd_bus_message *message, void *userda
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
machine = hashmap_get(m->machines, name);
if (!machine)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
p = machine_bus_path(machine);
if (!p)
- return sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ return -ENOMEM;
return sd_bus_reply_method_return(message, "o", p);
}
-static int method_get_machine_by_pid(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_get_machine_by_pid(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
Manager *m = userdata;
Machine *machine = NULL;
@@ -99,28 +99,28 @@ static int method_get_machine_by_pid(sd_bus *bus, sd_bus_message *message, void
r = sd_bus_message_read(message, "u", &pid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (pid == 0) {
r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
}
r = manager_get_machine_by_pid(m, pid, &machine);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (!machine)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_MACHINE_FOR_PID, "PID %lu does not belong to any known machine", (unsigned long) pid);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_MACHINE_FOR_PID, "PID %lu does not belong to any known machine", (unsigned long) pid);
p = machine_bus_path(machine);
if (!p)
- return sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ return -ENOMEM;
return sd_bus_reply_method_return(message, "o", p);
}
-static int method_list_machines(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_list_machines(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
Manager *m = userdata;
Machine *machine;
@@ -133,18 +133,18 @@ static int method_list_machines(sd_bus *bus, sd_bus_message *message, void *user
r = sd_bus_message_new_method_return(message, &reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return sd_bus_error_set_errno(error, r);
r = sd_bus_message_open_container(reply, 'a', "(ssso)");
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return sd_bus_error_set_errno(error, r);
HASHMAP_FOREACH(machine, m->machines, i) {
_cleanup_free_ char *p = NULL;
p = machine_bus_path(machine);
if (!p)
- return sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ return -ENOMEM;
r = sd_bus_message_append(reply, "(ssso)",
machine->name,
@@ -152,18 +152,17 @@ static int method_list_machines(sd_bus *bus, sd_bus_message *message, void *user
machine->service,
p);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return sd_bus_error_set_errno(error, r);
}
r = sd_bus_message_close_container(reply);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return sd_bus_error_set_errno(error, r);
return sd_bus_send(bus, reply, NULL);
}
-static int method_create_machine(sd_bus *bus, sd_bus_message *message, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_create_machine(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *name, *service, *class, *root_directory;
Manager *manager = userdata;
MachineClass c;
@@ -180,56 +179,56 @@ static int method_create_machine(sd_bus *bus, sd_bus_message *message, void *use
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (!valid_machine_name(name))
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine name");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine name");
r = sd_bus_message_read_array(message, 'y', &v, &n);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (n == 0)
id = SD_ID128_NULL;
else if (n == 16)
memcpy(&id, v, n);
else
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine ID parameter");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine ID parameter");
r = sd_bus_message_read(message, "ssus", &service, &class, &leader, &root_directory);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (isempty(class))
c = _MACHINE_CLASS_INVALID;
else {
c = machine_class_from_string(class);
if (c < 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine class parameter");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine class parameter");
}
if (leader == 1)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid leader PID");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid leader PID");
if (!isempty(root_directory) && !path_is_absolute(root_directory))
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Root directory must be empty or an absolute path");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Root directory must be empty or an absolute path");
r = sd_bus_message_enter_container(message, 'a', "(sv)");
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
if (leader == 0) {
assert_cc(sizeof(uint32_t) == sizeof(pid_t));
r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), (pid_t*) &leader);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
}
if (hashmap_get(manager->machines, name))
- return sd_bus_reply_method_errorf(message, BUS_ERROR_MACHINE_EXISTS, "Machine '%s' already exists", name);
+ return sd_bus_error_setf(error, BUS_ERROR_MACHINE_EXISTS, "Machine '%s' already exists", name);
r = manager_add_machine(manager, name, &m);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return r;
m->leader = leader;
m->class = c;
@@ -238,7 +237,7 @@ static int method_create_machine(sd_bus *bus, sd_bus_message *message, void *use
if (!isempty(service)) {
m->service = strdup(service);
if (!m->service) {
- r = sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ r = -ENOMEM;
goto fail;
}
}
@@ -246,16 +245,14 @@ static int method_create_machine(sd_bus *bus, sd_bus_message *message, void *use
if (!isempty(root_directory)) {
m->root_directory = strdup(root_directory);
if (!m->root_directory) {
- r = sd_bus_reply_method_errno(message, -ENOMEM, NULL);
+ r = -ENOMEM;
goto fail;
}
}
- r = machine_start(m, message, &error);
- if (r < 0) {
- r = sd_bus_reply_method_errno(message, r, &error);
+ r = machine_start(m, message, error);
+ if (r < 0)
goto fail;
- }
m->create_message = sd_bus_message_ref(message);
@@ -267,7 +264,7 @@ fail:
return r;
}
-static int method_terminate_machine(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_terminate_machine(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
Machine *machine;
const char *name;
@@ -279,20 +276,20 @@ static int method_terminate_machine(sd_bus *bus, sd_bus_message *message, void *
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return sd_bus_error_set_errno(error, r);
machine = hashmap_get(m->machines, name);
if (!machine)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
r = machine_stop(machine);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return sd_bus_error_set_errno(error, r);
return sd_bus_reply_method_return(message, NULL);
}
-static int method_kill_machine(sd_bus *bus, sd_bus_message *message, void *userdata) {
+static int method_kill_machine(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
Machine *machine;
const char *name;
@@ -307,26 +304,26 @@ static int method_kill_machine(sd_bus *bus, sd_bus_message *message, void *userd
r = sd_bus_message_read(message, "ssi", &name, &swho, &signo);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return sd_bus_error_set_errno(error, r);
if (isempty(swho))
who = KILL_ALL;
else {
who = kill_who_from_string(swho);
if (who < 0)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
}
if (signo <= 0 || signo >= _NSIG)
- return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
machine = hashmap_get(m->machines, name);
if (!machine)
- return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
r = machine_kill(machine, who, signo);
if (r < 0)
- return sd_bus_reply_method_errno(message, r, NULL);
+ return sd_bus_error_set_errno(error, r);
return sd_bus_reply_method_return(message, NULL);
}
@@ -344,7 +341,7 @@ const sd_bus_vtable manager_vtable[] = {
SD_BUS_VTABLE_END
};
-int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
+int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *path, *result, *unit;
Manager *m = userdata;
Machine *machine;
@@ -357,8 +354,8 @@ int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
r = sd_bus_message_read(message, "uoss", &id, &path, &unit, &result);
if (r < 0) {
- log_error("Failed to parse JobRemoved message: %s", strerror(-r));
- return 0;
+ bus_log_parse_error(r);
+ return r;
}
machine = hashmap_get(m->machine_units, unit);
@@ -373,11 +370,11 @@ int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
if (streq(result, "done"))
machine_send_create_reply(machine, NULL);
else {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_bus_error_free_ sd_bus_error e = SD_BUS_ERROR_NULL;
- sd_bus_error_setf(&error, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
+ sd_bus_error_setf(&e, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
- machine_send_create_reply(machine, &error);
+ machine_send_create_reply(machine, &e);
}
} else
machine_save(machine);
@@ -387,11 +384,12 @@ int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
return 0;
}
-int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata) {
+int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *unit = NULL;
Manager *m = userdata;
Machine *machine;
const char *path;
+ int r;
assert(bus);
assert(message);
@@ -401,9 +399,9 @@ int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdat
if (!path)
return 0;
- unit_name_from_dbus_path(path, &unit);
- if (!unit)
- return 0;
+ r = unit_name_from_dbus_path(path, &unit);
+ if (r < 0)
+ return r;
machine = hashmap_get(m->machine_units, unit);
if (machine)
@@ -412,7 +410,7 @@ int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdat
return 0;
}
-int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
+int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *path, *unit;
Manager *m = userdata;
Machine *machine;
@@ -424,8 +422,8 @@ int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
r = sd_bus_message_read(message, "so", &unit, &path);
if (r < 0) {
- log_error("Failed to parse UnitRemoved message: %s", strerror(-r));
- return 0;
+ bus_log_parse_error(r);
+ return r;
}
machine = hashmap_get(m->machine_units, unit);
@@ -435,7 +433,7 @@ int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
return 0;
}
-int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata) {
+int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
Machine *machine;
Iterator i;
@@ -445,10 +443,9 @@ int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata) {
r = sd_bus_message_read(message, "b", &b);
if (r < 0) {
- log_error("Failed to parse Reloading message: %s", strerror(-r));
- return 0;
+ bus_log_parse_error(r);
+ return r;
}
-
if (b)
return 0;
diff --git a/src/machine/machined.h b/src/machine/machined.h
index 3f07d4dd8e..0b074c4e8a 100644
--- a/src/machine/machined.h
+++ b/src/machine/machined.h
@@ -62,10 +62,10 @@ extern const sd_bus_vtable manager_vtable[];
int machine_node_enumerator(sd_bus *bus, const char *path, char ***nodes, void *userdata);
-int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata);
-int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata);
-int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata);
-int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata);
+int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
+int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
+int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
+int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
int manager_start_scope(Manager *manager, const char *scope, pid_t pid, const char *slice, const char *description, sd_bus_message *more_properties, sd_bus_error *error, char **job);
int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 84826a3829..bd443e98ce 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -1711,7 +1711,7 @@ typedef struct WaitData {
char *result;
} WaitData;
-static int wait_filter(sd_bus *bus, sd_bus_message *m, void *data) {
+static int wait_filter(sd_bus *bus, sd_bus_message *m, void *data, sd_bus_error *error) {
WaitData *d = data;
assert(bus);
@@ -1764,7 +1764,7 @@ static int wait_filter(sd_bus *bus, sd_bus_message *m, void *data) {
}
#endif
- log_error("Failed to parse message.");
+ bus_log_parse_error(r);
}
return 0;
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 9693f4bac6..582720815a 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -46,9 +46,9 @@ typedef struct {
/* Callbacks */
-typedef int (*sd_bus_message_handler_t)(sd_bus *bus, sd_bus_message *m, void *userdata);
-typedef int (*sd_bus_property_get_t) (sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata);
-typedef int (*sd_bus_property_set_t) (sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, sd_bus_error *error, void *userdata);
+typedef int (*sd_bus_message_handler_t)(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
+typedef int (*sd_bus_property_get_t) (sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *ret_error);
+typedef int (*sd_bus_property_set_t) (sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, void *userdata, sd_bus_error *ret_error);
typedef int (*sd_bus_object_find_t) (sd_bus *bus, const char *path, const char *interface, void **found, void *userdata);
typedef int (*sd_bus_node_enumerator_t) (sd_bus *bus, const char *path, char ***nodes, void *userdata);
@@ -95,7 +95,7 @@ int sd_bus_get_server_id(sd_bus *bus, sd_id128_t *peer);
int sd_bus_send(sd_bus *bus, sd_bus_message *m, uint64_t *serial);
int sd_bus_send_to(sd_bus *bus, sd_bus_message *m, const char *destination, uint64_t *serial);
-int sd_bus_call(sd_bus *bus, sd_bus_message *m, uint64_t usec, sd_bus_error *error, sd_bus_message **reply);
+int sd_bus_call(sd_bus *bus, sd_bus_message *m, uint64_t usec, sd_bus_error *ret_error, sd_bus_message **reply);
int sd_bus_call_async(sd_bus *bus, sd_bus_message *m, sd_bus_message_handler_t callback, void *userdata, uint64_t usec, uint64_t *serial);
int sd_bus_call_async_cancel(sd_bus *bus, uint64_t serial);
@@ -220,12 +220,12 @@ int sd_bus_message_rewind(sd_bus_message *m, int complete);
/* Convenience calls */
-int sd_bus_call_method(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *types, ...);
-int sd_bus_get_property(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *type);
-int sd_bus_get_property_trivial(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, char type, void *ptr);
-int sd_bus_get_property_string(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, char **ret); /* free the result! */
-int sd_bus_get_property_strv(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, char ***ret); /* free the result! */
-int sd_bus_set_property(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, const char *type, ...);
+int sd_bus_call_method(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, sd_bus_message **reply, const char *types, ...);
+int sd_bus_get_property(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, sd_bus_message **reply, const char *type);
+int sd_bus_get_property_trivial(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, char type, void *ret_ptr);
+int sd_bus_get_property_string(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, char **ret); /* free the result! */
+int sd_bus_get_property_strv(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, char ***ret); /* free the result! */
+int sd_bus_set_property(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, const char *ret_type, ...);
int sd_bus_reply_method_return(sd_bus_message *call, const char *types, ...);
int sd_bus_reply_method_error(sd_bus_message *call, const sd_bus_error *e);
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 735e090e62..a8261fee38 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -458,8 +458,8 @@ static int property_get_rtc_time(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
struct tm tm;
usec_t t;
@@ -470,17 +470,12 @@ static int property_get_rtc_time(
if (r == -EBUSY) {
log_warning("/dev/rtc is busy, is somebody keeping it open continously? That's not a good idea... Returning a bogus RTC timestamp.");
t = 0;
- } else if (r < 0) {
- sd_bus_error_set_errnof(error, -r, "Failed to read RTC: %s", strerror(-r));
- return r;
- } else
+ } else if (r < 0)
+ return sd_bus_error_set_errnof(error, r, "Failed to read RTC: %s", strerror(-r));
+ else
t = (usec_t) timegm(&tm) * USEC_PER_SEC;
- r = sd_bus_message_append(reply, "t", t);
- if (r < 0)
- return r;
-
- return 1;
+ return sd_bus_message_append(reply, "t", t);
}
static int property_get_time(
@@ -489,16 +484,10 @@ static int property_get_time(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
-
- int r;
-
- r = sd_bus_message_append(reply, "t", now(CLOCK_REALTIME));
- if (r < 0)
- return r;
+ void *userdata,
+ sd_bus_error *error) {
- return 1;
+ return sd_bus_message_append(reply, "t", now(CLOCK_REALTIME));
}
static int property_get_ntp_sync(
@@ -507,20 +496,13 @@ static int property_get_ntp_sync(
const char *interface,
const char *property,
sd_bus_message *reply,
- sd_bus_error *error,
- void *userdata) {
+ void *userdata,
+ sd_bus_error *error) {
- int r;
-
- r = sd_bus_message_append(reply, "b", ntp_synced());
- if (r < 0)
- return r;
-
- return 1;
+ return sd_bus_message_append(reply, "b", ntp_synced());
}
-static int method_set_timezone(sd_bus *bus, sd_bus_message *m, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_set_timezone(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
Context *c = userdata;
const char *z;
int interactive;
@@ -533,23 +515,23 @@ static int method_set_timezone(sd_bus *bus, sd_bus_message *m, void *userdata) {
r = sd_bus_message_read(m, "sb", &z, &interactive);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, NULL);
+ return r;
if (!valid_timezone(z))
- return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Invalid time zone '%s'", z);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid time zone '%s'", z);
if (streq_ptr(z, c->zone))
return sd_bus_reply_method_return(m, NULL);
- r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.timedate1.set-timezone", interactive, &error, method_set_timezone, c);
+ r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.timedate1.set-timezone", interactive, error, method_set_timezone, c);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, &error);
+ return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
t = strdup(z);
if (!t)
- return log_oom();
+ return -ENOMEM;
free(c->zone);
c->zone = t;
@@ -558,7 +540,7 @@ static int method_set_timezone(sd_bus *bus, sd_bus_message *m, void *userdata) {
r = context_write_data_timezone(c);
if (r < 0) {
log_error("Failed to set timezone: %s", strerror(-r));
- return sd_bus_reply_method_errnof(m, r, "Failed to set timezone: %s", strerror(-r));
+ return sd_bus_error_set_errnof(error, r, "Failed to set timezone: %s", strerror(-r));
}
/* 2. Tell the kernel our timezone */
@@ -585,8 +567,7 @@ static int method_set_timezone(sd_bus *bus, sd_bus_message *m, void *userdata) {
return sd_bus_reply_method_return(m, NULL);
}
-static int method_set_local_rtc(sd_bus *bus, sd_bus_message *m, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_set_local_rtc(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
int lrtc, fix_system, interactive;
Context *c = userdata;
struct timespec ts;
@@ -598,14 +579,14 @@ static int method_set_local_rtc(sd_bus *bus, sd_bus_message *m, void *userdata)
r = sd_bus_message_read(m, "bbb", &lrtc, &fix_system, &interactive);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, NULL);
+ return r;
if (lrtc == c->local_rtc)
return sd_bus_reply_method_return(m, NULL);
- r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.timedate1.set-local-rtc", interactive, &error, method_set_local_rtc, c);
+ r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.timedate1.set-local-rtc", interactive, error, method_set_local_rtc, c);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, &error);
+ return r;
if (r == 0)
return 1;
@@ -615,7 +596,7 @@ static int method_set_local_rtc(sd_bus *bus, sd_bus_message *m, void *userdata)
r = context_write_data_local_rtc(c);
if (r < 0) {
log_error("Failed to set RTC to local/UTC: %s", strerror(-r));
- return sd_bus_reply_method_errnof(m, r, "Failed to set RTC to local/UTC: %s", strerror(-r));
+ return sd_bus_error_set_errnof(error, r, "Failed to set RTC to local/UTC: %s", strerror(-r));
}
/* 2. Tell the kernel our timezone */
@@ -669,8 +650,7 @@ static int method_set_local_rtc(sd_bus *bus, sd_bus_message *m, void *userdata)
return sd_bus_reply_method_return(m, NULL);
}
-static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
int relative, interactive;
Context *c = userdata;
int64_t utc;
@@ -684,10 +664,10 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata) {
r = sd_bus_message_read(m, "xbb", &utc, &relative, &interactive);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, NULL);
+ return r;
if (!relative && utc <= 0)
- return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Invalid absolute time");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid absolute time");
if (relative && utc == 0)
return sd_bus_reply_method_return(m, NULL);
@@ -700,22 +680,22 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata) {
if ((utc > 0 && x < n) ||
(utc < 0 && x > n))
- return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Time value overflow");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Time value overflow");
timespec_store(&ts, x);
} else
timespec_store(&ts, (usec_t) utc);
- r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.timedate1.set-time", interactive, &error, method_set_time, c);
+ r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.timedate1.set-time", interactive, error, method_set_time, c);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, &error);
+ return r;
if (r == 0)
return 1;
/* Set system clock */
if (clock_settime(CLOCK_REALTIME, &ts) < 0) {
log_error("Failed to set local time: %m");
- return sd_bus_reply_method_errnof(m, errno, "Failed to set local time: %m");
+ return sd_bus_error_set_errnof(error, errno, "Failed to set local time: %m");
}
/* Sync down to RTC */
@@ -735,34 +715,33 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata) {
return sd_bus_reply_method_return(m, NULL);
}
-static int method_set_ntp(sd_bus *bus, sd_bus_message *m, void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+static int method_set_ntp(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
int ntp, interactive;
Context *c = userdata;
int r;
r = sd_bus_message_read(m, "bb", &ntp, &interactive);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, NULL);
+ return r;
if ((bool)ntp == c->use_ntp)
return sd_bus_reply_method_return(m, NULL);
- r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.timedate1.set-ntp", interactive, &error, method_set_ntp, c);
+ r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.timedate1.set-ntp", interactive, error, method_set_ntp, c);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, &error);
+ return r;
if (r == 0)
return 1;
c->use_ntp = ntp;
- r = context_enable_ntp(c, bus, &error);
+ r = context_enable_ntp(c, bus, error);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, &error);
+ return r;
- r = context_start_ntp(c, bus, &error);
+ r = context_start_ntp(c, bus, error);
if (r < 0)
- return sd_bus_reply_method_errno(m, r, &error);
+ return r;
log_info("Set NTP to %s", c->use_ntp ? "enabled" : "disabled");