Exemplo n.º 1
0
static void setup_dbus_server(mrp_mainloop_t *ml)
{
    static struct DBusObjectPathVTable vtable = {
        .message_function = dispatch_method
    };

    char *addr = "org.murphy.test";

    MRP_UNUSED(ml);

    if ((dbus_test.conn = connect_to_dbus(addr)) == NULL)
        fatal("failed to connect to DBUS");

    if (!mrp_setup_dbus_connection(ml, dbus_test.conn))
        fatal("failed to setup DBUS connection with mainloop");

    if (!dbus_connection_register_fallback(dbus_test.conn, "/", &vtable, NULL))
        fatal("failed to set up method dispatching");

    if (write(dbus_test.pipe[1], addr, strlen(addr) + 1) < 0) {
        /* just ignore it... */
    }

    cfg.nrunning++;
}
/**
 * wpas_dbus_register_new_iface - Register a new interface with dbus
 * @wpa_s: %wpa_supplicant interface description structure to register
 * Returns: 0 on success, -1 on error
 *
 * Registers a new interface with dbus and assigns it a dbus object path.
 */
int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s)
{
	struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
	DBusConnection * con;
	u32 next;
	DBusObjectPathVTable vtable = {
		NULL, &wpas_iface_message_handler, NULL, NULL, NULL, NULL
	};

	/* Do nothing if the control interface is not turned on */
	if (ctrl_iface == NULL)
		return 0;

	con = ctrl_iface->con;
	next = ctrl_iface->next_objid++;

	/* Create and set the interface's object path */
	wpa_s->dbus_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
	if (wpa_s->dbus_path == NULL)
		return -1;
	os_snprintf(wpa_s->dbus_path, WPAS_DBUS_OBJECT_PATH_MAX,
		    WPAS_DBUS_PATH_INTERFACES "/%u",
		    next);

	/* Register the message handler for the interface functions */
	if (!dbus_connection_register_fallback(con, wpa_s->dbus_path, &vtable,
					       wpa_s)) {
		wpa_printf(MSG_ERROR, "dbus: Could not set up message "
			   "handler for interface %s", wpa_s->ifname);
		return -1;
	}

	return 0;
}
Exemplo n.º 3
0
void plugin_init(void)
{
	DBusError error;

    object_hash=g_hash_table_new(g_str_hash, g_str_equal);
	object_count=g_hash_table_new(g_str_hash, g_str_equal);
	dbg(0,"enter 1\n");
	dbus_error_init(&error);
	connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
	if (!connection) {
		dbg(0,"Failed to open connection to session message bus: %s\n", error.message);
		dbus_error_free(&error);
		return;
	}
	dbus_connection_setup_with_g_main(connection, NULL);
#if 0
	dbus_connection_add_filter(connection, filter, NULL, NULL);
	dbus_bus_add_match(connection, "type='signal',""interface='" DBUS_INTERFACE_DBUS  "'", &error);
#endif
	dbus_connection_register_fallback(connection, object_path, &dbus_navit_vtable, NULL);
	dbus_bus_request_name(connection, service_name, 0, &error);
	if (dbus_error_is_set(&error)) {
		dbg(0,"Failed to request name: %s", error.message);
		dbus_error_free (&error);
	}
}
Exemplo n.º 4
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.º 5
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.º 6
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.º 7
0
Tcl_DBusHandlerData *DBus_GetMessageHandler(Tcl_Interp *interp,
	Tcl_DBusBus *dbus, char *path)
{
   DBusObjectPathVTable vtable;
   Tcl_DBusHandlerData *dataPtr;

   /* Get the currently registered handler for the path */
   if (*path == '\0') {
      if (!dbus_connection_get_object_path_data(dbus->conn, "/", 
		(void **)&dataPtr)) return NULL;
   }
   else {
      if (!dbus_connection_get_object_path_data(dbus->conn, path,
		(void **)&dataPtr)) return NULL;
   }
   if (dataPtr == NULL) {
      /* No handler currently exists - create a new one */
      vtable.message_function = DBus_Message;
      vtable.unregister_function = DBus_Unregister;
      dataPtr = (Tcl_DBusHandlerData *)ckalloc(sizeof(Tcl_DBusHandlerData));
      dataPtr->dbus = dbus;
      dataPtr->signal = NULL;
      dataPtr->method = NULL;
      dataPtr->flags = 0;
      if (path[0] == '\0' || (path[0] == '/' && path[1] == '\0')) {
	 /* Register as a fallback method handler */
	 if (!dbus_connection_register_fallback(dbus->conn, "/", 
						   &vtable, dataPtr))
	   return NULL;
	 dataPtr->flags |= DBUSFLAG_FALLBACK;
      }
      else {
	 /* Register as a regular method handler */
	 if (!dbus_connection_register_object_path(dbus->conn, path, 
						      &vtable, dataPtr))
	   return NULL;
      }
   }
   if (*path == '\0') {
      if (dbus->fallback != NULL) 
	return dbus->fallback;
      dataPtr = (Tcl_DBusHandlerData *)ckalloc(sizeof(Tcl_DBusHandlerData));
      dataPtr->dbus = dbus;
      dataPtr->signal = NULL;
      dataPtr->method = NULL;
      dbus->fallback = dataPtr;	 
   }
   return dataPtr;
}
Exemplo n.º 8
0
/**
 * wpas_dbus_register_new_iface - Register a new interface with dbus
 * @global: Global %wpa_supplicant data
 * @wpa_s: %wpa_supplicant interface description structure to register
 * Returns: 0 on success, -1 on error
 *
 * Registers a new interface with dbus and assigns it a dbus object path.
 */
