X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=afs.c;h=58b04a8bafce749308aefe17d42ebaf178d4d45b;hp=03a8d4b97a6c02a0544ff68dba4400dc93dfeb92;hb=ec22c98399a8317cb8310a343ac0030279b58571;hpb=78882bd94652b156e55e6385a33cd5126c439651 diff --git a/afs.c b/afs.c index 03a8d4b9..58b04a8b 100644 --- a/afs.c +++ b/afs.c @@ -75,6 +75,7 @@ struct command_task { struct task task; }; +extern int mmd_mutex; extern struct misc_meta_data *mmd; static int server_socket; @@ -499,7 +500,7 @@ static int pass_afd(int fd, char *buf, size_t size) * * \sa open_and_update_audio_file(). */ -int open_next_audio_file(void) +static int open_next_audio_file(void) { struct osl_row *aft_row; struct audio_file_data afd; @@ -571,15 +572,15 @@ static int activate_mood_or_playlist(char *arg, int *num_admissible) free(current_mop); if (arg) { current_mop = para_strdup(arg); - mmd_lock(); + mutex_lock(mmd_mutex); strncpy(mmd->afs_mode_string, arg, sizeof(mmd->afs_mode_string)); mmd->afs_mode_string[sizeof(mmd->afs_mode_string) - 1] = '\0'; - mmd_unlock(); + mutex_unlock(mmd_mutex); } else { - mmd_lock(); + mutex_lock(mmd_mutex); strcpy(mmd->afs_mode_string, "dummy"); - mmd_unlock(); + mutex_unlock(mmd_mutex); current_mop = NULL; } } @@ -747,12 +748,6 @@ static int open_afs_tables(void) return ret; } -static void unregister_tasks(void) -{ - unregister_task(&command_task_struct.task); - unregister_task(&signal_task_struct.task); -} - static void signal_pre_select(struct sched *s, struct task *t) { struct signal_task *st = container_of(t, struct signal_task, task); @@ -900,28 +895,24 @@ static int call_callback(int fd, int query_shmid) return 1; } -static void execute_server_command(void) +static int execute_server_command(void) { char buf[8]; int ret = recv_bin_buffer(server_socket, buf, sizeof(buf) - 1); if (ret <= 0) { - if (ret < 0) - PARA_ERROR_LOG("%s\n", para_strerror(-ret)); - return; + if (!ret) + ret = -ERRNO_TO_PARA_ERROR(ECONNRESET); + goto err; } buf[ret] = '\0'; PARA_DEBUG_LOG("received: %s\n", buf); - if (!strcmp(buf, "new")) { - ret = open_next_audio_file(); - if (ret < 0) { - PARA_EMERG_LOG("%s\n", para_strerror(-ret)); - unregister_tasks(); - } - return; - } - PARA_ERROR_LOG("unknown command\n"); - + ret = -E_BAD_CMD; + if (strcmp(buf, "new")) + goto err; + ret = open_next_audio_file(); +err: + return ret; } static void execute_afs_command(int fd, uint32_t expected_cookie) @@ -966,8 +957,15 @@ static void command_post_select(struct sched *s, struct task *t) struct sockaddr_un unix_addr; struct afs_client *client, *tmp; int fd, ret; - if (FD_ISSET(server_socket, &s->rfds)) - execute_server_command(); + + if (FD_ISSET(server_socket, &s->rfds)) { + ret = execute_server_command(); + if (ret < 0) { + PARA_EMERG_LOG("%s\n", para_strerror(-ret)); + sched_shutdown(); + return; + } + } /* Check the list of connected clients. */ list_for_each_entry_safe(client, tmp, &afs_client_list, node) { @@ -1025,7 +1023,7 @@ static void register_command_task(uint32_t cookie) */ __noreturn void afs_init(uint32_t cookie, int socket_fd) { - struct sched s; + static struct sched s; int i, ret; register_signal_task();