X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=audiod.c;h=032b608cbc3acb32e537350fffba2a01aa27c099;hb=786010c598f79d20280e6ea9ea458cad4a7e9af7;hp=bcead91ff11ab61582f8fd1b98197cc96433d608;hpb=7d1805d1559e08e0af701155574aef220925d411;p=paraslash.git diff --git a/audiod.c b/audiod.c index bcead91f..032b608c 100644 --- a/audiod.c +++ b/audiod.c @@ -22,14 +22,13 @@ #include "audiod.cmdline.h" #include "list.h" -#include "close_on_fork.h" #include "sched.h" #include "recv.h" #include "filter.h" #include "grab_client.cmdline.h" #include "grab_client.h" - -#include "error.h" +#include "client.cmdline.h" +#include "client.h" #include "audiod.h" #include "net.h" #include "daemon.h" @@ -37,6 +36,7 @@ #include "fd.h" #include "write.h" #include "write_common.h" +#include "error.h" /** define the array of error lists needed by para_audiod */ INIT_AUDIOD_ERRLISTS; @@ -70,9 +70,8 @@ struct slot_info slot[MAX_STREAM_SLOTS]; int audiod_status = AUDIOD_ON; -struct gengetopt_args_info conf; -static char *af_status, /* the audio format announced in server status */ - *socket_name; +struct audiod_args_info conf; +static char *socket_name; static FILE *logfile; static struct audio_format_info afi[NUM_AUDIO_FORMATS]; @@ -164,10 +163,8 @@ static void setup_signal_handling(void) PARA_INFO_LOG("signal pipe: fd %d\n", sig_task->fd); para_install_sighandler(SIGINT); para_install_sighandler(SIGTERM); - para_install_sighandler(SIGCHLD); para_install_sighandler(SIGHUP); - para_install_sighandler(SIGPIPE); -// signal(SIGPIPE, SIG_IGN); + signal(SIGPIPE, SIG_IGN); } static void clear_slot(int slot_num) @@ -262,13 +259,10 @@ static void close_stat_pipe(void) { int i; - if (stat_task->fd < 0) + if (!stat_task->pcd) return; - PARA_NOTICE_LOG("%s", "closing status pipe\n"); - close(stat_task->fd); - del_close_on_fork_list(stat_task->fd); - stat_task->fd = -1; -// kill_all_decoders(); + client_close(stat_task->pcd); + stat_task->pcd = NULL; for (i = 0; i < NUM_STAT_ITEMS; i++) { free(stat_task->stat_item_values[i]); stat_task->stat_item_values[i] = NULL; @@ -289,8 +283,7 @@ void __noreturn clean_exit(int status, const char *msg) PARA_EMERG_LOG("%s\n", msg); if (socket_name) unlink(socket_name); - if (stat_task->fd >= 0) - close_stat_pipe(); + close_stat_pipe(); exit(status); } @@ -451,9 +444,9 @@ static int open_current_receiver(struct sched *s) int i; struct timeval diff; - if (!af_status) + if (!stat_task->af_status || !stat_task->pcd) return 0; - i = get_audio_format_num(af_status); + i = get_audio_format_num(stat_task->af_status); if (i < 0) return 0; if (decoder_running(i)) @@ -529,8 +522,8 @@ static void check_stat_line(char *line) stat_task->playing = strstr(line, "playing")? 1 : 0; break; case SI_FORMAT: - free(af_status); - af_status = para_strdup(line + ilen + 1); + free(stat_task->af_status); + stat_task->af_status = para_strdup(line + ilen + 1); break; case SI_OFFSET: stat_task->offset_seconds = atoi(line + ilen + 1); @@ -556,13 +549,6 @@ static void check_stat_line(char *line) static void handle_signal(int sig) { switch (sig) { - case SIGCHLD: - for (;;) { - pid_t pid = para_reap_child(); - if (pid <= 0) - return; - PARA_CRIT_LOG("para_client died (pid %d)\n", pid); - } case SIGINT: case SIGTERM: case SIGHUP: @@ -882,24 +868,10 @@ static int audiod_get_socket(void) PARA_EMERG_LOG("%s", "can not listen on socket\n"); exit(EXIT_FAILURE); /* do not unlink socket */ } - add_close_on_fork_list(fd); + mark_fd_nonblock(fd); return fd; } -static int open_stat_pipe(void) -{ - int ret, fd[3] = {-1, 1, 0}; - pid_t pid; - ret = para_exec_cmdline_pid(&pid, BINDIR "/para_client stat", fd); - if (ret >= 0) { - ret = fd[1]; - PARA_NOTICE_LOG("stat pipe opened, fd %d\n", ret); - add_close_on_fork_list(ret); - } else - clean_exit(EXIT_FAILURE, "failed to open status pipe"); - return ret; -} - void signal_event_handler(struct task *t) { struct signal_task *st = t->private_data; @@ -968,6 +940,15 @@ static void init_command_task(struct command_task *ct) sprintf(ct->task.status, "command task"); } +static void client_task_event_handler(__a_unused struct task *t) +{ + struct private_client_data *pcd = t->private_data; + if (t->ret == -E_HANDSHAKE_COMPLETE) + return; + unregister_task(t); + pcd->eof = 1; +} + static void status_event_handler(__a_unused struct task *t) { struct timeval delay = {1, 0}; @@ -985,34 +966,34 @@ static void status_event_handler(__a_unused struct task *t) static void status_pre_select(struct sched *s, struct task *t) { struct status_task *st = t->private_data; + int argc = 2; + char *argv[] = {"audiod", "stat", NULL}; t->ret = 1; - if (st->fd >= 0 && audiod_status == AUDIOD_OFF) + if (st->pcd && (audiod_status == AUDIOD_OFF || st->pcd->eof)) close_stat_pipe(); - if (st->fd < 0 && audiod_status != AUDIOD_OFF + if (!st->pcd && audiod_status != AUDIOD_OFF && tv_diff(now, &st->restart_barrier, NULL) > 0) { - st->fd = open_stat_pipe(); - st->loaded = 0; - st->buf[0] = '\0'; + t->ret = client_parse_config(argc, argv, &st->pcd); + if (t->ret < 0) + return; + t->ret = client_open(st->pcd); + if (t->ret < 0) + return; + st->pcd->task.event_handler = client_task_event_handler; + s->timeout.tv_sec = 0; + s->timeout.tv_usec = 1; } - if (st->fd >= 0 && audiod_status != AUDIOD_OFF) - para_fd_set(st->fd, &s->rfds, &s->max_fileno); } -static void status_post_select(struct sched *s, struct task *t) +static void status_post_select(__a_unused struct sched *s, struct task *t) { struct status_task *st = t->private_data; t->ret = 1; - if (st->fd < 0 || !FD_ISSET(st->fd, &s->rfds)) - return; - t->ret = read(st->fd, st->buf + st->loaded, STRINGSIZE - 1 - st->loaded); - if (t->ret <= 0) { - if (!t->ret) - t->ret = -E_STATUS_EOF; + if (!st->pcd || !st->pcd->loaded + || st->pcd->status != CL_RECEIVING_SERVER_OUTPUT) return; - } - st->buf[t->ret + st->loaded] = '\0'; - st->loaded = for_each_line(st->buf, t->ret + st->loaded, + st->pcd->loaded = for_each_line(st->pcd->buf, st->pcd->loaded, &check_stat_line); } @@ -1023,7 +1004,6 @@ static void init_status_task(struct status_task *st) st->task.post_select = status_post_select; st->task.event_handler = status_event_handler; st->task.private_data = st; - st->fd = -1; st->sa_time_diff_sign = 1; sprintf(st->task.status, "status task"); } @@ -1053,14 +1033,12 @@ int main(int argc, char *argv[]) struct command_task command_task_struct, *cmd_task = &command_task_struct; struct task audiod_task_struct, *audiod_task = &audiod_task_struct; - init_sched(); - valid_fd_012(); - cmdline_parser(argc, argv, &conf); + audiod_cmdline_parser(argc, argv, &conf); para_drop_privileges(conf.user_arg, conf.group_arg); cf = configfile_exists(); if (cf) { - if (cmdline_parser_configfile(cf, &conf, 0, 0, 0)) { + if (audiod_cmdline_parser_configfile(cf, &conf, 0, 0, 0)) { PARA_EMERG_LOG("%s", "parse error in config file\n"); exit(EXIT_FAILURE); } @@ -1093,7 +1071,7 @@ int main(int argc, char *argv[]) register_task(&cmd_task->task); register_task(&stat_task->task); register_task(audiod_task); - s.default_timeout.tv_sec = 3; + s.default_timeout.tv_sec = 0; s.default_timeout.tv_usec = 99 * 1000; ret = sched(&s);