(5) fix foo_mem_clean() functions to avoid race cond.
authorkremlin <ian@kremlin.cc>
Tue, 5 Aug 2014 02:18:51 +0000 (21:18 -0500)
committerkremlin <ian@kremlin.cc>
Tue, 5 Aug 2014 02:18:51 +0000 (21:18 -0500)
mem_clean functions previously free()'d our pointer array without
first checking that the name/interface had properly been unexported from
dbus. checking first better guarantees all operations implicating that date
have ceased, and that it is safe to go ahead and stop the GMainLoop before
immediately returning. this causes the code just after the main_loop_begin()
call to start functioning, in our case the actual free() calls (which are now
*absolutley* safe to call)

src/interfaces/localed/localed.c
src/interfaces/logind/logind.c
src/interfaces/timedated/timedated.c

index 10ae7b714337f44bd60f796f908f4e1cdbabed4f..e2fd3f44d201abac9780879291b5dfa396211c27 100644 (file)
@@ -123,8 +123,14 @@ static void localed_on_name_lost(GDBusConnection *conn,
  * this stops our GMainLoop safely before letting main() return */
 void localed_mem_clean() {
 
-    g_ptr_array_foreach(localed_freeable, (GFunc) g_free, NULL);
-       g_ptr_array_free(localed_freeable, TRUE);
+       g_printf("exiting...\n");
+
+       if(dbus_interface_exported)
+               g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(localed_interf));
+
+       if(g_main_loop_is_running(localed_loop))
+               g_main_loop_quit(localed_loop);
+
 }
 
 int main() {
index b08db9f17f3de7d9ddbbde3a3ce56451c8b708b0..78775cf8c2a9ff924f803dedaafd5aa0c657ce6e 100644 (file)
@@ -123,8 +123,14 @@ static void logind_on_name_lost(GDBusConnection *conn,
  * this stops our GMainLoop sfaely before letting main() return */
 void logind_mem_clean() {
 
-    g_ptr_array_foreach(logind_freeable, (GFunc) g_free, NULL);
-       g_ptr_array_free(logind_freeable, TRUE);
+    g_printf("exiting...\n");
+
+    if(dbus_interface_exported)
+        g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(logind_interf));
+
+    if(g_main_loop_is_running(logind_loop))
+        g_main_loop_quit(logind_loop);
+
 }
 
 int main() {
index 3df5fc6e3e1fd956ef15894741f2896eb154680b..72d14f8c80e7b67c6f2476ba96b743f025cbe89b 100644 (file)
@@ -123,8 +123,14 @@ static void timedated_on_name_lost(GDBusConnection *conn,
  * this stops our GMainLoop safely before letting main() return */
 void timedated_mem_clean() {
 
-    g_ptr_array_foreach(timedated_freeable, (GFunc) g_free, NULL);
-       g_ptr_array_free(timedated_freeable, TRUE);
+    g_printf("exiting...\n");
+
+    if(dbus_interface_exported)
+        g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(timedated_interf));
+
+     if(g_main_loop_is_running(timedated_loop))
+        g_main_loop_quit(timedated_loop);
+
 }
 
 int main() {