From 9728ae1fd2b7c7851673a27f698ae2e3c8c03461 Mon Sep 17 00:00:00 2001 From: kremlin Date: Mon, 4 Aug 2014 21:50:37 -0500 Subject: [PATCH] (8) [final] modify main() to call correct clean sequence main() now sets the signal handlers (via function from previous commit) before establishing the GMainLoop as well as invoke the proper clean()'s after unref'ing the loop. at this point all four interfaces are at the same place structurally. builds all cases. --- src/interfaces/localed/localed.c | 7 ++++++- src/interfaces/logind/logind.c | 8 +++++++- src/interfaces/timedated/timedated.c | 7 ++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/interfaces/localed/localed.c b/src/interfaces/localed/localed.c index 27448ac..3fdb7cf 100644 --- a/src/interfaces/localed/localed.c +++ b/src/interfaces/localed/localed.c @@ -152,6 +152,8 @@ void set_signal_handlers() { int main() { + set_signal_handlers(); + localed_loop = g_main_loop_new(NULL, TRUE); localed_freeable = g_ptr_array_new(); @@ -165,11 +167,14 @@ int main() { NULL); g_main_loop_run(localed_loop); + /* runs until single g_main_loop_quit() call is raised inside _mem_clean() */ g_main_loop_unref(localed_loop); + /* guaranteed unownable */ g_bus_unown_name(bus_descriptor); - localed_mem_clean(); + /* at this point no operations can occur with our data, it is safe to free it + its container */ + g_ptr_array_free(localed_freeable, TRUE); return 0; } diff --git a/src/interfaces/logind/logind.c b/src/interfaces/logind/logind.c index da9e24b..274bf16 100644 --- a/src/interfaces/logind/logind.c +++ b/src/interfaces/logind/logind.c @@ -152,6 +152,8 @@ void set_signal_handlers() { int main() { + set_signal_handlers(); + logind_loop = g_main_loop_new(NULL, TRUE); logind_freeable = g_ptr_array_new(); @@ -165,11 +167,15 @@ int main() { NULL); g_main_loop_run(logind_loop); + /* runs until single g_main_loop_quit() call is raised inside _mem_clean() */ g_main_loop_unref(logind_loop); + /* guaranteed unownable */ g_bus_unown_name(bus_descriptor); - logind_mem_clean(); + /* at this point no operations can occur with our data, it is safe to free it + its container */ + g_ptr_array_free(logind_freeable, TRUE); + return 0; } diff --git a/src/interfaces/timedated/timedated.c b/src/interfaces/timedated/timedated.c index 32f040a..a0d536d 100644 --- a/src/interfaces/timedated/timedated.c +++ b/src/interfaces/timedated/timedated.c @@ -152,6 +152,8 @@ void set_signal_handlers() { int main() { + set_signal_handlers(); + timedated_loop = g_main_loop_new(NULL, TRUE); timedated_freeable = g_ptr_array_new(); @@ -165,11 +167,14 @@ int main() { NULL); g_main_loop_run(timedated_loop); + /* runs until single g_main_loop_quit() call is raised inside _mem_clean() */ g_main_loop_unref(timedated_loop); + /* guaranteed unownable */ g_bus_unown_name(bus_descriptor); - timedated_mem_clean(); + /* at this point no operations can occur with our data, it is safe to free it + its container */ + g_ptr_array_free(timedated_freeable, TRUE); return 0; } -- 2.41.0