diff options
author | kremlin <ian@kremlin.cc> | 2014-08-05 10:18:51 +0800 |
---|---|---|
committer | kremlin <ian@kremlin.cc> | 2014-08-05 10:18:51 +0800 |
commit | 5a2ebcdb9775e789cec2d66545a581846f55d937 (patch) | |
tree | 1caa4744472945fa20d75942b34c7d281c9f80b5 | |
parent | ca5a7f9fddc137fca1cb9bdaa9fbfd7525fb03cc (diff) | |
download | systembsd-5a2ebcdb9775e789cec2d66545a581846f55d937.tar systembsd-5a2ebcdb9775e789cec2d66545a581846f55d937.tar.gz systembsd-5a2ebcdb9775e789cec2d66545a581846f55d937.tar.bz2 systembsd-5a2ebcdb9775e789cec2d66545a581846f55d937.tar.lz systembsd-5a2ebcdb9775e789cec2d66545a581846f55d937.tar.xz systembsd-5a2ebcdb9775e789cec2d66545a581846f55d937.tar.zst systembsd-5a2ebcdb9775e789cec2d66545a581846f55d937.zip |
(5) fix foo_mem_clean() functions to avoid race cond.
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)
-rw-r--r-- | src/interfaces/localed/localed.c | 10 | ||||
-rw-r--r-- | src/interfaces/logind/logind.c | 10 | ||||
-rw-r--r-- | src/interfaces/timedated/timedated.c | 10 |
3 files changed, 24 insertions, 6 deletions
diff --git a/src/interfaces/localed/localed.c b/src/interfaces/localed/localed.c index 10ae7b7..e2fd3f4 100644 --- a/src/interfaces/localed/localed.c +++ b/src/interfaces/localed/localed.c @@ -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() { diff --git a/src/interfaces/logind/logind.c b/src/interfaces/logind/logind.c index b08db9f..78775cf 100644 --- a/src/interfaces/logind/logind.c +++ b/src/interfaces/logind/logind.c @@ -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() { diff --git a/src/interfaces/timedated/timedated.c b/src/interfaces/timedated/timedated.c index 3df5fc6..72d14f8 100644 --- a/src/interfaces/timedated/timedated.c +++ b/src/interfaces/timedated/timedated.c @@ -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() { |