int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s)
{
	struct ctrl_iface_dbus_priv *ctrl_iface =
		wpa_s->global->dbus_ctrl_iface;
	DBusConnection * con;
	u32 next;
	DBusObjectPathVTable vtable = {
		NULL, &wpas_iface_message_handler, NULL, NULL, NULL, NULL
	};
	char *path;
	int ret = -1;

	/* Do nothing if the control interface is not turned on */
	if (ctrl_iface == NULL)
		return 0;

	con = ctrl_iface->con;
	next = wpa_supplicant_dbus_next_objid(ctrl_iface);

	/* Create and set the interface's object path */
	path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
	if (path == NULL)
		return -1;
	snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
		 WPAS_DBUS_PATH_INTERFACES "/%u",
		 next);
	if (wpa_supplicant_set_dbus_path(wpa_s, path)) {
		wpa_printf(MSG_DEBUG,
		           "Failed to set dbus path for interface %s",
			   wpa_s->ifname);
		goto out;
	}

	/* Register the message handler for the interface functions */
	if (!dbus_connection_register_fallback(con, path, &vtable, wpa_s)) {
		perror("wpas_dbus_register_iface [dbus]");
		wpa_printf(MSG_ERROR, "Could not set up DBus message "
			   "handler for interface %s.", wpa_s->ifname);
		goto out;
	}
	ret = 0;

