dbus-core: Make dbus-core no longer mutually exclusive with udev

With systemd-logind the dbus-core will be used for more then just config, so
it should be possible to build it even when using a non dbus dependent config
backend.

This patch also removes the config_ prefix from the dbus-core symbols.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Daniel Stone <daniel@fooishbar.org>
This commit is contained in:
Hans de Goede 2013-12-04 11:10:06 +01:00 committed by Keith Packard
parent c29454ae9d
commit 480590b90c
10 changed files with 101 additions and 74 deletions

View File

@ -2,12 +2,19 @@ AM_CFLAGS = $(DIX_CFLAGS)
noinst_LTLIBRARIES = libconfig.la noinst_LTLIBRARIES = libconfig.la
libconfig_la_SOURCES = config.c config-backends.h libconfig_la_SOURCES = config.c config-backends.h
libconfig_la_LIBADD =
if NEED_DBUS
AM_CFLAGS += $(DBUS_CFLAGS)
libconfig_la_SOURCES += dbus-core.c
libconfig_la_LIBADD += $(DBUS_LIBS)
endif
if CONFIG_UDEV if CONFIG_UDEV
AM_CFLAGS += $(UDEV_CFLAGS) AM_CFLAGS += $(UDEV_CFLAGS)
libconfig_la_SOURCES += udev.c libconfig_la_SOURCES += udev.c
libconfig_la_LIBADD = $(UDEV_LIBS) libconfig_la_LIBADD += $(UDEV_LIBS)
if XORG if XORG
xorgconfddir = $(datadir)/X11/$(XF86CONFIGDIR) xorgconfddir = $(datadir)/X11/$(XF86CONFIGDIR)
@ -16,16 +23,10 @@ endif
else else
if CONFIG_NEED_DBUS
AM_CFLAGS += $(DBUS_CFLAGS)
libconfig_la_SOURCES += dbus-core.c
libconfig_la_LIBADD = $(DBUS_LIBS)
if CONFIG_HAL if CONFIG_HAL
AM_CFLAGS += $(HAL_CFLAGS) AM_CFLAGS += $(HAL_CFLAGS)
libconfig_la_SOURCES += hal.c libconfig_la_SOURCES += hal.c
libconfig_la_LIBADD += $(HAL_LIBS) libconfig_la_LIBADD += $(HAL_LIBS)
endif
else else
@ -33,7 +34,7 @@ if CONFIG_WSCONS
libconfig_la_SOURCES += wscons.c libconfig_la_SOURCES += wscons.c
endif # CONFIG_WSCONS endif # CONFIG_WSCONS
endif # CONFIG_NEED_DBUS endif # !CONFIG_HAL
endif # !CONFIG_UDEV endif # !CONFIG_UDEV

View File

@ -37,36 +37,10 @@ int config_udev_pre_init(void);
int config_udev_init(void); int config_udev_init(void);
void config_udev_fini(void); void config_udev_fini(void);
void config_udev_odev_probe(config_odev_probe_proc_ptr probe_callback); void config_udev_odev_probe(config_odev_probe_proc_ptr probe_callback);
#else #elif defined(CONFIG_HAL)
#ifdef CONFIG_NEED_DBUS
#include <dbus/dbus.h>
typedef void (*config_dbus_core_connect_hook) (DBusConnection * connection,
void *data);
typedef void (*config_dbus_core_disconnect_hook) (void *data);
struct config_dbus_core_hook {
config_dbus_core_connect_hook connect;
config_dbus_core_disconnect_hook disconnect;
void *data;
struct config_dbus_core_hook *next;
};
int config_dbus_core_init(void);
void config_dbus_core_fini(void);
int config_dbus_core_add_hook(struct config_dbus_core_hook *hook);
void config_dbus_core_remove_hook(struct config_dbus_core_hook *hook);
#endif
#ifdef CONFIG_HAL
int config_hal_init(void); int config_hal_init(void);
void config_hal_fini(void); void config_hal_fini(void);
#endif #elif defined(CONFIG_WSCONS)
#endif
#ifdef CONFIG_WSCONS
int config_wscons_init(void); int config_wscons_init(void);
void config_wscons_fini(void); void config_wscons_fini(void);
#endif #endif

View File

