/** The process id of the audio file selector process. */
pid_t afs_pid = 0;
+/* The the main server process (parent of afs and the command handlers). */
+static pid_t server_pid;
+
+/**
+ * Tell whether the executing process is a command handler.
+ *
+ * Cleanup on exit must be performed differently for command handlers.
+ *
+ * \return True if the pid of the executing process is neither the server pid
+ * nor the afs pid.
+ */
+bool process_is_command_handler(void)
+{
+ pid_t pid = getpid();
+
+ return pid != afs_pid && pid != server_pid;
+}
+
/** The task responsible for server command handling. */
struct server_command_task {
/** TCP port on which para_server listens for connections. */
/* become daemon */
if (OPT_GIVEN(DAEMON))
daemon_pipe = daemonize(true /* parent waits for SIGTERM */);
+ server_pid = getpid();
init_random_seed_or_die();
daemon_log_welcome("server");
init_ipc_or_die(); /* init mmd struct and mmd->lock */
ret = schedule(&sched);
sched_shutdown(&sched);
signal_shutdown(signal_task);
- if (sct->child_fd < 0) { /* parent (server) */
+ if (!process_is_command_handler()) { /* parent (server) */
if (ret < 0)
PARA_EMERG_LOG("%s\n", para_strerror(-ret));
- } else { /* child (command handler) */
+ } else {
/*
- * We hold the lock: it was re-acquired in server_select()
+ * We hold the mmd lock: it was re-acquired in server_select()
* after the select call.
*/
mutex_unlock(mmd_mutex);
close_listed_fds();
ret = handle_connect(sct->child_fd);
}
+ vss_shutdown();
lls_free_parse_result(server_lpr, CMD_PTR);
if (server_lpr != cmdline_lpr)
lls_free_parse_result(cmdline_lpr, CMD_PTR);