static int _Go(string cfgfile, string bus, string[] listeners) { StartDBusServerThread(listeners.ToArray()); if (cfgfile.e() && File.Exists("versaplexd.ini")) cfgfile = "versaplexd.ini"; if (cfgfile.e()) cfgfile = "/etc/versaplexd.ini"; log.print("Config file is '{0}'\n", cfgfile); VxSqlPool.SetIniFile(cfgfile); wv.assert(bus.ne()); log.print("Connecting to '{0}'\n", bus); conn = new WvDbus(bus); RequestNameReply rnr = conn.RequestName("vx.versaplexd", NameFlag.DoNotQueue); switch (rnr) { case RequestNameReply.PrimaryOwner: log.print("Name registered, ready\n"); break; default: log.print("Register name result: \n" + rnr.ToString()); return 2; } conn.stream.onclose += () => { log.print( "***********************************************************\n"+ "************ D-bus connection closed by server ************\n"+ "***********************************************************\n"); want_to_die = true; }; conn.handlers.Insert(0, (m) => WvDbusMsgReady(conn, m)); while (!want_to_die) { log.print(WvLog.L.Debug2, "Event loop.\n"); // We can't wait infinitely here, because someone in another // thread might set want_to_die. // (FIXME: in that case it's lame that we might ignore it for // a timeout. We should have a loopback stream of some sort // instead...) WvStream.runonce(1000); while (action_queue.Count > 0) { log.print(WvLog.L.Debug2, "Action queue.\n"); lock (action_mutex) { curaction = action_queue.First(); action_queue.RemoveAt(0); } curaction.action(); lock (action_mutex) { curaction = null; } log.print(WvLog.L.Debug2, "Action queue element done.\n"); } } log.print("Done!\n"); return 0; }