Exemple #1
0
/* Currently this is implemented using a timed out wait on our private DBus
 * connection.  Because the connection is private we don't have to worry about
 * blocking other users. */
int VBoxMainHotplugWaiter::Wait(RTMSINTERVAL cMillies)
{
    int rc = VINF_SUCCESS;
#if defined RT_OS_LINUX && defined VBOX_WITH_DBUS
    if (!mContext->mConnection)
        rc = VERR_NOT_SUPPORTED;
    bool connected = true;
    mContext->mTriggered = false;
    mContext->mInterrupt = false;
    unsigned cRealMillies;
    if (cMillies != RT_INDEFINITE_WAIT)
        cRealMillies = cMillies;
    else
        cRealMillies = DBUS_POLL_TIMEOUT;
    while (   RT_SUCCESS(rc) && connected && !mContext->mTriggered
           && !mContext->mInterrupt)
    {
        connected = dbus_connection_read_write_dispatch (mContext->mConnection.get(),
                                                         cRealMillies);
        if (mContext->mInterrupt)
            LogFlowFunc(("wait loop interrupted\n"));
        if (cMillies != RT_INDEFINITE_WAIT)
            mContext->mInterrupt = true;
    }
    if (!connected)
        rc = VERR_TRY_AGAIN;
#else  /* !(defined RT_OS_LINUX && defined VBOX_WITH_DBUS) */
    rc = VERR_NOT_IMPLEMENTED;
#endif  /* !(defined RT_OS_LINUX && defined VBOX_WITH_DBUS) */
    return rc;
}
void dbus_initialize(void) {
	DBusError err;

	dbus_threads_init_default();
	dbus_error_init(&err);

	if (!(service_bus = dbus_connection_open(SERVICE_BUS_ADDRESS, &err))) {
		dbus_error_free(&err);
		errx(1, "failed to connect to service bus: %s: %s", err.name, err.message);
	}

	if (!dbus_bus_register(service_bus, &err)) {
		dbus_error_free(&err);
		errx(1, "failed to register with service bus: %s: %s", err.name, err.message);
	}
	
	dbus_error_free(&err);
	
	service_thread = std::thread([]() {
		// dispatch messages until disconnect
		while (dbus_connection_read_write_dispatch(service_bus, -1));
		dbus_connection_unref(service_bus);
	});

    service_thread.detach();
}
Exemple #3
0
int elektraDbusReceiveMessage (DBusBusType type, DBusHandleMessageFunction filter_func)
{
    DBusConnection *connection;
    DBusError error;

    dbus_error_init (&error);
    connection = dbus_bus_get (type, &error);
    if (connection == NULL)
    {
        fprintf (stderr, "Failed to open connection to %s message bus: %s\n",
                 (type == DBUS_BUS_SYSTEM) ? "system" : "session",
                 error.message);
        goto error;
    }

    dbus_bus_add_match (connection, "type='signal',interface='org.libelektra',path='/org/libelektra/configuration'", &error);
    if (dbus_error_is_set (&error)) goto error;

    if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL))
    {
        goto error;
    }

    while (dbus_connection_read_write_dispatch(connection, -1));
    return 0;
