static int is_root;
/*
- * Stop all threads by closing the thread quit pipe.
+ * Notify the main thread to initiate the teardown of the worker threads by
+ * writing to the main quit pipe.
*/
-static void stop_threads(void)
+static void notify_main_quit_pipe(void)
{
int ret;
/* Stopping all threads */
- DBG("Terminating all threads");
- ret = sessiond_notify_quit_pipe();
+ DBG("Notify the main thread to terminate all worker threads");
+ ret = sessiond_notify_main_quit_pipe();
if (ret < 0) {
- ERR("write error on thread quit pipe");
+ ERR("write error on main quit pipe");
}
}
DBG("Cleanup sessiond");
/*
- * Close the thread quit pipe. It has already done its job,
- * since we are now called.
+ * Close the main quit pipe. It has already done its job, since we are
+ * now cleaning up.
*/
- sessiond_close_quit_pipe();
+ sessiond_close_main_quit_pipe();
+
+ /* Close all other pipes. */
utils_close_pipe(apps_cmd_pipe);
utils_close_pipe(apps_cmd_notify_pipe);
utils_close_pipe(the_kernel_poll_pipe);
switch (sig) {
case SIGINT:
DBG("SIGINT caught");
- stop_threads();
+ notify_main_quit_pipe();
break;
case SIGTERM:
DBG("SIGTERM caught");
- stop_threads();
+ notify_main_quit_pipe();
break;
case SIGUSR1:
CMM_STORE_SHARED(recv_child_signal, 1);
goto stop_threads;
}
- /* Create thread quit pipe */
- if (sessiond_init_thread_quit_pipe()) {
+ /* Create main quit pipe */
+ if (sessiond_init_main_quit_pipe()) {
retval = -1;
goto stop_threads;
}
if (!rotation_thread_handle) {
retval = -1;
ERR("Failed to create rotation thread shared data");
- stop_threads();
goto stop_threads;
}
* signal that asks threads to teardown).
*/
- /* Initiate teardown once activity occurs on the quit pipe. */
- sessiond_wait_for_quit_pipe(-1);
+ /* Initiate teardown once activity occurs on the main quit pipe. */
+ sessiond_wait_for_main_quit_pipe(-1);
stop_threads:
+ DBG("Terminating all threads");
+
/*
* Ensure that the client thread is no longer accepting new commands,
* which could cause new sessions to be created.