- for (;;) {
- int max_fileno = -1, check_write = 0;
- ssize_t len;
- fd_set rfd, wfd;
- FD_ZERO(&rfd);
- FD_ZERO(&wfd);
- if (loaded && loaded > 10000)
- fprintf(stderr, "loaded: %d\n", loaded);
- if (loaded < conf.bufsize_arg) {
- FD_SET(fd, &rfd);
- max_fileno = PARA_MAX(max_fileno, fd);
- }
- if (loaded > 0) {
- FD_SET(STDOUT_FILENO, &wfd);
- max_fileno = PARA_MAX(max_fileno, STDOUT_FILENO);
- check_write = 1;
- }
- ret = -E_OVERRUN;
- if (max_fileno < 0)
- goto out;
- ret = para_select(max_fileno + 1, &rfd, &wfd, NULL);
- if (ret < 0) {
- ret = -E_SELECT;
- goto out;
- }
- if (loaded < conf.bufsize_arg && FD_ISSET(fd, &rfd)) {
- len = recv_bin_buffer(fd, buf + loaded,
- conf.bufsize_arg - loaded);
- if (len <= 0) {
- ret = len < 0? -E_READ : 0;
- goto out;
- }
- loaded += len;
- }
- if (check_write && FD_ISSET(STDOUT_FILENO, &wfd)) {
- ret = write(STDOUT_FILENO, buf, loaded);
- if (ret < 0) {
- ret = -E_WRITE;
- goto out;
- }
- loaded -= ret;
- }
+ para_log = i9e_log;
+ ret = schedule(&sched);
+ sched_shutdown(&sched);
+ i9e_close();
+ para_log = stderr_log;
+out:
+ free(history_file);
+ free(socket_name);
+ if (ret < 0)
+ PARA_ERROR_LOG("%s\n", para_strerror(-ret));
+ exit(ret < 0? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+__noreturn static void print_completions(void)
+{
+ int ret = i9e_print_completions(audiod_completers);
+ exit(ret <= 0? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+#else /* HAVE_READLINE */
+
+__noreturn static void interactive_session(void)
+{
+ PARA_EMERG_LOG("interactive sessions not available\n");
+ exit(EXIT_FAILURE);
+}
+
+__noreturn static void print_completions(void)
+{
+ PARA_EMERG_LOG("command completion not available\n");
+ exit(EXIT_FAILURE);
+}
+
+#endif /* HAVE_READLINE */
+
+static void handle_help_flag(void)
+{
+ char *help;
+
+ if (OPT_GIVEN(DETAILED_HELP))
+ help = lls_long_help(CMD_PTR);
+ else if (OPT_GIVEN(HELP))
+ help = lls_short_help(CMD_PTR);
+ else
+ return;
+ printf("%s\n", help);
+ free(help);
+ exit(EXIT_SUCCESS);
+}
+
+/**
+ * The client program to connect to para_audiod.
+ *
+ * \param argc Usual argument count.
+ * \param argv Usual argument vector.
+ *
+ * It connects to the "well-known" local socket to communicate with
+ * para_audiod. Authentication is performed by sending a ucred buffer
+ * containing the user id to the local socket.
+ *
+ * Any data received from the socket is written to stdout.
+ *
+ * \return EXIT_SUCCESS or EXIT_FAILURE.
+ *
+ * \sa \ref send_cred_buffer(), para_audioc(1), para_audiod(1).
+ */
+int main(int argc, char *argv[])
+{
+ int ret, fd;
+ char *buf, *args, *errctx = NULL;
+ size_t bufsize;
+ unsigned num_inputs;
+
+ ret = lls(lls_parse(argc, argv, CMD_PTR, &lpr, &errctx));
+ if (ret < 0)
+ goto fail;
+ version_handle_flag("audioc", OPT_GIVEN(VERSION));
+ handle_help_flag();
+ ret = lsu_merge_config_file_options(NULL, "audioc.conf",
+ &lpr, CMD_PTR, audioc_suite, 0 /* default flags */);
+ if (ret < 0)
+ goto fail;
+ loglevel = OPT_UINT32_VAL(LOGLEVEL);
+ if (OPT_GIVEN(COMPLETE))
+ print_completions();
+ if (OPT_GIVEN(SOCKET))
+ socket_name = para_strdup(OPT_STRING_VAL(SOCKET));
+ else {
+ char *hn = para_hostname();
+ socket_name = make_message("/var/paraslash/audiod_socket.%s",
+ hn);
+ free(hn);