From 28a410f423bf9bcdf43ed14cd4c50634753b51f3 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Mon, 2 May 2011 10:04:44 -0400 Subject: Create common sss_monitor_init() This was implemented almost identically for both the responders and the providers. It is easier to maintain as a single routine. This patch also adds the ability to provide a private context to attach to the sbus_connection for later use. --- src/monitor/monitor_interfaces.h | 7 +++++++ src/monitor/monitor_sbus.c | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'src/monitor') diff --git a/src/monitor/monitor_interfaces.h b/src/monitor/monitor_interfaces.h index 4830f678..8ec6d89b 100644 --- a/src/monitor/monitor_interfaces.h +++ b/src/monitor/monitor_interfaces.h @@ -56,3 +56,10 @@ int monitor_common_res_init(DBusMessage *message, int monitor_common_rotate_logs(DBusMessage *message, struct sbus_connection *conn); +errno_t sss_monitor_init(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct sbus_interface *intf, + const char *svc_name, + uint16_t svc_version, + void *pvt, + struct sbus_connection **mon_conn); diff --git a/src/monitor/monitor_sbus.c b/src/monitor/monitor_sbus.c index c2106e86..3d0d9d31 100644 --- a/src/monitor/monitor_sbus.c +++ b/src/monitor/monitor_sbus.c @@ -27,6 +27,7 @@ #include "util/util.h" #include "confdb/confdb.h" #include "sbus/sssd_dbus.h" +#include "sbus/sbus_client.h" #include "monitor/monitor_interfaces.h" int monitor_get_sbus_address(TALLOC_CTX *mem_ctx, char **address) @@ -191,3 +192,44 @@ int monitor_common_rotate_logs(DBusMessage *message, return monitor_common_pong(message, conn); } + +errno_t sss_monitor_init(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct sbus_interface *intf, + const char *svc_name, + uint16_t svc_version, + void *pvt, + struct sbus_connection **mon_conn) +{ + errno_t ret; + char *sbus_address; + struct sbus_connection *conn; + + /* Set up SBUS connection to the monitor */ + ret = monitor_get_sbus_address(NULL, &sbus_address); + if (ret != EOK) { + DEBUG(0, ("Could not locate monitor address.\n")); + return ret; + } + + ret = sbus_client_init(mem_ctx, ev, sbus_address, + intf, &conn, + NULL, pvt); + if (ret != EOK) { + DEBUG(0, ("Failed to connect to monitor services.\n")); + talloc_free(sbus_address); + return ret; + } + talloc_free(sbus_address); + + /* Identify ourselves to the monitor */ + ret = monitor_common_send_id(conn, svc_name, svc_version); + if (ret != EOK) { + DEBUG(0, ("Failed to identify to the monitor!\n")); + return ret; + } + + *mon_conn = conn; + + return EOK; +} -- cgit