From 11c621b5ee1a0cdc27610f8b172017764acc285e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 5 Aug 2009 14:11:12 -0400 Subject: Simplify interfaces initialization Make as much as possible static, and remove use of talloc_reference and allocation/deallocation of memory when not necessary. Fix also responder use of rctx->conn, was mistakenly used for both monitor and dp connections. --- server/monitor/monitor.c | 64 +++++++++++++++---------------------- server/monitor/monitor_interfaces.h | 23 +++++++------ server/monitor/monitor_sbus.c | 35 -------------------- server/monitor/monitor_sbus.h | 2 -- 4 files changed, 37 insertions(+), 87 deletions(-) (limited to 'server/monitor') diff --git a/server/monitor/monitor.c b/server/monitor/monitor.c index 7a27c4ec..81012071 100644 --- a/server/monitor/monitor.c +++ b/server/monitor/monitor.c @@ -171,45 +171,33 @@ static int dbus_get_monitor_version(DBusMessage *message, } struct sbus_method monitor_methods[] = { - { MONITOR_METHOD_VERSION, dbus_get_monitor_version}, - {NULL, NULL} + { MON_SRV_METHOD_VERSION, dbus_get_monitor_version }, + { NULL, NULL } +}; + +struct sbus_interface monitor_server_interface = { + MONITOR_DBUS_INTERFACE, + MONITOR_DBUS_PATH, + SBUS_DEFAULT_VTABLE, + monitor_methods, + NULL }; /* monitor_dbus_init * Set up the monitor service as a D-BUS Server */ static int monitor_dbus_init(struct mt_ctx *ctx) { - struct sbus_method_ctx *sd_ctx; char *monitor_address; int ret; - sd_ctx = talloc_zero(ctx, struct sbus_method_ctx); - if (!sd_ctx) { - return ENOMEM; - } - - monitor_address = talloc_asprintf(sd_ctx, "unix:path=%s/%s", + monitor_address = talloc_asprintf(ctx, "unix:path=%s/%s", PIPE_PATH, SSSD_SERVICE_PIPE); if (!monitor_address) { - talloc_free(sd_ctx); - return ENOMEM; - } - - /* Set up globally-available D-BUS methods */ - sd_ctx->interface = talloc_strdup(sd_ctx, MONITOR_DBUS_INTERFACE); - if (!sd_ctx->interface) { - talloc_free(sd_ctx); - return ENOMEM; - } - sd_ctx->path = talloc_strdup(sd_ctx, MONITOR_DBUS_PATH); - if (!sd_ctx->path) { - talloc_free(sd_ctx); return ENOMEM; } - sd_ctx->methods = monitor_methods; - sd_ctx->message_handler = sbus_message_handler; - ret = sbus_new_server(ctx, ctx->ev, monitor_address, sd_ctx, + ret = sbus_new_server(ctx, ctx->ev, + monitor_address, &monitor_server_interface, &ctx->sbus_srv, dbus_service_init, ctx); talloc_free(monitor_address); @@ -464,9 +452,9 @@ static int monitor_shutdown_service(struct mt_svc *svc) /* Construct a shutdown message */ msg = dbus_message_new_method_call(NULL, - SERVICE_PATH, - SERVICE_INTERFACE, - SERVICE_METHOD_SHUTDOWN); + MONITOR_PATH, + MONITOR_INTERFACE, + MON_CLI_METHOD_SHUTDOWN); if (!msg) { DEBUG(0,("Out of memory?!\n")); monitor_kill_service(svc); @@ -581,8 +569,8 @@ static int service_signal(struct mt_svc *svc, const char *svc_signal) dbus_conn = sbus_get_connection(svc->mt_conn->conn); msg = dbus_message_new_method_call(NULL, - SERVICE_PATH, - SERVICE_INTERFACE, + MONITOR_PATH, + MONITOR_INTERFACE, svc_signal); if (!msg) { DEBUG(0,("Out of memory?!\n")); @@ -610,11 +598,11 @@ static int service_signal(struct mt_svc *svc, const char *svc_signal) static int service_signal_reload(struct mt_svc *svc) { - return service_signal(svc, SERVICE_METHOD_RELOAD); + return service_signal(svc, MON_CLI_METHOD_RELOAD); } static int service_signal_dns_reload(struct mt_svc *svc) { - return service_signal(svc, SERVICE_METHOD_RES_INIT); + return service_signal(svc, MON_CLI_METHOD_RES_INIT); } static int check_domain_ranges(struct sss_domain_info *domains) @@ -1823,9 +1811,9 @@ static int dbus_service_init(struct sbus_connection *conn, void *data) * for all services */ msg = dbus_message_new_method_call(NULL, - SERVICE_PATH, - SERVICE_INTERFACE, - SERVICE_METHOD_IDENTITY); + MONITOR_PATH, + MONITOR_INTERFACE, + MON_CLI_METHOD_IDENTITY); if (msg == NULL) { DEBUG(0,("Out of memory?!\n")); talloc_free(conn); @@ -1970,9 +1958,9 @@ static int service_send_ping(struct mt_svc *svc) * for all services */ msg = dbus_message_new_method_call(NULL, - SERVICE_PATH, - SERVICE_INTERFACE, - SERVICE_METHOD_PING); + MONITOR_PATH, + MONITOR_INTERFACE, + MON_CLI_METHOD_PING); if (!msg) { DEBUG(0,("Out of memory?!\n")); talloc_free(svc->mt_conn->conn); diff --git a/server/monitor/monitor_interfaces.h b/server/monitor/monitor_interfaces.h index 05d1bb41..5c58066d 100644 --- a/server/monitor/monitor_interfaces.h +++ b/server/monitor/monitor_interfaces.h @@ -25,20 +25,19 @@ #define MONITOR_DBUS_INTERFACE "org.freedesktop.sssd.monitor" #define MONITOR_DBUS_PATH "/org/freedesktop/sssd/monitor" -/* Monitor Methods */ -#define MONITOR_METHOD_VERSION "getVersion" +/* Monitor SRV Methods */ +#define MON_SRV_METHOD_VERSION "getVersion" +/*** Monitor Interface ***/ -/*** Services ***/ +#define MONITOR_PATH "/org/freedesktop/sssd/service" +#define MONITOR_INTERFACE "org.freedesktop.sssd.service" -#define SERVICE_PATH "/org/freedesktop/sssd/service" -#define SERVICE_INTERFACE "org.freedesktop.sssd.service" - -/* Service Methods */ -#define SERVICE_METHOD_IDENTITY "getIdentity" -#define SERVICE_METHOD_PING "ping" -#define SERVICE_METHOD_RELOAD "reloadConfig" -#define SERVICE_METHOD_SHUTDOWN "shutDown" -#define SERVICE_METHOD_RES_INIT "resInit" +/* Monitor CLI Methods */ +#define MON_CLI_METHOD_IDENTITY "getIdentity" +#define MON_CLI_METHOD_PING "ping" +#define MON_CLI_METHOD_RELOAD "reloadConfig" +#define MON_CLI_METHOD_SHUTDOWN "shutDown" +#define MON_CLI_METHOD_RES_INIT "resInit" #define SSSD_SERVICE_PIPE "private/sbus-monitor" diff --git a/server/monitor/monitor_sbus.c b/server/monitor/monitor_sbus.c index 5d49f003..817b42ae 100644 --- a/server/monitor/monitor_sbus.c +++ b/server/monitor/monitor_sbus.c @@ -54,38 +54,3 @@ done: return ret; } -int monitor_init_sbus_methods(TALLOC_CTX *mem_ctx, - struct sbus_method *methods, - struct sbus_method_ctx **sm_ctx) -{ - struct sbus_method_ctx *method_ctx; - int ret; - - method_ctx = talloc_zero(mem_ctx, struct sbus_method_ctx); - if (!method_ctx) { - ret = ENOMEM; - goto fail; - } - - method_ctx->interface = talloc_strdup(method_ctx, SERVICE_INTERFACE); - if (method_ctx->interface == NULL) { - ret = ENOMEM; - goto fail; - } - - method_ctx->path = talloc_strdup(method_ctx, SERVICE_PATH); - if (method_ctx->path == NULL) { - ret = ENOMEM; - goto fail; - } - - method_ctx->methods = methods; - method_ctx->message_handler = sbus_message_handler; - - *sm_ctx = method_ctx; - return EOK; - -fail: - talloc_free(method_ctx); - return ret; -} diff --git a/server/monitor/monitor_sbus.h b/server/monitor/monitor_sbus.h index 5e110ab8..bc36e88e 100644 --- a/server/monitor/monitor_sbus.h +++ b/server/monitor/monitor_sbus.h @@ -24,7 +24,5 @@ int monitor_get_sbus_address(TALLOC_CTX *mem_ctx, struct confdb_ctx *confdb, char **address); -int monitor_init_sbus_methods(TALLOC_CTX *mem_ctx, struct sbus_method *methods, - struct sbus_method_ctx **sm_ctx); #endif /* MONITOR_SBUS_H_ */ -- cgit