4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
47 ARG_DISALLOW_MODULE_LOADING
,
58 static struct option long_options
[] = {
59 {"help", 0, 0, ARG_HELP
},
60 {"version", 0, 0, ARG_VERSION
},
61 {"dump-conf", 0, 0, ARG_DUMP_CONF
},
62 {"dump-modules", 0, 0, ARG_DUMP_MODULES
},
63 {"daemonize", 2, 0, ARG_DAEMONIZE
},
64 {"fail", 2, 0, ARG_FAIL
},
65 {"verbose", 2, 0, ARG_VERBOSE
},
66 {"high-priority", 2, 0, ARG_HIGH_PRIORITY
},
67 {"disallow-module-loading", 2, 0, ARG_DISALLOW_MODULE_LOADING
},
68 {"exit-idle-time", 2, 0, ARG_EXIT_IDLE_TIME
},
69 {"module-idle-time", 2, 0, ARG_MODULE_IDLE_TIME
},
70 {"scache-idle-time", 2, 0, ARG_SCACHE_IDLE_TIME
},
71 {"log-target", 1, 0, ARG_LOG_TARGET
},
72 {"load", 1, 0, ARG_LOAD
},
73 {"file", 1, 0, ARG_FILE
},
74 {"dl-search-path", 1, 0, ARG_DL_SEARCH_PATH
},
75 {"resample-method", 1, 0, ARG_RESAMPLE_METHOD
},
80 void pa_cmdline_help(const char *argv0
) {
83 if ((e
= strrchr(argv0
, '/')))
88 printf("%s [options]\n"
89 " -h, --help Show this help\n"
90 " --version Show version\n"
91 " --dump-conf Dump default configuration\n"
92 " --dump-modules Dump list of available modules\n\n"
94 " -D, --daemonize[=BOOL] Daemonize after startup\n"
95 " --fail[=BOOL] Quit when startup fails\n"
96 " --verbose[=BOOL] Be slightly more verbose\n"
97 " --high-priority[=BOOL] Try to set high process priority (only available as root)\n"
98 " --disallow-module-loading[=BOOL] Disallow module loading after startup\n"
99 " --exit-idle-time=SECS Terminate the daemon when idle and this time passed\n"
100 " --module-idle-time=SECS Unload autoloaded modules when idle and this time passed\n"
101 " --scache-idle-time=SECS Unload autoloaded samples when idle and this time passed\n"
102 " --log-target={auto,syslog,stderr} Specify the log target\n"
103 " -p, --dl-search-path=PATH Set the search path for dynamic shared objects (plugins)\n"
104 " --resample-method=[METHOD] Use the specified resampling method\n\n"
106 " -L, --load=\"MODULE ARGUMENTS\" Load the specified plugin module with the specified argument\n"
107 " -F, --file=FILENAME Run the specified script\n"
108 " -C Open a command line on the running TTY after startup\n\n"
110 " -n Don't load default script file\n", e
);
113 int pa_cmdline_parse(struct pa_daemon_conf
*conf
, int argc
, char *const argv
[], int *d
) {
114 struct pa_strbuf
*buf
= NULL
;
116 assert(conf
&& argc
&& argv
);
118 buf
= pa_strbuf_new();
120 if (conf
->script_commands
)
121 pa_strbuf_puts(buf
, conf
->script_commands
);
123 while ((c
= getopt_long(argc
, argv
, "L:F:ChDnp:", long_options
, NULL
)) != -1) {
127 conf
->cmd
= PA_CMD_HELP
;
131 conf
->cmd
= PA_CMD_VERSION
;
135 conf
->cmd
= PA_CMD_DUMP_CONF
;
138 case ARG_DUMP_MODULES
:
139 conf
->cmd
= PA_CMD_DUMP_MODULES
;
144 pa_strbuf_printf(buf
, "load-module %s\n", optarg
);
149 pa_strbuf_printf(buf
, ".include %s\n", optarg
);
153 pa_strbuf_puts(buf
, "load-module module-cli\n");
158 if ((conf
->daemonize
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
159 pa_log(__FILE__
": --daemonize expects boolean argument\n");
165 if ((conf
->fail
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
166 pa_log(__FILE__
": --fail expects boolean argument\n");
172 if ((conf
->verbose
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
173 pa_log(__FILE__
": --verbose expects boolean argument\n");
178 case ARG_HIGH_PRIORITY
:
179 if ((conf
->high_priority
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
180 pa_log(__FILE__
": --high-priority expects boolean argument\n");
185 case ARG_DISALLOW_MODULE_LOADING
:
186 if ((conf
->disallow_module_loading
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
187 pa_log(__FILE__
": --disallow-module-loading expects boolean argument\n");
193 case ARG_DL_SEARCH_PATH
:
194 pa_xfree(conf
->dl_search_path
);
195 conf
->dl_search_path
= *optarg
? pa_xstrdup(optarg
) : NULL
;
199 pa_xfree(conf
->default_script_file
);
200 conf
->default_script_file
= NULL
;
204 if (pa_daemon_conf_set_log_target(conf
, optarg
) < 0) {
205 pa_log(__FILE__
": Invalid log target: use either 'syslog', 'stderr' or 'auto'.\n");
210 case ARG_EXIT_IDLE_TIME
:
211 conf
->exit_idle_time
= atoi(optarg
);
214 case ARG_MODULE_IDLE_TIME
:
215 conf
->module_idle_time
= atoi(optarg
);
218 case ARG_SCACHE_IDLE_TIME
:
219 conf
->scache_idle_time
= atoi(optarg
);
222 case ARG_RESAMPLE_METHOD
:
223 if (pa_daemon_conf_set_resample_method(conf
, optarg
) < 0) {
224 pa_log(__FILE__
": Invalid resample method '%s'.\n", optarg
);
234 pa_xfree(conf
->script_commands
);
235 conf
->script_commands
= pa_strbuf_tostring_free(buf
);
237 if (!conf
->script_commands
) {
238 pa_xfree(conf
->script_commands
);
239 conf
->script_commands
= NULL
;