Defer busname ownership until init complete

Avoid race conditions where applications expecting an object to be
present upon recipt of NameOwnerChanged find that the object hasn't
been created yet.

Change-Id: I4236a3898055a84b00e1eaf37f32e0192b683a0f
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/pychassisctl/chassis_control.py b/pychassisctl/chassis_control.py
index 56a2116..71bf533 100755
--- a/pychassisctl/chassis_control.py
+++ b/pychassisctl/chassis_control.py
@@ -239,9 +239,9 @@
     dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 
     bus = get_dbus()
-    name = dbus.service.BusName(DBUS_NAME, bus)
     obj = ChassisControlObject(bus, OBJ_NAME)
     mainloop = gobject.MainLoop()
+    name = dbus.service.BusName(DBUS_NAME, bus)
 
     print "Running ChassisControlService"
     mainloop.run()
diff --git a/pydownloadmgr/download_manager.py b/pydownloadmgr/download_manager.py
index 9dd6c2d..aeb85c7 100644
--- a/pydownloadmgr/download_manager.py
+++ b/pydownloadmgr/download_manager.py
@@ -71,9 +71,9 @@
 if __name__ == '__main__':
     dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
     bus = get_dbus()
-    name = dbus.service.BusName(DBUS_NAME, bus)
     obj = DownloadManagerObject(bus, OBJ_NAME)
     mainloop = gobject.MainLoop()
+    name = dbus.service.BusName(DBUS_NAME, bus)
     
     print "Running Download Manager"
     mainloop.run()
diff --git a/pyfanctl/fan_control.py b/pyfanctl/fan_control.py
index cea2215..bccfe50 100644
--- a/pyfanctl/fan_control.py
+++ b/pyfanctl/fan_control.py
@@ -50,11 +50,11 @@
 	
 	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 	bus = get_dbus()
-	name = dbus.service.BusName(DBUS_NAME,bus)
 	fan_control = FanControl(bus,OBJ_PATH)
 	mainloop = gobject.MainLoop()
    
 	print "Starting fan control"
 	fan_control.setMax()
+	name = dbus.service.BusName(DBUS_NAME,bus)
 	mainloop.run()
 
diff --git a/pyflashbmc/bmc_update.py b/pyflashbmc/bmc_update.py
index 1ffe8e7..5f03b96 100644
--- a/pyflashbmc/bmc_update.py
+++ b/pyflashbmc/bmc_update.py
@@ -293,9 +293,9 @@
     dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 
     bus = get_dbus()
-    name = dbus.service.BusName(DBUS_NAME, bus)
     obj = BmcFlashControl(bus, OBJ_NAME)
     mainloop = gobject.MainLoop()
+    name = dbus.service.BusName(DBUS_NAME, bus)
     
     print "Running Bmc Flash Control"
     mainloop.run()
diff --git a/pyipmitest/ipmi_debug.py b/pyipmitest/ipmi_debug.py
index 0fc6a86..3e0ea18 100644
--- a/pyipmitest/ipmi_debug.py
+++ b/pyipmitest/ipmi_debug.py
@@ -86,10 +86,10 @@
 def main():
     dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
     bus = dbus.SystemBus()
-    name = dbus.service.BusName(DBUS_NAME, bus)
     obj = IpmiDebug(bus, OBJ_NAME)
     mainloop = gobject.MainLoop()
     r = ConsoleReader(obj)
+    name = dbus.service.BusName(DBUS_NAME, bus)
 
     print ("Enter IPMI packet as hex values. First three bytes will be used"
             "as netfn and cmd.\nlun will be zero.")
diff --git a/pysensormgr/sensor_manager2.py b/pysensormgr/sensor_manager2.py
index d8fa013..34ea0fc 100644
--- a/pysensormgr/sensor_manager2.py
+++ b/pysensormgr/sensor_manager2.py
@@ -45,7 +45,6 @@
 if __name__ == '__main__':
 	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 	bus = get_dbus()
-	name = dbus.service.BusName(DBUS_NAME,bus)
 	root_sensor = SensorManager(bus,OBJ_PATH)
 
 
@@ -60,6 +59,7 @@
 		root_sensor.add(obj_path, sensor_obj)
 
 	mainloop = gobject.MainLoop()
+	name = dbus.service.BusName(DBUS_NAME,bus)
 	print "Starting sensor manager"
 	mainloop.run()
 
diff --git a/pysystemmgr/system_manager.py b/pysystemmgr/system_manager.py
index 6af8727..9625c45 100644
--- a/pysystemmgr/system_manager.py
+++ b/pysystemmgr/system_manager.py
@@ -274,9 +274,9 @@
 if __name__ == '__main__':
     dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
     bus = get_dbus()
-    name = dbus.service.BusName(DBUS_NAME,bus)
     obj = SystemManager(bus,OBJ_NAME)
     mainloop = gobject.MainLoop()
+    name = dbus.service.BusName(DBUS_NAME,bus)
 
     print "Running SystemManager"
     mainloop.run()