out:
	free(path);
	return ret;
}
Exemplo n.º 9
0
static int ldbus_connection_register_fallback(lua_State *L) {
	DBusConnection *connection = check_DBusConnection(L, 1);
	const char *path = luaL_checkstring(L, 2);
	ldbus_callback_udata *data;
	luaL_checktype(L, 3, LUA_TFUNCTION);
	lua_settop(L, 3);
	if ((data = malloc(sizeof(ldbus_callback_udata))) == NULL) {
		return luaL_error(L, LDBUS_NO_MEMORY);
	}
	data->L = L;
	data->ref = luaL_ref(L, LUA_REGISTRYINDEX);
	if (!dbus_connection_register_fallback(connection, path, &VTable, data)) {
		free(data);
		return luaL_error(L, "unknown error");
	}
	lua_pushboolean(L, 1);
	return 1;
}
Exemplo n.º 10
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.º 11
0
int
init_ac_manage_dbus(void) {
    
	DBusError dbus_error;

	DBusObjectPathVTable ac_manage_vtable = {NULL, &ac_manage_dbus_message_handler, NULL, NULL, NULL, NULL};	
    
	dbus_error_init (&dbus_error);

	ac_manage_dbus_connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &dbus_error);
	if(NULL == ac_manage_dbus_connection) {
		syslog(LOG_WARNING, "dbus_bus_get(): %s\n", dbus_error.message);
        	dbus_error_free(&dbus_error);
		return AC_MANAGE_DBUS_ERROR;
	}
	
	if(!dbus_connection_register_fallback(ac_manage_dbus_connection, AC_MANAGE_DBUS_OBJPATH, &ac_manage_vtable, NULL)) {
		syslog(LOG_WARNING, "init_ac_manage_dbus: register fallback fail!\n");
		return AC_MANAGE_DBUS_ERROR;
	}
	
	
	dbus_bus_request_name(ac_manage_dbus_connection, AC_MANAGE_DBUS_DBUSNAME, 0, &dbus_error);
	
	if (dbus_error_is_set(&dbus_error)) {
		syslog(LOG_WARNING, "dbus_bus_get(): %s\n", dbus_error.message);
		dbus_error_free(&dbus_error);
		return AC_MANAGE_DBUS_ERROR;
	}

	dbus_connection_add_filter (ac_manage_dbus_connection, ac_manage_dbus_filter_function, NULL, NULL);
				
	dbus_bus_add_match (ac_manage_dbus_connection,
							"type='signal'"
							",interface='"AC_MANAGE_DBUS_INTERFACE"'",
							NULL);

	return AC_MANAGE_SUCCESS;  
    
}
Exemplo n.º 12
0
static void 
handle_connection(DBusServer *server,
                  DBusConnection *new_connection,
                  void *data)
{

	if (runner_connection == NULL) {
		DBusObjectPathVTable vtable = { &runner_server_unregister_handler, 
						&runner_server_message_handler, 
						NULL, NULL, NULL, NULL};
		
		runner_connection = new_connection;
		dbus_connection_ref (new_connection);
		dbus_connection_setup_with_g_main (new_connection, NULL);

		dbus_connection_register_fallback (new_connection, 
						   "/org/freedesktop",
						   &vtable,
						   NULL);

		/* dbus_server_unref(server); */

	}
}
Exemplo n.º 13
0
static int manager_connect_bus(Manager *m) {
        DBusError error;
        int r;
        struct epoll_event ev = {
                .events = EPOLLIN,
                .data.u32 = FD_BUS,
        };

        assert(m);
        assert(!m->bus);
        assert(m->bus_fd < 0);

        dbus_error_init(&error);

        m->bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
        if (!m->bus) {
                log_error("Failed to get system D-Bus connection: %s", bus_error_message(&error));
                r = -ECONNREFUSED;
                goto fail;
        }

        if (!dbus_connection_register_object_path(m->bus, "/org/freedesktop/machine1", &bus_manager_vtable, m) ||
            !dbus_connection_register_fallback(m->bus, "/org/freedesktop/machine1/machine", &bus_machine_vtable, m) ||
            !dbus_connection_add_filter(m->bus, bus_message_filter, m, NULL)) {
                r = log_oom();
                goto fail;
        }

        dbus_bus_add_match(m->bus,
                           "type='signal',"
                           "sender='org.freedesktop.systemd1',"
                           "interface='org.freedesktop.systemd1.Manager',"
                           "member='JobRemoved',"
                           "path='/org/freedesktop/systemd1'",
                           &error);
        if (dbus_error_is_set(&error)) {
                log_error("Failed to add match for JobRemoved: %s", bus_error_message(&error));
                dbus_error_free(&error);
        }

        dbus_bus_add_match(m->bus,
                           "type='signal',"
                           "sender='org.freedesktop.systemd1',"
                           "interface='org.freedesktop.systemd1.Manager',"
                           "member='UnitRemoved',"
                           "path='/org/freedesktop/systemd1'",
                           &error);
        if (dbus_error_is_set(&error)) {
                log_error("Failed to add match for UnitRemoved: %s", bus_error_message(&error));
                dbus_error_free(&error);
        }

        dbus_bus_add_match(m->bus,
                           "type='signal',"
                           "sender='org.freedesktop.systemd1',"
                           "interface='org.freedesktop.DBus.Properties',"
                           "member='PropertiesChanged'",
                           &error);
        if (dbus_error_is_set(&error)) {
                log_error("Failed to add match for PropertiesChanged: %s", bus_error_message(&error));
                dbus_error_free(&error);
        }

        dbus_bus_add_match(m->bus,
                           "type='signal',"
                           "sender='org.freedesktop.systemd1',"
                           "interface='org.freedesktop.systemd1.Manager',"
                           "member='Reloading',"
                           "path='/org/freedesktop/systemd1'",
                           &error);
        if (dbus_error_is_set(&error)) {
                log_error("Failed to add match for Reloading: %s", bus_error_message(&error));
                dbus_error_free(&error);
        }

        r = bus_method_call_with_reply(
                        m->bus,
                        "org.freedesktop.systemd1",
                        "/org/freedesktop/systemd1",
                        "org.freedesktop.systemd1.Manager",
                        "Subscribe",
                        NULL,
                        &error,
                        DBUS_TYPE_INVALID);
        if (r < 0) {
                log_error("Failed to enable subscription: %s", bus_error(&error, r));
                dbus_error_free(&error);
        }

        r = dbus_bus_request_name(m->bus, "org.freedesktop.machine1", DBUS_NAME_FLAG_DO_NOT_QUEUE, &error);
        if (dbus_error_is_set(&error)) {
                log_error("Failed to register name on bus: %s", bus_error_message(&error));
                r = -EIO;
                goto fail;
        }

        if (r != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)  {
                log_error("Failed to acquire name.");
                r = -EEXIST;
                goto fail;
        }

        m->bus_fd = bus_loop_open(m->bus);
        if (m->bus_fd < 0) {
                r = m->bus_fd;
                goto fail;
        }

        if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->bus_fd, &ev) < 0)
                goto fail;

        return 0;

fail:
        dbus_error_free(&error);

        return r;
}

void manager_gc(Manager *m, bool drop_not_started) {
        Machine *machine;

        assert(m);

        while ((machine = m->machine_gc_queue)) {
                LIST_REMOVE(gc_queue, m->machine_gc_queue, machine);
                machine->in_gc_queue = false;

                if (machine_check_gc(machine, drop_not_started) == 0) {
                        machine_stop(machine);
                        machine_free(machine);
                }
        }
}