static int parse_resample_method(pa_config_parser_state *state) { pa_daemon_conf *c; pa_assert(state); c = state->data; if (pa_daemon_conf_set_resample_method(c, state->rvalue) < 0) { pa_log(_("[%s:%u] Invalid resample method '%s'."), state->filename, state->lineno, state->rvalue); return -1; } return 0; }
static int parse_resample_method(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) { pa_daemon_conf *c = data; pa_assert(filename); pa_assert(lvalue); pa_assert(rvalue); pa_assert(data); if (pa_daemon_conf_set_resample_method(c, rvalue) < 0) { pa_log(_("[%s:%u] Invalid resample method '%s'."), filename, line, rvalue); return -1; } return 0; }
int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d) { pa_strbuf *buf = NULL; int c; int b; pa_assert(conf); pa_assert(argc > 0); pa_assert(argv); buf = pa_strbuf_new(); if (conf->script_commands) pa_strbuf_puts(buf, conf->script_commands); while ((c = getopt_long(argc, argv, "L:F:ChDnp:kv", long_options, NULL)) != -1) { switch (c) { case ARG_HELP: case 'h': conf->cmd = PA_CMD_HELP; break; case ARG_VERSION: conf->cmd = PA_CMD_VERSION; break; case ARG_DUMP_CONF: conf->cmd = PA_CMD_DUMP_CONF; break; case ARG_DUMP_MODULES: conf->cmd = PA_CMD_DUMP_MODULES; break; case ARG_DUMP_RESAMPLE_METHODS: conf->cmd = PA_CMD_DUMP_RESAMPLE_METHODS; break; case ARG_CLEANUP_SHM: conf->cmd = PA_CMD_CLEANUP_SHM; break; case 'k': case ARG_KILL: conf->cmd = PA_CMD_KILL; break; case ARG_START: conf->cmd = PA_CMD_START; conf->daemonize = true; break; case ARG_CHECK: conf->cmd = PA_CMD_CHECK; break; case ARG_LOAD: case 'L': pa_strbuf_printf(buf, "load-module %s\n", optarg); break; case ARG_FILE: case 'F': { char *p; pa_strbuf_printf(buf, ".include %s\n", p = pa_make_path_absolute(optarg)); pa_xfree(p); break; } case 'C': pa_strbuf_puts(buf, "load-module module-cli exit_on_eof=1\n"); break; case ARG_DAEMONIZE: case 'D': if ((b = optarg ? pa_parse_boolean(optarg) : 1) < 0) { pa_log(_("--daemonize expects boolean argument")); goto fail; } conf->daemonize = !!b; break; case ARG_FAIL: if ((b = optarg ? pa_parse_boolean(optarg) : 1) < 0) { pa_log(_("--fail expects boolean argument")); goto fail; } conf->fail = !!b; break; case 'v': case ARG_LOG_LEVEL: if (optarg) { if (pa_daemon_conf_set_log_level(conf, optarg) < 0) { pa_log(_("--log-level expects log level argument (either numeric in range 0..4 or one of debug, info, notice, warn, error).")); goto fail; } } else { if (conf->log_level < PA_LOG_LEVEL_MAX-1) conf->log_level++; } break; case ARG_HIGH_PRIORITY: if ((b = optarg ? pa_parse_boolean(optarg) : 1) < 0) { pa_log(_("--high-priority expects boolean argument")); goto fail; } conf->high_priority = !!b; break; case ARG_REALTIME: if ((b = optarg ? pa_parse_boolean(optarg) : 1) < 0) { pa_log(_("--realtime expects boolean argument")); goto fail; } conf->realtime_scheduling = !!b; break; case ARG_DISALLOW_MODULE_LOADING: if ((b = optarg ? pa_parse_boolean(optarg) : 1) < 0) { pa_log(_("--disallow-module-loading expects boolean argument")); goto fail; } conf->disallow_module_loading = !!b; break; case ARG_DISALLOW_EXIT: if ((b = optarg ? pa_parse_boolean(optarg) : 1) < 0) { pa_log(_("--disallow-exit expects boolean argument")); goto fail; } conf->disallow_exit = !!b; break; case ARG_USE_PID_FILE: if ((b = optarg ? pa_parse_boolean(optarg) : 1) < 0) { pa_log(_("--use-pid-file expects boolean argument")); goto fail; } conf->use_pid_file = !!b; break; case 'p': case ARG_DL_SEARCH_PATH: pa_xfree(conf->dl_search_path); conf->dl_search_path = pa_xstrdup(optarg); break; case 'n': conf->load_default_script_file = false; break; case ARG_LOG_TARGET: if (pa_daemon_conf_set_log_target(conf, optarg) < 0) { #ifdef HAVE_SYSTEMD_JOURNAL pa_log(_("Invalid log target: use either 'syslog', 'journal','stderr' or 'auto' or a valid file name 'file:<path>', 'newfile:<path>'.")); #else pa_log(_("Invalid log target: use either 'syslog', 'stderr' or 'auto' or a valid file name 'file:<path>', 'newfile:<path>'.")); #endif goto fail; } break; case ARG_LOG_TIME: if ((b = optarg ? pa_parse_boolean(optarg) : 1) < 0) { pa_log(_("--log-time expects boolean argument")); goto fail; } conf->log_time = !!b; break; case ARG_LOG_META: if ((b = optarg ? pa_parse_boolean(optarg) : 1) < 0) { pa_log(_("--log-meta expects boolean argument")); goto fail; } conf->log_meta = !!b; break; case ARG_LOG_BACKTRACE: conf->log_backtrace = (unsigned) atoi(optarg); break; case ARG_EXIT_IDLE_TIME: conf->exit_idle_time = atoi(optarg); break; case ARG_SCACHE_IDLE_TIME: conf->scache_idle_time = atoi(optarg); break; case ARG_RESAMPLE_METHOD: if (pa_daemon_conf_set_resample_method(conf, optarg) < 0) { pa_log(_("Invalid resample method '%s'."), optarg); goto fail; } break; case ARG_SYSTEM: if ((b = optarg ? pa_parse_boolean(optarg) : 1) < 0) { pa_log(_("--system expects boolean argument")); goto fail; } conf->system_instance = !!b; break; case ARG_NO_CPU_LIMIT: if ((b = optarg ? pa_parse_boolean(optarg) : 1) < 0) { pa_log(_("--no-cpu-limit expects boolean argument")); goto fail; } conf->no_cpu_limit = !!b; break; case ARG_DISABLE_SHM: if ((b = optarg ? pa_parse_boolean(optarg) : 1) < 0) { pa_log(_("--disable-shm expects boolean argument")); goto fail; } conf->disable_shm = !!b; break; case ARG_ENABLE_MEMFD: if ((b = optarg ? pa_parse_boolean(optarg) : 1) < 0) { pa_log(_("--enable-memfd expects boolean argument")); goto fail; } conf->disable_memfd = !b; break; default: goto fail; } } pa_xfree(conf->script_commands); conf->script_commands = pa_strbuf_to_string_free(buf); *d = optind; return 0; fail: if (buf) pa_strbuf_free(buf); return -1; }