D-Bus server: delay message processing until server is running

Server::run() still does some initialization (backend loading and file
watching). We need to wait with processing calls until that is done,
otherwise we have a race condition in TestFileNotify.testSession3:
- server starts
- test calls GetVersion()
- server answers as part of sending out log messages or loading backends (?),
  sending incomplete information (no backends loaded yet)
- test touches syncevo-dbus-server
- server sets up watch
=> test fails because server missed the file modification and incorrect information returned
   by GetVersions()
This commit is contained in:
Patrick Ohly 2014-04-25 08:25:07 +02:00
parent dd66d1d0cb
commit 9c733242a4
3 changed files with 9 additions and 1 deletions

View File

@ -219,7 +219,6 @@ int main(int argc, char **argv, char **envp)
unsetenv("G_DBUS_DEBUG");
}
dbus_bus_connection_undelay(conn);
server->run();
SE_LOG_DEBUG(NULL, "cleaning up");
#ifdef ENABLE_DBUS_PIM

View File

@ -356,6 +356,7 @@ Server::Server(GMainLoop *loop,
m_loop(loop),
m_shutdownRequested(shutdownRequested),
m_restart(restart),
m_conn(conn),
m_lastSession(time(NULL)),
m_activeSession(NULL),
m_lastInfoReq(0),
@ -531,6 +532,13 @@ void Server::run()
}
SE_LOG_INFO(NULL, "ready to run");
// Note that with GDBus GIO, this will also finally request the
// "org.syncevolution" name. This relies on preserving the name in
// m_conn that we originally passed to dbus_get_bus_connection().
// getConnection() works with a plain GDBusConnection and doesn't
// have the name, so we really need our own copy of
// DBusConnectionPtr here.
dbus_bus_connection_undelay(m_conn);
if (!m_shutdownRequested) {
g_main_loop_run(m_loop);
}

View File

@ -67,6 +67,7 @@ class Server : public GDBusCXX::DBusObjectHelper
bool &m_shutdownRequested;
Timespec m_lastFileMod;
boost::shared_ptr<SyncEvo::Restart> &m_restart;
GDBusCXX::DBusConnectionPtr m_conn;
uint32_t m_lastSession;
typedef std::list< std::pair< boost::shared_ptr<GDBusCXX::Watch>, boost::shared_ptr<Client> > > Clients_t;