error:
    printf ("Error occurred\n");
    dbus_error_free (&error);
    return -1;
}
Exemple #4
0
int main(int argc, char *argv[])
{
    DBusConnection *conn;
    struct sigaction sa;

    conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
    if (!conn) {
        fprintf(stderr, "Can't get on system bus");
        return 1;
    }

    check_authorization(conn);

    memset(&sa, 0, sizeof(sa));
    sa.sa_flags   = SA_NOCLDSTOP;
    sa.sa_handler = sig_term;
    sigaction(SIGTERM, &sa, NULL);
    sigaction(SIGINT,  &sa, NULL);

#if 0
    while (!__io_terminate) {
        if (dbus_connection_read_write_dispatch(conn, 500) == FALSE)
            break;
    }
#endif

    dbus_connection_unref(conn);

    return 0;
}
Exemple #5
0
static int ldbus_connection_read_write_dispatch(lua_State *L) {
	DBusConnection *connection = check_DBusConnection(L, 1);
	int timeout_milliseconds = luaL_optint(L, 2, -1);

	lua_pushboolean(L, dbus_connection_read_write_dispatch(connection, timeout_milliseconds));

	return 1;
}
Exemple #6
0
gboolean
ibus_connection_read_write_dispatch (IBusConnection *connection,
                                     gint            timeout)
{
    IBusConnectionPrivate *priv;
    priv = IBUS_CONNECTION_GET_PRIVATE (connection);

    return dbus_connection_read_write_dispatch (priv->connection, timeout);
}
Exemple #7
0
static void *
_dbus_thread(void) {
	manage_log(LOG_INFO, "_dbus_thread: PID %d\n", getpid());
	while(manage_running 
		&& dbus_connection_read_write_dispatch(ac_manage_dbus_connection, 500)) {
	}

	return NULL;
}
Exemple #8
0
static void Run          ( intf_thread_t *p_intf )
{
    for( ;; )
    {
        if( dbus_connection_get_dispatch_status(p_intf->p_sys->p_conn)
                                             == DBUS_DISPATCH_COMPLETE )
            msleep( INTF_IDLE_SLEEP );
        int canc = vlc_savecancel();
        dbus_connection_read_write_dispatch( p_intf->p_sys->p_conn, 0 );

        /* Get the list of events to process
         *
         * We can't keep the lock on p_intf->p_sys->p_events, else we risk a
         * deadlock:
         * The signal functions could lock mutex X while p_events is locked;
         * While some other function in vlc (playlist) might lock mutex X
         * and then set a variable which would call AllCallback(), which itself
         * needs to lock p_events to add a new event.
         */
        vlc_mutex_lock( &p_intf->p_sys->lock );
        int i_events = vlc_array_count( p_intf->p_sys->p_events );
        callback_info_t* info[i_events];
        for( int i = i_events - 1; i >= 0; i-- )
        {
            info[i] = vlc_array_item_at_index( p_intf->p_sys->p_events, i );
            vlc_array_remove( p_intf->p_sys->p_events, i );
        }
        vlc_mutex_unlock( &p_intf->p_sys->lock );

        for( int i = 0; i < i_events; i++ )
        {
            switch( info[i]->signal )
            {
            case SIGNAL_ITEM_CURRENT:
                TrackChange( p_intf );
                break;
            case SIGNAL_INTF_CHANGE:
            case SIGNAL_PLAYLIST_ITEM_APPEND:
            case SIGNAL_PLAYLIST_ITEM_DELETED:
                TrackListChangeEmit( p_intf, info[i]->signal, info[i]->i_node );
                break;
            case SIGNAL_RANDOM:
            case SIGNAL_REPEAT:
            case SIGNAL_LOOP:
                StatusChangeEmit( p_intf );
                break;
            case SIGNAL_STATE:
                StateChange( p_intf, info[i]->i_input_state );
                break;
            default:
                assert(0);
            }
            free( info[i] );
        }
        vlc_restorecancel( canc );
    }
}
Exemple #9
0
int WaitUPowerStateChange() {
	event = 0;
	printf("[LPMTd] :: Waiting for power state change...\n");
	while(dbus_connection_read_write_dispatch(conn, -1) && !event);
	
	if(!event) {
		return -1;
	}
	return upower_pstate;
}
Exemple #10
0
int
main (int    argc,
      char **argv)
{
  DBusError error;
  DBusConnection *connection;
  
  dbus_error_init (&error);
  connection = dbus_bus_get (DBUS_BUS_STARTER, &error);
  if (connection == NULL)
    {
      fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n",
               error.message);
      dbus_error_free (&error);
      return 1;
    }

  if (!dbus_connection_add_filter (connection,
                                   filter_func, NULL, NULL))
    die ("No memory");

  if (!dbus_connection_register_object_path (connection,
                                             echo_path,
                                             &echo_vtable,
                                             (void*) 0xdeadbeef))
    die ("No memory");

  {
    void *d;
    if (!dbus_connection_get_object_path_data (connection, echo_path, &d))
      die ("No memory");
    if (d != (void*) 0xdeadbeef)
      die ("dbus_connection_get_object_path_data() doesn't seem to work right\n");
  }
  
  dbus_bus_request_name (connection, "org.freedesktop.DBus.GLib.TestEchoService",
                                  0, &error);
  if (dbus_error_is_set (&error))
    {
      fprintf (stderr, "Error %s\n", error.message);
      dbus_error_free (&error);
      exit (1);
    }
  
  while (dbus_connection_read_write_dispatch (connection, -1) && !already_quit)
    ;  

  dbus_connection_remove_filter (connection, filter_func, NULL);
  
  dbus_connection_unref (connection);

  dbus_shutdown ();

  return 0;
}
Exemple #11
0
void *bsd_dbus_thread_restart()
{
	bsd_pid_write_v2("BSDDbus Reinit",HOST_SLOT_NO);	
	if(bsd_dbus_reinit()) {
		while (dbus_connection_read_write_dispatch(bsd_dbus_connection,500)) {

		}
	}
	bsd_syslog_err("there is something wrong in dbus handler\n");	
	return 0;
}
Exemple #12
0
void *wbmd_dbus_thread_restart()
{
	wbmd_pid_write_v2("WBMDDbus Reinit");	
	if(wbmd_dbus_reinit()
	){
		while (dbus_connection_read_write_dispatch(wbmd_dbus_connection,500)) {

		}
	}
	wbmd_syslog_err("there is something wrong in dbus handler\n");	
	return 0;
}
Exemple #13
0
void * igmp_snp_dbus_thread_main(void *arg)
{
	int loop_count = 0;
	
	/*
	  * For all OAM method call, synchronous is necessary.
	  * Only signal/event could be asynchronous, it could be sent in other thread.
	  */	
	while (dbus_connection_read_write_dispatch(igmp_snp_dbus_connection,-1)) {
		igmp_snp_syslog_dbg("igmp snooping dbus thread running.\n");
	}
	return NULL;
}
Exemple #14
0
void initialize_dbus(void)
{
    dbus_threads_init_default();

    DBusError error;
    dbus_error_init(&error);

    // Initialize service bus
    service_bus = dbus_connection_open(SERVICE_BUS_ADDRESS, &error);
    if (!service_bus) {
        errx(1, "failed to connect to service bus: %s: %s\n", error.name, error.message);
    }

    if (!dbus_bus_register(service_bus, &error)) {
        errx(1, "failed to register with service bus: %s: %s\n", error.name, error.message);
    }

    // Initialize HMI bus
    hmi_bus = dbus_connection_open(HMI_BUS_ADDRESS, &error);
    if (!hmi_bus) {
        errx(1, "failed to connect to HMI bus: %s: %s\n", error.name, error.message);
    }

    if (!dbus_bus_register(hmi_bus, &error)) {
        errx(1, "failed to register with HMI bus: %s: %s\n", error.name, error.message);
    }

    std::thread service_thread([]() {
        while (dbus_connection_read_write_dispatch(service_bus, -1));
    });

    std::thread hmi_thread([]() {
        while (dbus_connection_read_write_dispatch(hmi_bus, -1));
    });

    service_thread.detach();
    hmi_thread.detach();
}
Exemple #15
0
static void
wakeup_handler(void *data, int err, void *read_mask)
{
    struct dbus_core_info *info = data;

    if (info->connection && FD_ISSET(info->fd, (fd_set *) read_mask)) {
        do {
            dbus_connection_read_write_dispatch(info->connection, 0);
        } while (info->connection &&
                 dbus_connection_get_is_connected(info->connection) &&
                 dbus_connection_get_dispatch_status(info->connection) ==
                 DBUS_DISPATCH_DATA_REMAINS);
    }
}
Exemple #16
0
int main(int argc, char *argv[])
{
    DBusError dberr;
    DBusConnection *dbconn;
    FILE *fp;
    char *line, *idx;
    size_t len=0;
    ssize_t read;
    int count=0;

    fp = fopen("buttons_client.rc", "r");
    if (NULL == fp) {
      chdir(getenv("HOME"));
      fp = fopen(".buttons_client.rc", "r");
      if (NULL == fp) return -1;
    }
    while ((read = getline(&line, &len, fp)) != -1) {
      if ((idx = strchr(line, '\r')) != NULL) *idx = '\0';
      if ((idx = strchr(line, '\n')) != NULL) *idx = '\0';
      if ((idx = strchr(line, ':')) != NULL) {
        strncpy (buttons[count].button, line, (idx-line));
        strcpy (buttons[count].command, idx+1);
      }
      count++;
    }
    fclose (fp);

    dbus_error_init(&dberr);
 
    dbconn = dbus_bus_get(DBUS_BUS_SESSION, &dberr);
    if (dbus_error_is_set(&dberr)) {
        dbus_error_free(&dberr);
        return -1;
    }
 
    if (!dbus_connection_add_filter(dbconn, filter_func, NULL, NULL)) {
        return -1;
    }
 
    dbus_bus_add_match(dbconn, "type='signal',interface='imobile.buttonsd.Type'", &dberr);
    if (dbus_error_is_set(&dberr)) {
        dbus_error_free(&dberr);
        return -1;
    }
 
    while(dbus_connection_read_write_dispatch(dbconn, -1)) {
        /* loop */
    }
    return 0;
}
    void onDbusMessage(DBusConnection *conn)
    {
        if ( !m_bus )
            return;
        DBusMessage* msg;
        DBusMessageIter args;
        DBusError err;
        int ret;
        char* sigvalue;

        // non blocking read of the next available message
        dbus_connection_read_write_dispatch(conn, 0);
        msg = dbus_connection_pop_message(conn);

        // loop again if we haven't read a message
        if (NULL == msg)
        {
            return;
        }
        //check if the message is a signal from the correct interface and with the correct name
        if (dbus_message_is_signal (msg, "com.burtonini.dbus.Signal", "Ping"))
        {
                    //read the parameters
            if (!dbus_message_iter_init(msg, &args))
                    CRLog::error("dbus: Message Has No Parameters\n");
            else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args))
                    CRLog::error("dbus: Argument is not string!\n");
            else
            {
                    dbus_message_iter_get_basic(&args, &sigvalue);
                    CRLog::info("dbus: Got Signal with value %s\n", sigvalue);
            }
        }
        else if (dbus_message_is_signal (msg, "com.burtonini.dbus.Signal", "Exit"))
        {
                    //read the parameters
            if (!dbus_message_iter_init(msg, &args))
                    CRLog::error("dbus: Message Has No Parameters\n");
            else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args))
                    CRLog::error("dbus: Argument is not string!\n");
            else
            {
                dbus_message_iter_get_basic(&args, &sigvalue);
                CRLog::info("dbus: Got Signal with value %s\n", sigvalue);
            }
        }
        //free the message
        dbus_message_unref(msg);
    }
