X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=audiod.c;h=8d1d8eb8a48235a7a7355b29c633f9aae9be7990;hp=462ecc8baefe442c8b383f253a7a57bb086cf591;hb=298ad3958d76fc775dfd0503ae4b1e43dce70f04;hpb=6df4ed2fc04c7eeb4474e7d152e4374c219c3aac diff --git a/audiod.c b/audiod.c index 462ecc8b..8d1d8eb8 100644 --- a/audiod.c +++ b/audiod.c @@ -104,6 +104,7 @@ struct audiod_command { const char *name; /** pointer to the function that handles the command */ int (*handler)(int, int, char**); +int (*line_handler)(int, char*); /** one-line description of the command */ const char *description; /** summary of the command line options */ @@ -114,7 +115,7 @@ const char *help; extern const char *status_item_list[NUM_STAT_ITEMS]; -static int com_grab(int, int, char **); +static int com_grab(int, char *); static int com_cycle(int, int, char **); static int com_help(int, int, char **); static int com_off(int, int, char **); @@ -150,7 +151,7 @@ static struct audiod_command cmds[] = { }, { .name = "grab", -.handler = com_grab, +.line_handler = com_grab, .description = "grab the audio stream", .synopsis = "-- grab [grab_options]", .help = @@ -368,8 +369,6 @@ __malloc static char *decoder_flags(void) flag += 1; if (s->wpid > 0) flag += 2; - if (flag != '0') - flag += s->format * 4; decoder_flags[i] = flag; } decoder_flags[MAX_STREAM_SLOTS] = '\0'; @@ -696,7 +695,7 @@ static void start_stream_writer(int slot_num) if (a->write_cmd) glob = glob_cmd(a->write_cmd); if (!glob) - glob = para_strdup("para_play"); + glob = para_strdup("para_write -w alsa"); PARA_INFO_LOG("starting stream writer: %s\n", glob); open_filters(slot_num); ret = para_exec_cmdline_pid(&s->wpid, glob, fds); @@ -809,7 +808,7 @@ static void check_stat_line(char *line) long unsigned sec, usec; char *tmp; - PARA_INFO_LOG("line: %s\n", line); +// PARA_INFO_LOG("line: %s\n", line); if (!line) return; itemnum = stat_line_valid(line); @@ -1096,8 +1095,9 @@ static int setup_default_filters(void) free(tmp); if (ret < 0) goto out; - PARA_INFO_LOG("%s -> default filter: %s\n", audio_formats[i], filters[j].name); - ret = add_filter(i, para_strdup("wav")); + PARA_INFO_LOG("%s -> default filter: %s\n", audio_formats[i], + filters[j].name); + ret = add_filter(i, "wav"); if (ret < 0) goto out; PARA_INFO_LOG("%s -> default filter: wav\n", audio_formats[i]); @@ -1334,16 +1334,15 @@ static char *list_filters(void) } #endif -static int com_grab(int fd, int argc, char **argv) + +static int com_grab(int fd, char *cmdline) { struct grab_client *gc; struct filter_node *fn; int i, err; char *msg; - PARA_INFO_LOG("argc: %d, argv[0]: %s, optind: %d\n", argc, argv[0], optind); - gc = grab_client_new(fd, argc, argv, &err); - PARA_INFO_LOG("argc: %d, argv[0]: %s, optind: %d\n", argc, argv[0], optind); + gc = grab_client_new(fd, cmdline, &err); if (!gc) goto err_out; fn = find_filter_node(gc->conf->slot_arg, gc->audio_format_num, gc->conf->filter_num_arg); @@ -1432,7 +1431,7 @@ static int check_perms(uid_t uid) static int handle_connect(void) { int i, argc, ret, clifd = -1; - char *buf = para_malloc(MAXLINE), **argv = NULL; + char *cmd = NULL, *p, *buf = para_calloc(MAXLINE), **argv = NULL; struct sockaddr_un unix_addr; ret = para_accept(audiod_socket, &unix_addr, sizeof(struct sockaddr_un)); @@ -1442,20 +1441,39 @@ static int handle_connect(void) ret = recv_cred_buffer(clifd, buf, MAXLINE - 1); if (ret < 0) goto out; - PARA_INFO_LOG("connection from user %i\n", ret); + PARA_INFO_LOG("connection from user %i, buf: %s\n", ret, buf); ret = check_perms(ret); if (ret < 0) goto out; - argc = split_args(buf, &argv, "\n"); - PARA_INFO_LOG("argv[0]: %s, argc= %d\n", argv[0], argc); + ret = -E_INVALID_AUDIOD_CMD; + cmd = para_strdup(buf); + p = strchr(cmd, '\n'); + if (!p) + p = ""; + else { + *p = '\0'; + p++; + } for (i = 0; cmds[i].name; i++) { - if (strcmp(cmds[i].name, argv[0])) + int j; + if (strcmp(cmds[i].name, cmd)) continue; - ret = cmds[i].handler(clifd, argc, argv); + if (cmds[i].handler) { + argc = split_args(buf, &argv, "\n"); + PARA_INFO_LOG("argv[0]: %s, argc= %d\n", argv[0], argc); + ret = cmds[i].handler(clifd, argc, argv); + goto out; + } + for (j = 0; p[j]; j++) + if (p[j] == '\n') + p[j] = ' '; + PARA_INFO_LOG("cmd: %s, options: %s\n", cmd, p); + ret = cmds[i].line_handler(clifd, p); goto out; } ret = -E_INVALID_AUDIOD_CMD; /* cmd not found */ out: + free(cmd); free(buf); free(argv); if (clifd > 0 && ret < 0 && ret != -E_CLIENT_WRITE) { @@ -1561,9 +1579,9 @@ static void __noreturn audiod_mainloop(void) repeat: FD_ZERO(&wfds); FD_ZERO(&rfds); + max_fileno = -1; /* always check signal pipe and the local socket */ - FD_SET(signal_pipe, &rfds); - max_fileno = signal_pipe; + para_fd_set(signal_pipe, &rfds, &max_fileno); para_fd_set(audiod_socket, &rfds, &max_fileno); if (audiod_status != AUDIOD_ON) @@ -1644,7 +1662,6 @@ int __noreturn main(int argc, char *argv[]) char *cf; int i; - fprintf(stderr, "argc: %d\n", argc); valid_fd_012(); hostname = para_hostname(); cmdline_parser(argc, argv, &conf);