X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=server.c;h=690f7163984c2f00cb0de1e4982da4668676e500;hp=13c8c85f98339023b90415125e9df275a28c98f3;hb=ced0c17d1a3e;hpb=7f08e8b0eb9570f1eb787dbb4e10d56585b36bbf;ds=sidebyside diff --git a/server.c b/server.c index 13c8c85f..690f7163 100644 --- a/server.c +++ b/server.c @@ -100,6 +100,9 @@ uint32_t afs_socket_cookie; /** The mutex protecting the shared memory area containing the mmd struct. */ int mmd_mutex; +/* Serializes log output. */ +static int log_mutex; + static struct sched sched; static struct signal_task *signal_task; @@ -151,9 +154,17 @@ char *server_get_tasks(void) return get_task_list(&sched); } -/* - * setup shared memory area and get mutex for locking - */ +static void pre_log_hook(void) +{ + mutex_lock(log_mutex); +} + +static void post_log_hook(void) +{ + mutex_unlock(log_mutex); +} + +/* Setup shared memory area and init mutexes */ static void init_ipc_or_die(void) { void *shm; @@ -172,6 +183,10 @@ static void init_ipc_or_die(void) if (ret < 0) goto err_out; mmd_mutex = ret; + ret = mutex_new(); + if (ret < 0) + goto destroy_mmd_mutex; + log_mutex = ret; mmd->num_played = 0; mmd->num_commands = 0; @@ -181,6 +196,8 @@ static void init_ipc_or_die(void) mmd->vss_status_flags = VSS_NEXT; mmd->new_vss_status_flags = VSS_NEXT; return; +destroy_mmd_mutex: + mutex_destroy(mmd_mutex); err_out: PARA_EMERG_LOG("%s\n", para_strerror(-ret)); exit(EXIT_FAILURE); @@ -548,8 +565,9 @@ static void server_init(int argc, char **argv, struct server_command_task *sct) server_pid = getpid(); init_random_seed_or_die(); daemon_log_welcome("server"); - init_ipc_or_die(); /* init mmd struct and mmd->lock */ + 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(); @@ -653,6 +671,8 @@ int main(int argc, char *argv[]) signal_shutdown(signal_task); if (!process_is_command_handler()) { /* parent (server) */ mutex_destroy(mmd_mutex); + daemon_set_hooks(NULL, NULL); /* only one process remaining */ + mutex_destroy(log_mutex); shm_detach(mmd); if (ret < 0) PARA_EMERG_LOG("%s\n", para_strerror(-ret));