summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus/bus-convenience.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-10-16 06:10:04 +0200
committerLennart Poettering <lennart@poettering.net>2013-10-16 06:15:02 +0200
commit40ca29a1370379d43e44c0ed425eecc7218dcbca (patch)
tree39cde46c8166bd79471b0111251693edddfae3c4 /src/libsystemd-bus/bus-convenience.c
parent7a37d62501c97eb3b48a418ef764d0308e0c3fb9 (diff)
timedated: use libsystemd-bus instead of libdbus for bus communication
Among other things this also adds a few things necessary for the change: - Considerably more powerful error returning APIs in libsystemd-bus - Adapter for connecting an sd_bus to an sd_event - As I reworked the PolicyKit logic to the new library I also made it asynchronous, so that PolicyKit requests of one user cannot block out another user anymore. - We always use the macro names for common bus error. That way it is harder to mistype them since the compiler will notice
Diffstat (limited to 'src/libsystemd-bus/bus-convenience.c')
-rw-r--r--src/libsystemd-bus/bus-convenience.c76
1 files changed, 61 insertions, 15 deletions
diff --git a/src/libsystemd-bus/bus-convenience.c b/src/libsystemd-bus/bus-convenience.c
index ddde5da163..95a7577b29 100644
--- a/src/libsystemd-bus/bus-convenience.c
+++ b/src/libsystemd-bus/bus-convenience.c
@@ -22,6 +22,7 @@
#include "bus-internal.h"
#include "bus-message.h"
#include "bus-signature.h"
+#include "bus-util.h"
int sd_bus_emit_signal(
sd_bus *bus,
@@ -99,7 +100,7 @@ int sd_bus_reply_method_return(
assert_return(bus, -EINVAL);
assert_return(call, -EINVAL);
assert_return(call->sealed, -EPERM);
- assert_return(call->header->type == SD_BUS_MESSAGE_TYPE_METHOD_CALL, -EINVAL);
+ assert_return(call->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
@@ -134,7 +135,7 @@ int sd_bus_reply_method_error(
assert_return(bus, -EINVAL);
assert_return(call, -EINVAL);
assert_return(call->sealed, -EPERM);
- assert_return(call->header->type == SD_BUS_MESSAGE_TYPE_METHOD_CALL, -EINVAL);
+ assert_return(call->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
assert_return(sd_bus_error_is_set(e), -EINVAL);
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
@@ -163,29 +164,74 @@ int sd_bus_reply_method_errorf(
assert_return(bus, -EINVAL);
assert_return(call, -EINVAL);
assert_return(call->sealed, -EPERM);
- assert_return(call->header->type == SD_BUS_MESSAGE_TYPE_METHOD_CALL, -EINVAL);
+ assert_return(call->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED)
return 0;
- error.name = strdup(name);
- if (!error.name)
- return -ENOMEM;
+ va_start(ap, format);
+ r = bus_error_setfv(&error, name, format, ap);
+ va_end(ap);
- error.need_free = true;
+ if (r < 0)
+ return r;
- if (format) {
- va_start(ap, format);
- r = vasprintf((char**) &error.message, format, ap);
- va_end(ap);
+ return sd_bus_reply_method_error(bus, call, &error);
+}
- if (r < 0)
- return -ENOMEM;
- }
+int sd_bus_reply_method_errno(
+ sd_bus *bus,
+ sd_bus_message *call,
+ int error,
+ const sd_bus_error *p) {
- return sd_bus_reply_method_error(bus, call, &error);
+ _cleanup_bus_error_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
+
+ assert_return(bus, -EINVAL);
+ assert_return(call, -EINVAL);
+ assert_return(call->sealed, -EPERM);
+ assert_return(call->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
+ assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+ assert_return(!bus_pid_changed(bus), -ECHILD);
+
+ if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED)
+ return 0;
+
+ if (sd_bus_error_is_set(p))
+ return sd_bus_reply_method_error(bus, call, p);
+
+ sd_bus_error_set_errno(&berror, error);
+
+ return sd_bus_reply_method_error(bus, call, &berror);
+}
+
+int sd_bus_reply_method_errnof(
+ sd_bus *bus,
+ sd_bus_message *call,
+ int error,
+ const char *format,
+ ...) {
+
+ _cleanup_bus_error_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
+ va_list ap;
+
+ assert_return(bus, -EINVAL);
+ assert_return(call, -EINVAL);
+ assert_return(call->sealed, -EPERM);
+ assert_return(call->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
+ assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+ assert_return(!bus_pid_changed(bus), -ECHILD);
+
+ if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED)
+ return 0;
+
+ va_start(ap, format);
+ bus_error_set_errnofv(&berror, error, format, ap);
+ va_end(ap);
+
+ return sd_bus_reply_method_error(bus, call, &berror);
}
int sd_bus_get_property(