Exemplo n.º 1
0
int weston_dbus_open(struct wl_event_loop *loop, DBusBusType bus,
		     DBusConnection **out, struct wl_event_source **ctx_out)
{
	DBusConnection *c;
	int r;

	/* Ihhh, global state.. stupid dbus. */
	dbus_connection_set_change_sigpipe(FALSE);

	/* This is actually synchronous. It blocks for some authentication and
	 * setup. We just trust the dbus-server here and accept this blocking
	 * call. There is no real reason to complicate things further and make
	 * this asynchronous/non-blocking. A context should be created during
	 * thead/process/app setup, so blocking calls should be fine. */
	c = dbus_bus_get_private(bus, NULL);
	if (!c)
		return -EIO;

	dbus_connection_set_exit_on_disconnect(c, FALSE);

	r = weston_dbus_bind(loop, c, ctx_out);
	if (r < 0)
		goto error;

	*out = c;
	return r;

error:
	dbus_connection_close(c);
	dbus_connection_unref(c);
	return r;
}
Exemplo n.º 2
0
static DBusConnection *virDBusBusInit(DBusBusType type, DBusError *dbuserr)
{
    DBusConnection *bus;

    /* Allocate and initialize a new HAL context */
    dbus_connection_set_change_sigpipe(FALSE);
    dbus_threads_init_default();

    dbus_error_init(dbuserr);
    bus = sharedBus ?
        dbus_bus_get(type, dbuserr) :
        dbus_bus_get_private(type, dbuserr);
    if (!bus)
        return NULL;

    dbus_connection_set_exit_on_disconnect(bus, FALSE);

    /* Register dbus watch callbacks */
    if (!dbus_connection_set_watch_functions(bus,
                                             virDBusAddWatch,
                                             virDBusRemoveWatch,
                                             virDBusToggleWatch,
                                             bus, NULL)) {
        return NULL;
    }
    return bus;
}
Exemplo n.º 3
0
/**
* Description:
*   WSM Debus initialize function
*
* Parameter:
*   NULL
*
* Return:
*   0: Successed; -1: failed
*
*/
int wsm_dbus_init(void)
{
	DBusError err;
	DBusObjectPathVTable wsm_vtbl = {NULL, &wsm_dbus_msg_handler, NULL, NULL, NULL, NULL};
	unsigned char dbus_name[WSM_PATH_MAX] = {0};
	unsigned char obj_path[WSM_PATH_MAX] = {0};

	sprintf(dbus_name, "%s%d_%d", WSM_DBUS_BUSNAME,local, vrrid);
	sprintf(obj_path, "%s%d_%d", WSM_DBUS_OBJPATH,local, vrrid);

	WSMLog(L_INFO, "%s: dbus name : %s\n", __func__, dbus_name);
	WSMLog(L_INFO, "%s: obj name : %s\n", __func__, obj_path);
	
	dbus_threads_init_default();
	dbus_connection_set_change_sigpipe (1);
	dbus_error_init (&err);
	wsm_dbus_conn = dbus_bus_get_private (DBUS_BUS_SYSTEM, &err);

	if (!wsm_dbus_conn)
	{
		WSMLog(L_CRIT, "%s: wsm_dbus_conn = NULL.\n", __func__);
		return -1;
	}

	if (!dbus_connection_register_fallback (wsm_dbus_conn, obj_path, &wsm_vtbl, NULL)) 
	{
		WSMLog(L_CRIT, "%s: register fallback failed.\n", __func__);
		return -1;
	}
	
	dbus_bus_request_name (wsm_dbus_conn, dbus_name, 0, &err);

	if (dbus_error_is_set (&err))
	{
		WSMLog(L_CRIT, "%s: dbus_bus_request_name() ERR:%s\n", __func__,
				err.message);
		return -1;
	}
	
	dbus_connection_add_filter (wsm_dbus_conn, wsm_dbus_filter_function, NULL, NULL);
	dbus_bus_add_match (wsm_dbus_conn,
				"type='signal'"
				",interface='"DBUS_INTERFACE_DBUS"'"
				",sender='"DBUS_SERVICE_DBUS"'"
				",member='NameOwnerChanged'",
				NULL);

	return 0;
}
Exemplo n.º 4
0
int wbmd_dbus_reinit(void)
{	
	int i = 0;
	DBusError dbus_error;
	dbus_threads_init_default();
	
	DBusObjectPathVTable	wbmd_vtable = {NULL, &wbmd_dbus_message_handler, NULL, NULL, NULL, NULL};	


	dbus_connection_set_change_sigpipe (TRUE);

	dbus_error_init (&dbus_error);
	wbmd_dbus_connection = dbus_bus_get_private (DBUS_BUS_SYSTEM, &dbus_error);
	if (wbmd_dbus_connection == NULL) {
		wbmd_syslog_err("dbus_bus_get(): %s\n", dbus_error.message);
		return FALSE;
	}

	// Use npd to handle subsection of NPD_DBUS_OBJPATH including slots
	if (!dbus_connection_register_fallback (wbmd_dbus_connection, WBMD_DBUS_OBJPATH, &wbmd_vtable, NULL)) {
		wbmd_syslog_err("can't register D-BUS handlers (fallback NPD). cannot continue.\n");
		return FALSE;
		
	}
	
	
	i = dbus_bus_request_name (wbmd_dbus_connection, WBMD_DBUS_BUSNAME,
			       0, &dbus_error);
		
	wbmd_syslog_debug_debug(WBMD_DBUS,"dbus_bus_request_name:%d",i);
	
	if (dbus_error_is_set (&dbus_error)) {
		wbmd_syslog_debug_debug(WBMD_DBUS,"dbus_bus_request_name(): %s",
			    dbus_error.message);
		return FALSE;
	}

	dbus_connection_add_filter (wbmd_dbus_connection, wbmd_dbus_filter_function, NULL, NULL);

	dbus_bus_add_match (wbmd_dbus_connection,
			    "type='signal'"
					    ",interface='"DBUS_INTERFACE_DBUS"'"
					    ",sender='"DBUS_SERVICE_DBUS"'"
					    ",member='NameOwnerChanged'",
			    NULL);
	
	return TRUE;
  
}
Exemplo n.º 5
0
int bsd_dbus_init(void)
{	
	int i = 0;
	DBusError dbus_error;
	dbus_threads_init_default();
	
	DBusObjectPathVTable	bsd_vtable = {NULL, &bsd_dbus_message_handler, NULL, NULL, NULL, NULL};	

	dbus_connection_set_change_sigpipe (TRUE);

	dbus_error_init (&dbus_error);
	bsd_dbus_connection = dbus_bus_get_private (DBUS_BUS_SYSTEM, &dbus_error);
	bsd_dbus_connection2 = dbus_bus_get_private (DBUS_BUS_SYSTEM, &dbus_error);

	if (bsd_dbus_connection == NULL) {
		bsd_syslog_err("dbus_bus_get(): %s\n", dbus_error.message);
		return FALSE;
	}
    
	if (!dbus_connection_register_fallback (bsd_dbus_connection, BSD_DBUS_OBJPATH, &bsd_vtable, NULL)) {
		bsd_syslog_err("can't register D-BUS handlers (fallback NPD). cannot continue.\n");
		return FALSE;
		
	}
	
	i = dbus_bus_request_name (bsd_dbus_connection, BSD_DBUS_BUSNAME,
			       0, &dbus_error);
	dbus_bus_request_name (bsd_dbus_connection2, "aw.bsd2",
			       0, &dbus_error);

	if (dbus_error_is_set (&dbus_error)) {
		bsd_syslog_debug_debug(BSD_DBUS,"dbus_bus_request_name(): %s",
			    dbus_error.message);
		return FALSE;
	}

	dbus_connection_add_filter (bsd_dbus_connection, bsd_dbus_filter_function, NULL, NULL);

	dbus_bus_add_match (bsd_dbus_connection,
			    "type='signal'"
					    ",interface='"DBUS_INTERFACE_DBUS"'"
					    ",sender='"DBUS_SERVICE_DBUS"'"
					    ",member='NameOwnerChanged'",
			    NULL);
	
//	printf("init finished\n");
	return TRUE;
  
}
Exemplo n.º 6
0
static gboolean
nm_dbus_manager_init_bus (NMDBusManager *self)
{
	NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self);
	GError *err = NULL;

	if (priv->connection) {
		nm_log_warn (LOGD_CORE, "DBus Manager already has a valid connection.");
		return FALSE;
	}

	dbus_connection_set_change_sigpipe (TRUE);

	priv->g_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
	if (!priv->g_connection) {
		nm_log_err (LOGD_CORE, "Could not get the system bus.  Make sure "
		            "the message bus daemon is running!  Message: %s",
		            err->message);
		g_error_free (err);
		return FALSE;
	}

	priv->connection = dbus_g_connection_get_connection (priv->g_connection);
	dbus_connection_set_exit_on_disconnect (priv->connection, FALSE);

	priv->proxy = dbus_g_proxy_new_for_name (priv->g_connection,
	                                         "org.freedesktop.DBus",
	                                         "/org/freedesktop/DBus",
	                                         "org.freedesktop.DBus");

	priv->proxy_destroy_id = g_signal_connect (priv->proxy, "destroy",
	                                           G_CALLBACK (destroy_cb), self);

	dbus_g_proxy_add_signal (priv->proxy, "NameOwnerChanged",
	                         G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
	                         G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (priv->proxy,
	                             "NameOwnerChanged",
	                             G_CALLBACK (proxy_name_owner_changed),
	                             self, NULL);
	return TRUE;
}
Exemplo n.º 7
0
static NMCEService *
bm_ce_service_new (DBusGConnection *bus, DBusGProxy *proxy, BMConnectionList *list)
{
	GObject *object;
	DBusConnection *connection;
	GError *err = NULL;
	guint32 result;

	g_return_val_if_fail (bus != NULL, NULL);
	g_return_val_if_fail (proxy != NULL, NULL);

	object = g_object_new (BM_TYPE_CE_SERVICE, NULL);
	if (!object)
		return NULL;

	BM_CE_SERVICE (object)->list = list;

	dbus_connection_set_change_sigpipe (TRUE);
	connection = dbus_g_connection_get_connection (bus);
	dbus_connection_set_exit_on_disconnect (connection, FALSE);

	/* Register our single-instance service.  Don't care if it fails. */
	if (!dbus_g_proxy_call (proxy, "RequestName", &err,
					    G_TYPE_STRING, BM_CE_DBUS_SERVICE_NAME,
					    G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
					    G_TYPE_INVALID,
					    G_TYPE_UINT, &result,
					    G_TYPE_INVALID)) {
		g_warning ("Could not acquire the connection editor service.\n"
		            "  Message: '%s'", err->message);
		g_error_free (err);
	} else {
		if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
			g_warning ("Could not acquire the connection editor service as it is already taken.");
		else {
			/* success */
			dbus_g_connection_register_g_object (bus, "/", object);
		}
	}

	return (NMCEService *) object;
}
Exemplo n.º 8
0
/*******************************************************************************
 * igmp_snp_dbus_init
 *
 * DESCRIPTION:
 *   		init the dbus ,include bus get and connection etc.
 *
 * INPUTS:
 * 		null
 *
 * OUTPUTS:
 *    	null
 *
 * RETURNS:
 *		IGMPSNP_RETURN_CODE_OK - init ok or can't register D-BUS handlers
 *		IGMPSNP_RETURN_CODE_DBUS_CONNECTION_E - bus get or request name or error set fail
 *
 * COMMENTS:
 *    
 **
 ********************************************************************************/
