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 Lesser 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 Lesser 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
38 /* Argument codes for getopt_long() */
48 ARG_DISALLOW_MODULE_LOADING
,
62 /* Tabel for getopt_long() */
63 static struct option long_options
[] = {
64 {"help", 0, 0, ARG_HELP
},
65 {"version", 0, 0, ARG_VERSION
},
66 {"dump-conf", 0, 0, ARG_DUMP_CONF
},
67 {"dump-modules", 0, 0, ARG_DUMP_MODULES
},
68 {"daemonize", 2, 0, ARG_DAEMONIZE
},
69 {"fail", 2, 0, ARG_FAIL
},
70 {"verbose", 2, 0, ARG_VERBOSE
},
71 {"high-priority", 2, 0, ARG_HIGH_PRIORITY
},
72 {"disallow-module-loading", 2, 0, ARG_DISALLOW_MODULE_LOADING
},
73 {"exit-idle-time", 2, 0, ARG_EXIT_IDLE_TIME
},
74 {"module-idle-time", 2, 0, ARG_MODULE_IDLE_TIME
},
75 {"scache-idle-time", 2, 0, ARG_SCACHE_IDLE_TIME
},
76 {"log-target", 1, 0, ARG_LOG_TARGET
},
77 {"load", 1, 0, ARG_LOAD
},
78 {"file", 1, 0, ARG_FILE
},
79 {"dl-search-path", 1, 0, ARG_DL_SEARCH_PATH
},
80 {"resample-method", 1, 0, ARG_RESAMPLE_METHOD
},
81 {"kill", 0, 0, ARG_KILL
},
82 {"use-pid-file", 2, 0, ARG_USE_PID_FILE
},
83 {"check", 0, 0, ARG_CHECK
},
87 void pa_cmdline_help(const char *argv0
) {
90 if ((e
= strrchr(argv0
, '/')))
95 printf("%s [options]\n\n"
97 " -h, --help Show this help\n"
98 " --version Show version\n"
99 " --dump-conf Dump default configuration\n"
100 " --dump-modules Dump list of available modules\n"
101 " -k --kill Kill a running daemon\n"
102 " --check Check for a running daemon\n\n"
105 " -D, --daemonize[=BOOL] Daemonize after startup\n"
106 " --fail[=BOOL] Quit when startup fails\n"
107 " --verbose[=BOOL] Be slightly more verbose\n"
108 " --high-priority[=BOOL] Try to set high process priority\n"
109 " (only available as root)\n"
110 " --disallow-module-loading[=BOOL] Disallow module loading after startup\n"
111 " --exit-idle-time=SECS Terminate the daemon when idle and this\n"
113 " --module-idle-time=SECS Unload autoloaded modules when idle and\n"
114 " this time passed\n"
115 " --scache-idle-time=SECS Unload autoloaded samples when idle and\n"
116 " this time passed\n"
117 " --log-target={auto,syslog,stderr} Specify the log target\n"
118 " -p, --dl-search-path=PATH Set the search path for dynamic shared\n"
119 " objects (plugins)\n"
120 " --resample-method=[METHOD] Use the specified resampling method\n"
121 " (one of src-sinc-medium-quality,\n"
122 " src-sinc-best-quality,src-sinc-fastest\n"
123 " src-zero-order-hold,src-linear,trivial)\n"
124 " --use-pid-file[=BOOL] Create a PID file\n\n"
127 " -L, --load=\"MODULE ARGUMENTS\" Load the specified plugin module with\n"
128 " the specified argument\n"
129 " -F, --file=FILENAME Run the specified script\n"
130 " -C Open a command line on the running TTY\n"
133 " -n Don't load default script file\n", e
);
136 int pa_cmdline_parse(struct pa_daemon_conf
*conf
, int argc
, char *const argv
[], int *d
) {
137 struct pa_strbuf
*buf
= NULL
;
139 assert(conf
&& argc
&& argv
);
141 buf
= pa_strbuf_new();
143 if (conf
->script_commands
)
144 pa_strbuf_puts(buf
, conf
->script_commands
);
146 while ((c
= getopt_long(argc
, argv
, "L:F:ChDnp:k", long_options
, NULL
)) != -1) {
150 conf
->cmd
= PA_CMD_HELP
;
154 conf
->cmd
= PA_CMD_VERSION
;
158 conf
->cmd
= PA_CMD_DUMP_CONF
;
161 case ARG_DUMP_MODULES
:
162 conf
->cmd
= PA_CMD_DUMP_MODULES
;
167 conf
->cmd
= PA_CMD_KILL
;
171 conf
->cmd
= PA_CMD_CHECK
;
176 pa_strbuf_printf(buf
, "load-module %s\n", optarg
);
181 pa_strbuf_printf(buf
, ".include %s\n", optarg
);
185 pa_strbuf_puts(buf
, "load-module module-cli\n");
190 if ((conf
->daemonize
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
191 pa_log(__FILE__
": --daemonize expects boolean argument\n");
197 if ((conf
->fail
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
198 pa_log(__FILE__
": --fail expects boolean argument\n");
204 if ((conf
->verbose
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
205 pa_log(__FILE__
": --verbose expects boolean argument\n");
210 case ARG_HIGH_PRIORITY
:
211 if ((conf
->high_priority
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
212 pa_log(__FILE__
": --high-priority expects boolean argument\n");
217 case ARG_DISALLOW_MODULE_LOADING
:
218 if ((conf
->disallow_module_loading
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
219 pa_log(__FILE__
": --disallow-module-loading expects boolean argument\n");
224 case ARG_USE_PID_FILE
:
225 if ((conf
->use_pid_file
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
226 pa_log(__FILE__
": --use-pid-file expects boolean argument\n");
232 case ARG_DL_SEARCH_PATH
:
233 pa_xfree(conf
->dl_search_path
);
234 conf
->dl_search_path
= *optarg
? pa_xstrdup(optarg
) : NULL
;
238 pa_xfree(conf
->default_script_file
);
239 conf
->default_script_file
= NULL
;
243 if (pa_daemon_conf_set_log_target(conf
, optarg
) < 0) {
244 pa_log(__FILE__
": Invalid log target: use either 'syslog', 'stderr' or 'auto'.\n");
249 case ARG_EXIT_IDLE_TIME
:
250 conf
->exit_idle_time
= atoi(optarg
);
253 case ARG_MODULE_IDLE_TIME
:
254 conf
->module_idle_time
= atoi(optarg
);
257 case ARG_SCACHE_IDLE_TIME
:
258 conf
->scache_idle_time
= atoi(optarg
);
261 case ARG_RESAMPLE_METHOD
:
262 if (pa_daemon_conf_set_resample_method(conf
, optarg
) < 0) {
263 pa_log(__FILE__
": Invalid resample method '%s'.\n", optarg
);
273 pa_xfree(conf
->script_commands
);
274 conf
->script_commands
= pa_strbuf_tostring_free(buf
);
276 if (!conf
->script_commands
) {
277 pa_xfree(conf
->script_commands
);
278 conf
->script_commands
= NULL
;