@ -47,16 +47,9 @@ config_init(void)
#ifdef CONFIG_UDEV #ifdef CONFIG_UDEV
if (!config_udev_init()) if (!config_udev_init())
ErrorF("[config] failed to initialise udev\n"); ErrorF("[config] failed to initialise udev\n");
#elif defined(CONFIG_NEED_DBUS) #elif defined(CONFIG_HAL)
if (config_dbus_core_init()) { if (!config_hal_init())
#ifdef CONFIG_HAL ErrorF("[config] failed to initialise HAL\n");
if (!config_hal_init())
ErrorF("[config] failed to initialise HAL\n");
#endif
}
else {
ErrorF("[config] failed to initialise D-Bus core\n");
}
#elif defined(CONFIG_WSCONS) #elif defined(CONFIG_WSCONS)
if (!config_wscons_init()) if (!config_wscons_init())
ErrorF("[config] failed to initialise wscons\n"); ErrorF("[config] failed to initialise wscons\n");
@ -68,11 +61,8 @@ config_fini(void)
{ {
#if defined(CONFIG_UDEV) #if defined(CONFIG_UDEV)
config_udev_fini(); config_udev_fini();
#elif defined(CONFIG_NEED_DBUS) #elif defined(CONFIG_HAL)
#ifdef CONFIG_HAL
config_hal_fini(); config_hal_fini();
#endif
config_dbus_core_fini();
#elif defined(CONFIG_WSCONS) #elif defined(CONFIG_WSCONS)
config_wscons_fini(); config_wscons_fini();
#endif #endif

View File

@ -30,9 +30,9 @@
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <sys/select.h> #include <sys/select.h>
#include "config-backends.h"
#include "dix.h" #include "dix.h"
#include "os.h" #include "os.h"
#include "dbus-core.h"
/* How often to attempt reconnecting when we get booted off the bus. */ /* How often to attempt reconnecting when we get booted off the bus. */
#define RECONNECT_DELAY (10 * 1000) /* in ms */ #define RECONNECT_DELAY (10 * 1000) /* in ms */
@ -41,7 +41,7 @@ struct dbus_core_info {
int fd; int fd;
DBusConnection *connection; DBusConnection *connection;
OsTimerPtr timer; OsTimerPtr timer;
struct config_dbus_core_hook *hooks; struct dbus_core_hook *hooks;
}; };
static struct dbus_core_info bus_info; static struct dbus_core_info bus_info;
@ -74,7 +74,7 @@ block_handler(void *data, struct timeval **tv, void *read_mask)
static void static void
teardown(void) teardown(void)
{ {
struct config_dbus_core_hook *hook; struct dbus_core_hook *hook;
if (bus_info.timer) { if (bus_info.timer) {
TimerFree(bus_info.timer); TimerFree(bus_info.timer);
@ -112,7 +112,7 @@ message_filter(DBusConnection * connection, DBusMessage * message, void *data)
* reconnect immediately (assuming it's just a restart). The * reconnect immediately (assuming it's just a restart). The
* connection isn't valid at this point, so throw it out immediately. */ * connection isn't valid at this point, so throw it out immediately. */
if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) { if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) {
DebugF("[config/dbus-core] disconnected from bus\n"); DebugF("[dbus-core] disconnected from bus\n");
bus_info.connection = NULL; bus_info.connection = NULL;
teardown(); teardown();
@ -136,12 +136,12 @@ static int
connect_to_bus(void) connect_to_bus(void)
{ {
DBusError error; DBusError error;
struct config_dbus_core_hook *hook; struct dbus_core_hook *hook;
dbus_error_init(&error); dbus_error_init(&error);
bus_info.connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); bus_info.connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
if (!bus_info.connection || dbus_error_is_set(&error)) { if (!bus_info.connection || dbus_error_is_set(&error)) {
DebugF("[config/dbus-core] error connecting to system bus: %s (%s)\n", LogMessage(X_ERROR, "dbus-core: error connecting to system bus: %s (%s)\n",
error.name, error.message); error.name, error.message);
goto err_begin; goto err_begin;
} }
@ -150,13 +150,13 @@ connect_to_bus(void)
dbus_connection_set_exit_on_disconnect(bus_info.connection, FALSE); dbus_connection_set_exit_on_disconnect(bus_info.connection, FALSE);
if (!dbus_connection_get_unix_fd(bus_info.connection, &bus_info.fd)) { if (!dbus_connection_get_unix_fd(bus_info.connection, &bus_info.fd)) {
ErrorF("[config/dbus-core] couldn't get fd for system bus\n"); ErrorF("[dbus-core] couldn't get fd for system bus\n");
goto err_unref; goto err_unref;
} }
if (!dbus_connection_add_filter(bus_info.connection, message_filter, if (!dbus_connection_add_filter(bus_info.connection, message_filter,
&bus_info, NULL)) { &bus_info, NULL)) {
ErrorF("[config/dbus-core] couldn't add filter: %s (%s)\n", error.name, ErrorF("[dbus-core] couldn't add filter: %s (%s)\n", error.name,
error.message); error.message);
goto err_fd; goto err_fd;
} }
@ -198,9 +198,9 @@ reconnect_timer(OsTimerPtr timer, CARD32 time, void *arg)
} }
int int
config_dbus_core_add_hook(struct config_dbus_core_hook *hook) dbus_core_add_hook(struct dbus_core_hook *hook)
{ {
struct config_dbus_core_hook **prev; struct dbus_core_hook **prev;
for (prev = &bus_info.hooks; *prev; prev = &(*prev)->next); for (prev = &bus_info.hooks; *prev; prev = &(*prev)->next);
@ -215,9 +215,9 @@ config_dbus_core_add_hook(struct config_dbus_core_hook *hook)
} }
void void
config_dbus_core_remove_hook(struct config_dbus_core_hook *hook) dbus_core_remove_hook(struct dbus_core_hook *hook)
{ {
struct config_dbus_core_hook **prev; struct dbus_core_hook **prev;
for (prev = &bus_info.hooks; *prev; prev = &(*prev)->next) { for (prev = &bus_info.hooks; *prev; prev = &(*prev)->next) {
if (*prev == hook) { if (*prev == hook) {
@ -228,7 +228,7 @@ config_dbus_core_remove_hook(struct config_dbus_core_hook *hook)
} }
int int
config_dbus_core_init(void) dbus_core_init(void)
{ {
memset(&bus_info, 0, sizeof(bus_info)); memset(&bus_info, 0, sizeof(bus_info));
bus_info.fd = -1; bus_info.fd = -1;
@ -240,7 +240,7 @@ config_dbus_core_init(void)
} }
void void
config_dbus_core_fini(void) dbus_core_fini(void)
{ {
teardown(); teardown();
} }

View File

@ -33,6 +33,7 @@
#include <string.h> #include <string.h>
#include <sys/select.h> #include <sys/select.h>
#include "dbus-core.h"
#include "input.h" #include "input.h"
#include "inputstr.h" #include "inputstr.h"
#include "hotplug.h" #include "hotplug.h"
@ -631,7 +632,7 @@ connect_hook(DBusConnection * connection, void *data)
static struct config_hal_info hal_info; static struct config_hal_info hal_info;
static struct config_dbus_core_hook hook = { static struct dbus_core_hook hook = {
.connect = connect_hook, .connect = connect_hook,
.disconnect = disconnect_hook, .disconnect = disconnect_hook,
.data = &hal_info, .data = &hal_info,
@ -644,7 +645,7 @@ config_hal_init(void)
hal_info.system_bus = NULL; hal_info.system_bus = NULL;
hal_info.hal_ctx = NULL; hal_info.hal_ctx = NULL;
if (!config_dbus_core_add_hook(&hook)) { if (!dbus_core_add_hook(&hook)) {
LogMessage(X_ERROR, "config/hal: failed to add D-Bus hook\n"); LogMessage(X_ERROR, "config/hal: failed to add D-Bus hook\n");
return 0; return 0;
} }
@ -658,5 +659,5 @@ config_hal_init(void)
void void
config_hal_fini(void) config_hal_fini(void)
{ {
config_dbus_core_remove_hook(&hook); dbus_core_remove_hook(&hook);
} }

View File

@ -897,14 +897,14 @@ if test "x$CONFIG_HAL" = xyes; then
fi fi
AC_DEFINE(CONFIG_HAL, 1, [Use the HAL hotplug API]) AC_DEFINE(CONFIG_HAL, 1, [Use the HAL hotplug API])
CONFIG_NEED_DBUS="yes" NEED_DBUS="yes"
fi fi
AM_CONDITIONAL(CONFIG_HAL, [test "x$CONFIG_HAL" = xyes]) AM_CONDITIONAL(CONFIG_HAL, [test "x$CONFIG_HAL" = xyes])
if test "x$CONFIG_NEED_DBUS" = xyes; then if test "x$NEED_DBUS" = xyes; then
AC_DEFINE(CONFIG_NEED_DBUS, 1, [Use D-Bus for input hotplug]) AC_DEFINE(NEED_DBUS, 1, [Enable D-Bus core])
fi fi
AM_CONDITIONAL(CONFIG_NEED_DBUS, [test "x$CONFIG_NEED_DBUS" = xyes]) AM_CONDITIONAL(NEED_DBUS, [test "x$NEED_DBUS" = xyes])
if test "x$CONFIG_WSCONS" = xauto; then if test "x$CONFIG_WSCONS" = xauto; then
case $host_os in case $host_os in

View File

@ -53,6 +53,7 @@
#include "scrnintstr.h" #include "scrnintstr.h"
#include "site.h" #include "site.h"
#include "mi.h" #include "mi.h"
#include "dbus-core.h"
#include "compiler.h" #include "compiler.h"
@ -456,6 +457,8 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
if (xf86DoShowOptions) if (xf86DoShowOptions)
DoShowOptions(); DoShowOptions();
dbus_core_init();
/* Do a general bus probe. This will be a PCI probe for x86 platforms */ /* Do a general bus probe. This will be a PCI probe for x86 platforms */
xf86BusProbe(); xf86BusProbe();
@ -1059,6 +1062,8 @@ ddxGiveUp(enum ExitCode error)
if (xorgHWOpenConsole) if (xorgHWOpenConsole)
xf86CloseConsole(); xf86CloseConsole();
dbus_core_fini();
xf86CloseLog(error); xf86CloseLog(error);
/* If an unexpected signal was caught, dump a core for debugging */ /* If an unexpected signal was caught, dump a core for debugging */

View File

@ -68,7 +68,7 @@ endif
AM_CFLAGS = $(DIX_CFLAGS) AM_CFLAGS = $(DIX_CFLAGS)
EXTRA_DIST = \ EXTRA_DIST = \
busfault.h \ busfault.h dbus-core.h \
dix-config-apple-verbatim.h \ dix-config-apple-verbatim.h \
dixfontstubs.h eventconvert.h eventstr.h inpututils.h \ dixfontstubs.h eventconvert.h eventstr.h inpututils.h \
protocol-versions.h \ protocol-versions.h \

56
include/dbus-core.h Normal file
View File

@ -0,0 +1,56 @@
/*
* Copyright © 2013 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Author: Hans de Goede <hdegoede@redhat.com>
*/
#ifndef DBUS_CORE_H
#define DBUS_CORE_H
#ifdef NEED_DBUS
typedef struct DBusConnection DBusConnection;
typedef void (*dbus_core_connect_hook) (DBusConnection * connection,
void *data);
typedef void (*dbus_core_disconnect_hook) (void *data);
struct dbus_core_hook {
dbus_core_connect_hook connect;
dbus_core_disconnect_hook disconnect;
void *data;
struct dbus_core_hook *next;
};
int dbus_core_init(void);
void dbus_core_fini(void);
int dbus_core_add_hook(struct dbus_core_hook *hook);
void dbus_core_remove_hook(struct dbus_core_hook *hook);
#else
#define dbus_core_init()
#define dbus_core_fini()
#endif
#endif

View File

@ -414,8 +414,8 @@
/* Use udev_enumerate_add_match_tag() */ /* Use udev_enumerate_add_match_tag() */
#undef HAVE_UDEV_ENUMERATE_ADD_MATCH_TAG #undef HAVE_UDEV_ENUMERATE_ADD_MATCH_TAG
/* Use D-Bus for input hotplug */ /* Enable D-Bus core */
#undef CONFIG_NEED_DBUS #undef NEED_DBUS
/* Support HAL for hotplug */ /* Support HAL for hotplug */
#undef CONFIG_HAL #undef CONFIG_HAL