int igmp_snp_dbus_init(void)
{
	DBusError 	dbus_error;
	int			ret = IGMPSNP_RETURN_CODE_OK;
	DBusObjectPathVTable	igmp_snp_vtable = {NULL, &igmp_snp_dbus_message_handler, NULL, NULL, NULL, NULL};

	igmp_snp_syslog_dbg ("IGMP>>DBUS init...\n");

	dbus_connection_set_change_sigpipe (TRUE);

	dbus_error_init (&dbus_error);
	igmp_snp_dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error);
	if (igmp_snp_dbus_connection == NULL) {
		igmp_snp_syslog_err ("IGMP>>dbus_bus_get(): %s", dbus_error.message);
		return IGMPSNP_RETURN_CODE_DBUS_CONNECTION_E;
	}
	igmp_snp_syslog_dbg("IGMP>>igmp_snp_dbus_connection %p\n",igmp_snp_dbus_connection);

	// Use npd to handle subsection of IGMP_DBUS_OBJPATH including slots
	if (!dbus_connection_register_fallback (igmp_snp_dbus_connection, IGMP_DBUS_OBJPATH, &igmp_snp_vtable, NULL)) {
		igmp_snp_syslog_err("IGMP>>can't register D-BUS handlers (fallback NPD). cannot continue.");
		return IGMPSNP_RETURN_CODE_OK;		
	}
		
	ret = dbus_bus_request_name (igmp_snp_dbus_connection, IGMP_DBUS_BUSNAME,0, &dbus_error);
	if(-1 == ret)
	{
		igmp_snp_syslog_err("IGMP>>dbus request name err %d\n",ret);
		
		ret = IGMPSNP_RETURN_CODE_DBUS_CONNECTION_E;
	}
	else
		igmp_snp_syslog_dbg("IGMP>>dbus request name ok\n");
	
	if (dbus_error_is_set (&dbus_error)) {
		igmp_snp_syslog_err ("IGMP>>dbus_bus_request_name(): %s", dbus_error.message);
		
		return IGMPSNP_RETURN_CODE_DBUS_CONNECTION_E;
	}
	return IGMPSNP_RETURN_CODE_OK;
}
Exemplo n.º 9
0
/** Establish connection to the D-BUS daemon.
 * 
 * @returns     TRUE if connection could be established or if connection is already,
 *              established. FALSE if connection failed.
 */
