diff options
author | Pavel Březina <pbrezina@redhat.com> | 2016-06-29 12:35:59 +0200 |
---|---|---|
committer | Lukas Slebodnik <lslebodn@redhat.com> | 2016-08-16 14:39:04 +0200 |
commit | 439e08cdc5c83b3e5835cb0435983f1da2ffbaf1 (patch) | |
tree | 3eac78aca3d7c0667f6cd720c0322c53a64e0a35 /src/tools/sssctl | |
parent | a06e23c0bcf0c8669a29b801876aca8aac422931 (diff) | |
download | sssd-439e08cdc5c83b3e5835cb0435983f1da2ffbaf1.tar.gz sssd-439e08cdc5c83b3e5835cb0435983f1da2ffbaf1.tar.xz sssd-439e08cdc5c83b3e5835cb0435983f1da2ffbaf1.zip |
sbus: add utility function to simplify message and reply handling
This patch adds the ability to hook DBusMessage to a talloc context
to remove the need of calling dbus_message_unref(). It also provides
an automatical way to detect error in a reply so the caller does
not need to parse it manually and the whole code around DBusError
can be avoided.
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/tools/sssctl')
-rw-r--r-- | src/tools/sssctl/sssctl_domains.c | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/src/tools/sssctl/sssctl_domains.c b/src/tools/sssctl/sssctl_domains.c index cfc4e5613..17ad670f3 100644 --- a/src/tools/sssctl/sssctl_domains.c +++ b/src/tools/sssctl/sssctl_domains.c @@ -79,15 +79,11 @@ static errno_t sssctl_domain_status_online(struct sss_tool_ctx *tool_ctx, { sss_sifp_ctx *sifp; sss_sifp_error sifp_error; - DBusError dbus_error; DBusMessage *reply = NULL; - DBusMessage *msg = NULL; + DBusMessage *msg; bool is_online; - dbus_bool_t dbret; errno_t ret; - dbus_error_init(&dbus_error); - if (!sssctl_start_sssd(force_start)) { ret = ERR_SSSD_NOT_RUNNING; goto done; @@ -100,16 +96,15 @@ static errno_t sssctl_domain_status_online(struct sss_tool_ctx *tool_ctx, goto done; } - - msg = sss_sifp_create_message(domain_path, IFACE_IFP_DOMAINS_DOMAIN, - IFACE_IFP_DOMAINS_DOMAIN_ISONLINE); + msg = sbus_create_message(tool_ctx, SSS_SIFP_ADDRESS, domain_path, + IFACE_IFP_DOMAINS_DOMAIN, + IFACE_IFP_DOMAINS_DOMAIN_ISONLINE); if (msg == NULL) { DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create D-Bus message\n"); ret = ENOMEM; goto done; } - sifp_error = sss_sifp_send_message(sifp, msg, &reply); if (sifp_error != SSS_SIFP_OK) { sssctl_sifp_error(sifp, sifp_error, "Unable to get online status"); @@ -117,16 +112,9 @@ static errno_t sssctl_domain_status_online(struct sss_tool_ctx *tool_ctx, goto done; } - dbret = dbus_message_get_args(reply, &dbus_error, - DBUS_TYPE_BOOLEAN, &is_online, - DBUS_TYPE_INVALID); - if (!dbret) { - DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse D-Bus reply\n"); - if (dbus_error_is_set(&dbus_error)) { - DEBUG(SSSDBG_CRIT_FAILURE, "%s: %s\n", - dbus_error.name, dbus_error.message); - } - ret = EIO; + ret = sbus_parse_reply(reply, DBUS_TYPE_BOOLEAN, &is_online); + if (ret != EOK) { + fprintf(stderr, _("Unable to get information from SSSD\n")); goto done; } @@ -135,16 +123,10 @@ static errno_t sssctl_domain_status_online(struct sss_tool_ctx *tool_ctx, ret = EOK; done: - if (msg != NULL) { - dbus_message_unref(msg); - } - if (reply != NULL) { dbus_message_unref(reply); } - dbus_error_free(&dbus_error); - return ret; } |