Exemple #18
0
void pa_dbus_wrap_connection_free(pa_dbus_wrap_connection* c) {
    pa_assert(c);

    if (dbus_connection_get_is_connected(c->connection)) {
        dbus_connection_close(c->connection);
        /* must process remaining messages, bit of a kludge to handle
         * both unload and shutdown */
        while (dbus_connection_read_write_dispatch(c->connection, -1))
            ;
    }

    c->mainloop->defer_free(c->dispatch_event);
    dbus_connection_unref(c->connection);
    pa_xfree(c);
}
Exemple #19
0
void Keyboard::Process() 
{
  while(!m_bStop && conn && dbus_connection_read_write_dispatch(conn, 0)) 
  {
    int ch[8];
    int chnum = 0;

    while ((ch[chnum] = getchar()) != EOF) chnum++;

    if (chnum > 1) ch[0] = ch[chnum - 1] | (ch[chnum - 2] << 8);

    if (m_keymap[ch[0]] != 0)
          send_action(m_keymap[ch[0]]);
    else
      Sleep(20);
  }
}
Exemple #20
0
static DBusMessage *
send_and_allow_reentry (DBusConnection *bus, DBusMessage *message, DBusError *error)
{
    DBusPendingCall *pending;
    DBusMessage *reply = NULL;

    if (!dbus_connection_send_with_reply (bus, message, &pending, -1))
    {
        return NULL;
    }
    dbus_pending_call_set_notify (pending, set_reply, (void *)&reply, NULL);
    while (!reply)
    {
      if (!dbus_connection_read_write_dispatch (bus, -1))
        return NULL;
    }
    return reply;
}
Exemple #21
0
/**
* Description:
*   WSM DBus thread function.
*
* Parameter:
*   NULL
*
* Return:
*   Void
*
*/
void wsm_dbus_main(void)
{
	if (wsm_dbus_init())
	{
		WSMLog(L_CRIT, "%s: Initialize failed.\n", __func__);
		exit(-1);
	}
	
	while (1)
	{
		if (!dbus_connection_read_write_dispatch(wsm_dbus_conn, DBUS_TIMEOUT))
		{
			break;
		}
	}
	
	WSMLog(L_CRIT, "%s: Out of main loop, Critical ERROR.\n", __func__);
}
Exemple #22
0
// Called from ProcessSlow to trigger the callbacks from DBus
bool CHALManager::Update()
{
  CSingleLock lock(m_lock);
  if (m_Context == NULL)
    return false;

  if (!dbus_connection_read_write_dispatch(m_DBusSystemConnection, 0)) // We choose 0 that means we won't wait for a message
  {
    CLog::Log(LOGERROR, "DBus: System - read/write dispatch");
    return false;
  }
  if (NewMessage)
  {
    NewMessage = false;
    return true;
  }
  else
    return false;
}
Exemple #23
0
int main (int argc, char *argv[])
{
    DBusError dberr;
    DBusConnection *dbconn;

    dbus_error_init (&dberr);
    dbconn = dbus_bus_get (DBUS_BUS_SESSION, &dberr);
    if (dbus_error_is_set (&dberr)) {
        fprintf (stderr, "getting session bus failed: %s\n", dberr.message);
        dbus_error_free (&dberr);
        return EXIT_FAILURE;
    }

    dbus_bus_request_name (dbconn, "com.wiley.test",
                           DBUS_NAME_FLAG_REPLACE_EXISTING, &dberr);
    if (dbus_error_is_set (&dberr)) {
        fprintf (stderr, "requesting name failed: %s\n", dberr.message);
        dbus_error_free (&dberr);
        return EXIT_FAILURE;
    }

    if (!dbus_connection_add_filter (dbconn, filter_func, NULL, NULL))
        return EXIT_FAILURE;

    dbus_bus_add_match (dbconn,
                        "type='signal',interface='com.wiley.test'",
                        &dberr);

    if (dbus_error_is_set (&dberr)) {
        fprintf (stderr, "Could not match: %s", dberr.message);
        dbus_error_free (&dberr);
        return EXIT_FAILURE;
    }


    while (dbus_connection_read_write_dispatch (dbconn, -1))
        ; /* empty loop body */


    return EXIT_SUCCESS;
}
Exemple #24
0
DBusMessage *
dbind_send_and_allow_reentry (DBusConnection * bus, DBusMessage * message, DBusError *error)
{
  DBusPendingCall *pending;
  SpiReentrantCallClosure *closure;
  const char *unique_name = dbus_bus_get_unique_name (bus);
  const char *destination = dbus_message_get_destination (message);
  struct timeval tv;
  DBusMessage *ret;

  if (unique_name && destination &&
      strcmp (destination, unique_name) != 0)
    return dbus_connection_send_with_reply_and_block (bus, message, dbind_timeout, error);

  closure = g_new0 (SpiReentrantCallClosure, 1);
  closure->reply = NULL;
  atspi_dbus_connection_setup_with_g_main(bus, NULL);
  if (!dbus_connection_send_with_reply (bus, message, &pending, dbind_timeout))
      return NULL;
  if (!pending)
    return NULL;
  dbus_pending_call_set_notify (pending, set_reply, (void *) closure, g_free);

  closure->reply = NULL;
  gettimeofday (&tv, NULL);
  dbus_pending_call_ref (pending);
  while (!closure->reply)
    {
      if (!dbus_connection_read_write_dispatch (bus, dbind_timeout) ||
          time_elapsed (&tv) > dbind_timeout)
        {
          dbus_pending_call_unref (pending);
          return NULL;
        }
    }
  
  ret = closure->reply;
  dbus_pending_call_unref (pending);
  return ret;
}
Exemple #25
0
void Keyboard::Process() 
{
  while(!m_bStop)
  {
    CLog::Log(LOGDEBUG, "Keyboard: Process() m_bStop %d", m_bStop);
    if (conn)
      dbus_connection_read_write_dispatch(conn, 0);
    int ch[8];
    int chnum = 0;

    while ((ch[chnum] = getchar()) != EOF) chnum++;

    if (chnum > 1) ch[0] = ch[chnum - 1] | (ch[chnum - 2] << 8);

    if (chnum > 0)
      CLog::Log(LOGDEBUG, "Keyboard: character %c", ch[0]);

    if (m_keymap[ch[0]] != 0)
          send_action(m_keymap[ch[0]]);
    else
      Sleep(20);
  }
}
MateKeyringResult
gkr_operation_block_and_unref (GkrOperation *op)
{
	DBusPendingCall *pending;
	g_return_val_if_fail (op, BROKEN);

	while ((int) gkr_operation_get_result (op) == INCOMPLETE) {
		if (op->pending) {
			/*
			 * DBus has strange behavior that can complete a pending call
			 * in another thread and somehow does this without calling our
			 * on_pending_call_notify. So guard against this brokenness.
			 */
			pending = op->pending;
			dbus_pending_call_block (pending);
			if (op->pending == pending) {
				g_return_val_if_fail (dbus_pending_call_get_completed (pending), BROKEN);
				on_pending_call_notify (pending, op);
				g_assert (op->pending != pending);
			}
		} else if (op->prompting) {
			dbus_connection_flush (op->conn);
			while (op->prompting && (int) gkr_operation_get_result (op) == INCOMPLETE) {
				if (!dbus_connection_read_write_dispatch (op->conn, 200))
					break;
			}
		} else {
			g_assert_not_reached ();
		}
	}

	/* Make sure we have run our callbacks if complete */
	if (!g_queue_is_empty (&op->callbacks))
		on_complete (op);

	return gkr_operation_unref_get_result (op);
}
Exemple #27
0
static int sync_auth(DBusConnection *bus, DBusError *error) {
        usec_t begin, tstamp;

        assert(bus);

        /* This complexity should probably move into D-Bus itself:
         *
         * https://bugs.freedesktop.org/show_bug.cgi?id=35189 */

        begin = tstamp = now(CLOCK_MONOTONIC);
        for (;;) {

                if (tstamp > begin + DEFAULT_TIMEOUT_USEC)
                        break;

                if (dbus_connection_get_is_authenticated(bus))
                        break;

                if (!dbus_connection_read_write_dispatch(bus, ((begin + DEFAULT_TIMEOUT_USEC - tstamp) + USEC_PER_MSEC - 1) / USEC_PER_MSEC))
                        break;

                tstamp = now(CLOCK_MONOTONIC);
        }

        if (!dbus_connection_get_is_connected(bus)) {
                dbus_set_error_const(error, DBUS_ERROR_NO_SERVER, "Connection terminated during authentication.");
                return -ECONNREFUSED;
        }

        if (!dbus_connection_get_is_authenticated(bus)) {
                dbus_set_error_const(error, DBUS_ERROR_TIMEOUT, "Failed to authenticate in time.");
                return -EACCES;
        }

        return 0;
}
Exemple #28
0
void OMXControl::dispatch()
{
  if (bus)
    dbus_connection_read_write_dispatch(bus, 0);
}
Exemple #29
0
void*
serverthread(void*) {
    DBusMessage* msg;
    DBusError err;
    int ret;

    printf("Listening for method calls\n");
    if (pipe(quitpipe) == -1) {
        fprintf(stderr, "Could not create pipe.\n");
        return 0;
    }

    // initialise the error
    dbus_error_init(&err);

    // connect to the bus and check for errors
    conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
    if (dbus_error_is_set(&err)) {
        fprintf(stderr, "Connection Error (%s)\n", err.message);
        dbus_error_free(&err);
        return 0;
    }
    if (NULL == conn) {
        fprintf(stderr, "Connection Null\n");
        return 0;
    }

    // request our name on the bus and check for errors
    ret = dbus_bus_request_name(conn, "vandenoever.strigi",
        DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
    if (dbus_error_is_set(&err)) {
        fprintf(stderr, "Name Error (%s)\n", err.message);
        dbus_error_free(&err);
    }
    if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
        fprintf(stderr, "Not Primary Owner (%d)\n", ret);
        return 0;
    }

    for (int i=0; i<10; ++i) {
        printf("server\n");
    }
    int fd;
    dbus_connection_get_unix_fd(conn, &fd);

    bool run;
    do {
        // block until there's activit on the port
        fd_set rfds;
        struct timeval tv;
        FD_ZERO(&rfds);
        FD_SET(fd, &rfds);
        FD_SET(quitpipe[0], &rfds);
        printf("server\n");
        tv.tv_sec = 50000;
        tv.tv_usec = 0;
        int retval = select(fd+1, &rfds, 0, 0, &tv);
        if (retval == -1 || FD_ISSET(quitpipe[0], &rfds)) break;

        // non blocking read of the next available message
        dbus_connection_read_write_dispatch(conn, 0);
//        dbus_connection_read_write(conn, 0);
        msg = dbus_connection_pop_message(conn);
        dbus_connection_flush(conn);
        dbus_message_unref(msg);

        STRIGI_MUTEX_LOCK(&lock);
        run = keeprunning;
        STRIGI_MUTEX_UNLOCK(&lock);
    } while (run);

    dbus_connection_unref(conn);
    dbus_connection_unref(conn);
    dbus_shutdown();
    printf("after dbus_shutdown\n");
    return 0;
}
TEST_F(LibdbusTest, DISABLED_NonreplyingLibdbusConnectionsAreHandled) {
    const char problemServiceName[] = "problem.service";
    replyArrived = false;
    bool running = true;

    dbus_threads_init_default();

   ::DBusConnection* serviceConnection = createConnection();
   ::DBusConnection* clientConnection = createConnection();


   dbus_bus_request_name(serviceConnection,
                   problemServiceName,
                   DBUS_NAME_FLAG_DO_NOT_QUEUE,
                   NULL);

   dbus_connection_try_register_object_path(serviceConnection,
                   "/",
                   &libdbusObjectPathVTable,
                   NULL,
                   NULL);

   std::thread([&, this] {
       while(running) {
           dbus_connection_read_write_dispatch(serviceConnection, 10);
       }
   }).detach();

   usleep(100000);

   ::DBusMessage* message = dbus_message_new_method_call(problemServiceName, "/", NULL, "someMethod");

   ::DBusPendingCall* libdbusPendingCall;

   dbus_connection_send_with_reply(
                   clientConnection,
                   message,
                   &libdbusPendingCall,
                   3000);

   dbus_pending_call_set_notify(
                   libdbusPendingCall,
                   onLibdbusPendingCallNotifyThunk,
                   NULL,
                   NULL);

   //100*50 = 5000 (ms) ==> 3 seconds timeout pending call *should* have arrived by now.
   for (unsigned int i = 0; i < 100 && (!replyArrived); i++) {
       dbus_connection_read_write_dispatch(clientConnection, 50);
   }

   EXPECT_TRUE(replyArrived);

   running = false;

   usleep(100000);

   dbus_connection_close(serviceConnection);
   dbus_connection_unref(serviceConnection);
   dbus_connection_close(clientConnection);
   dbus_connection_unref(clientConnection);
}