gboolean ial_dbus_connect()
{
    DBusError dbus_error;

    if (dbus_connection == NULL) {
        dbus_connection_set_change_sigpipe(TRUE);
        dbus_error_init(&dbus_error);
        dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);

        if (dbus_connection == NULL) {
            ERROR(("dbus_bus_get(): Error. (%s)", dbus_error.message));
            return FALSE;
        }
        else {
            INFO(("dbus_bus_get(): Success."));
            return TRUE;
        }
    }
    else {
        INFO(("Already connected to D-Bus."));
        return TRUE;
    }
}
Exemplo n.º 10
0
static NML2tpPppService *
nm_l2tp_ppp_service_new (NMConnection *connection,
                         GError **error)
{
	NML2tpPppService *self = NULL;
	DBusGConnection *bus;
	DBusGProxy *proxy;
	gboolean success = FALSE;
	guint result;

	bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, error);
	if (!bus)
		return NULL;
	dbus_connection_set_change_sigpipe (TRUE);

	proxy = dbus_g_proxy_new_for_name (bus,
									   "org.freedesktop.DBus",
									   "/org/freedesktop/DBus",
									   "org.freedesktop.DBus");
	g_assert(proxy);
	if (dbus_g_proxy_call (proxy, "RequestName", error,
					   G_TYPE_STRING, NM_DBUS_SERVICE_L2TP_PPP,
					   G_TYPE_UINT, 0,
					   G_TYPE_INVALID,
					   G_TYPE_UINT, &result,
					   G_TYPE_INVALID)) {
		self = (NML2tpPppService *) g_object_new (NM_TYPE_L2TP_PPP_SERVICE, NULL);
		g_assert(self);
		dbus_g_connection_register_g_object (bus, NM_DBUS_PATH_L2TP_PPP, G_OBJECT (self));
		success = TRUE;
	} else {
		g_warning (_("Could not register D-Bus service name.  Message: %s"), (*error)->message);
	}
	g_object_unref (proxy);
	dbus_g_connection_unref (bus);
	return self;
}
Exemplo n.º 11
0
static gboolean
request_dbus_name (DBusGConnection *bus)
{
    DBusGProxy *proxy;
    GError *error = NULL;
    int request_name_result;

    dbus_connection_set_change_sigpipe (TRUE);
    dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (bus), FALSE);

    proxy = dbus_g_proxy_new_for_name (bus,
                                       "org.freedesktop.DBus",
                                       "/org/freedesktop/DBus",
                                       "org.freedesktop.DBus");

    if (!dbus_g_proxy_call (proxy, "RequestName", &error,
                            G_TYPE_STRING, NM_DBUS_SERVICE_USER_SETTINGS,
                            G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
                            G_TYPE_INVALID,
                            G_TYPE_UINT, &request_name_result,
                            G_TYPE_INVALID)) {
        g_warning ("Could not acquire the NetworkManagerUserSettings service.\n"
                   "  Message: '%s'", error->message);
        g_error_free (error);
        return FALSE;
    }

    if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
        g_warning ("Could not acquire the NetworkManagerUserSettings service "
                   "as it is already taken.  Return: %d",
                   request_name_result);
        return FALSE;
    }

    return TRUE;
}
Exemplo n.º 12
0
Arquivo: dbus.cpp Projeto: nyorain/iro
//DbusHandler
DBusHandler::DBusHandler(Compositor& comp)
	: compositor_(&comp)
{
    DBusError err;
    dbus_error_init(&err);

    dbus_connection_set_change_sigpipe(false);

	//todo: error checking everywhere
    if(!(dbusConnection_ = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err)))
    {
		std::string errStr;
		checkError(err, errStr);
			
        throw std::runtime_error("DBus::DBus: cant connect to dbus. " + errStr);
        return;
    }

    dbus_connection_set_exit_on_disconnect(dbusConnection_, false);

    //use dummy event fd
    int fd;
    if((fd = eventfd(0, EFD_CLOEXEC)) < 0)
    {
        throw std::runtime_error("DBus::DBus: cant create eventfd");
        return;
    }

	//event source
    dbusEventSource_ = wl_event_loop_add_fd(&comp.wlEventLoop(), fd, 0, Callbacks::dispatchDBus, 
			this);
    close(fd);
    wl_event_source_check(dbusEventSource_);

	//watch
    if(!dbus_connection_set_watch_functions(dbusConnection_, Callbacks::addWatch, 
				Callbacks::removeWatch, Callbacks::toggleWatch, this, nullptr))
    {
        throw std::runtime_error("dbus_connection_set_watch_functions failed");
        return;
    }

	//timeout
    if(!dbus_connection_set_timeout_functions(dbusConnection_, Callbacks::addTimeout, 
				Callbacks::removeTimeout, Callbacks::toggleTimeout, this, nullptr))
    {
        throw std::runtime_error("dbus_connection_set_timeout_functions failed");
        return;
    }

	//filter
    if(!dbus_connection_add_filter(dbusConnection_, Callbacks::dbusFilter, this, nullptr))
	{
		throw std::runtime_error("dbus add filter failed");
		return;
	}

	//disconnected callback
	signalCallbacks_.emplace_back(MsgCallback{DBUS_INTERFACE_LOCAL, "Diconnected", 
		nytl::memberCallback(&DBusHandler::disconnected, this)});

	ny::sendLog("dbus handler succesfully set up");
}