summaryrefslogtreecommitdiffstats
path: root/src/sbus
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2014-04-15 15:29:44 +0200
committerJakub Hrozek <jhrozek@redhat.com>2014-05-13 21:46:38 +0200
commit87729e3a6c56383642a8d3a86b2856487f2ee064 (patch)
treee70448d22bf0a7925736420e57793c654b7dcd3e /src/sbus
parent94f07a6f4375ec25d8fa5c99a0c4f68de7002457 (diff)
downloadsssd-87729e3a6c56383642a8d3a86b2856487f2ee064.tar.gz
sssd-87729e3a6c56383642a8d3a86b2856487f2ee064.tar.xz
sssd-87729e3a6c56383642a8d3a86b2856487f2ee064.zip
SBUS: Add a convenience function sbus_error_new
Adds a convenience function that constructs a DBusError on top of a talloc context and as such can be used to mark an sbus request as failed without having to create a DBusError instance by the caller. Reviewed-by: Pavel Březina <pbrezina@redhat.com> Reviewed-by: Stef Walter <stefw@redhat.com>
Diffstat (limited to 'src/sbus')
-rw-r--r--src/sbus/sssd_dbus.h16
-rw-r--r--src/sbus/sssd_dbus_request.c27
2 files changed, 43 insertions, 0 deletions
diff --git a/src/sbus/sssd_dbus.h b/src/sbus/sssd_dbus.h
index 3bf70c8cc..0fd499cbe 100644
--- a/src/sbus/sssd_dbus.h
+++ b/src/sbus/sssd_dbus.h
@@ -27,6 +27,7 @@ struct sbus_interface;
struct sbus_request;
#include <dbus/dbus.h>
+#include "util/util.h"
typedef int (*sbus_msg_handler_fn)(struct sbus_request *dbus_req,
void *instance_data);
@@ -253,6 +254,21 @@ int sbus_request_fail_and_finish(struct sbus_request *dbus_req,
const DBusError *error);
/*
+ * Construct a new DBusError instance which can be consumed by functions such
+ * as @sbus_request_fail_and_finish().
+ *
+ * The @error is a string constant representing a DBus error as documented at
+ * http://dbus.freedesktop.org/doc/api/html/group__DBusProtocol.html.
+ * The parameter @err_msg is a human-readable error representation (or
+ * NULL for none). The returned DBusError is a talloc context and the err_msg
+ * is duplicated using the returned DBusError instance as a talloc parent.
+ */
+DBusError *sbus_error_new(TALLOC_CTX *mem_ctx,
+ const char *dbus_err_name,
+ const char *fmt,
+ ...) SSS_ATTRIBUTE_PRINTF(3,4);
+
+/*
* Parse a DBus method call request.
*
* If parsing the method call message does not succeed, then an error is
diff --git a/src/sbus/sssd_dbus_request.c b/src/sbus/sssd_dbus_request.c
index d8b189095..0021ce0e9 100644
--- a/src/sbus/sssd_dbus_request.c
+++ b/src/sbus/sssd_dbus_request.c
@@ -143,6 +143,33 @@ int sbus_request_fail_and_finish(struct sbus_request *dbus_req,
return ret;
}
+DBusError *sbus_error_new(TALLOC_CTX *mem_ctx,
+ const char *dbus_err_name,
+ const char *fmt,
+ ...)
+{
+ DBusError *dberr;
+ const char *err_msg_dup = NULL;
+ va_list ap;
+
+ dberr = talloc(mem_ctx, DBusError);
+ if (dberr == NULL) return NULL;
+
+ if (fmt) {
+ va_start(ap, fmt);
+ err_msg_dup = talloc_vasprintf(dberr, fmt, ap);
+ va_end(ap);
+ if (err_msg_dup == NULL) {
+ talloc_free(dberr);
+ return NULL;
+ }
+ }
+
+ dbus_error_init(dberr);
+ dbus_set_error_const(dberr, dbus_err_name, err_msg_dup);
+ return dberr;
+}
+
struct array_arg {
char **dbus_array;
};