/** \file server.c Paraslash's main server. */
-/**
- * \mainpage Main data structures and selected APIs:
- *
- * - Senders: \ref sender,
- * - Audio file selector: \ref afs_info, \ref afs_table,
- * - Audio format handler: \ref audio_format_handler, \ref afh_info
- * - Receivers/filters/writers: \ref receiver, \ref receiver_node,
- * \ref filter, \ref filter_node, \ref writer_node, \ref writer.
- * - Scheduling: \ref sched.h,
- * - Buffer trees: \ref buffer_tree.h,
- * - Sideband API: \ref sideband.h,
- * - Crypto: \ref crypt.h, \ref crypt_backend.h,
- * - Error subsystem: \ref error.h,
- * - Inter process communication: \ref ipc.h,
- * - Forward error correction: \ref fec.h,
- * - Daemons: \ref daemon.h,
- * - Mixer API: \ref mix.h,
- * - Interactive sessions: \ref interactive.h,
- * - File descriptors: \ref fd.h,
- * - Signals: \ref signal.h,
- * - Networking: \ref net.h,
- * - Time: \ref time.c,
- * - Doubly linked lists: \ref list.h.
- */
-
#include <netinet/in.h>
#include <sys/socket.h>
#include <signal.h>
/** 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). */
+/* The main server process (parent of afs and the command handlers). */
static pid_t server_pid;
/**
mmd->active_connections = 0;
mmd->vss_status_flags = VSS_NEXT;
mmd->new_vss_status_flags = VSS_NEXT;
+ mmd->loglevel = OPT_UINT32_VAL(LOGLEVEL);
return;
destroy_mmd_mutex:
mutex_destroy(mmd_mutex);
exit(EXIT_FAILURE);
}
+/** Get a reference to the supercommand of para_server. */
+#define CMD_PTR (lls_cmd(0, server_suite))
+
/**
* (Re-)read the server configuration files.
*
para_strerror(-ret));
exit(EXIT_FAILURE);
}
- daemon_set_loglevel(ENUM_STRING_VAL(LOGLEVEL));
+ daemon_set_loglevel(OPT_UINT32_VAL(LOGLEVEL));
if (OPT_GIVEN(LOGFILE)) {
daemon_set_logfile(OPT_STRING_VAL(LOGFILE));
daemon_open_log_or_die();
if (pid != afs_pid)
continue;
PARA_EMERG_LOG("fatal: afs died\n");
- kill(0, SIGTERM);
- goto cleanup;
+ goto genocide;
}
break;
/* die on sigint/sigterm. Kill all children too. */
case SIGINT:
case SIGTERM:
PARA_EMERG_LOG("terminating on signal %d\n", signum);
+genocide:
kill(0, SIGTERM);
/*
* We must wait for all of our children to die. For the afs
while (wait(NULL) != -1 || errno != ECHILD)
; /* still at least one child alive */
mutex_lock(mmd_mutex);
-cleanup:
free(mmd->afd.afhi.chunk_table);
task_notify_all(s, E_DEADLY_SIGNAL);
return -E_DEADLY_SIGNAL;
ret = task_get_notification(sct->task);
if (ret < 0)
- return ret;
+ goto fail;
for (n = 0; n < sct->num_listen_fds; n++) {
ret = command_task_accept(n, s, sct);
- if (ret < 0) {
- free(sct->listen_fds);
- return ret;
- }
+ if (ret < 0)
+ goto fail;
}
return 0;
+fail:
+ free(sct->listen_fds);
+ return ret;
}
static void init_server_command_task(struct server_command_task *sct,
.post_select = command_post_select,
.context = sct,
}, &sched);
+ /*
+ * Detect whether the abstract Unix domain socket space is supported,
+ * but do not create the socket. We check this once in server context
+ * so that the command handlers inherit this bit of information and
+ * don't need to check again.
+ */
+ create_local_socket(NULL);
return;
err:
PARA_EMERG_LOG("%s\n", para_strerror(-ret));
if (ret < 0)
goto fail;
server_lpr = cmdline_lpr;
- daemon_set_loglevel(ENUM_STRING_VAL(LOGLEVEL));
+ daemon_set_loglevel(OPT_UINT32_VAL(LOGLEVEL));
daemon_drop_privileges_or_die(OPT_STRING_VAL(USER),
OPT_STRING_VAL(GROUP));
version_handle_flag("server", OPT_GIVEN(VERSION));
init_ipc_or_die(); /* init mmd struct, mmd and log mutex */
daemon_set_start_time();
daemon_set_hooks(pre_log_hook, post_log_hook);
- PARA_NOTICE_LOG("initializing audio format handlers\n");
- afh_init();
-
/*
* Although afs uses its own signal handling we must ignore SIGUSR1
* _before_ the afs child process gets born by init_afs() below. It's
{
int ret;
+ daemon_set_loglevel(mmd->loglevel);
status_refresh();
mutex_unlock(mmd_mutex);
ret = para_select(max_fileno + 1, readfds, writefds, timeout_tv);
deplete_close_on_fork_list();
if (ret < 0)
PARA_EMERG_LOG("%s\n", para_strerror(-ret));
+ vss_shutdown();
} else {
+ vss_shutdown();
alarm(ALARM_TIMEOUT);
close_listed_fds();
ret = handle_connect(sct->child_fd);
}
- vss_shutdown();
shm_detach(mmd);
user_list_deplete();
free_lpr();