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
,
57 static struct option long_options
[] = {
58 {"help", 0, 0, ARG_HELP
},
59 {"version", 0, 0, ARG_VERSION
},
60 {"dump-conf", 0, 0, ARG_DUMP_CONF
},
61 {"dump-modules", 0, 0, ARG_DUMP_MODULES
},
62 {"daemonize", 2, 0, ARG_DAEMONIZE
},
63 {"fail", 2, 0, ARG_FAIL
},
64 {"verbose", 2, 0, ARG_VERBOSE
},
65 {"high-priority", 2, 0, ARG_HIGH_PRIORITY
},
66 {"disallow-module-loading", 2, 0, ARG_DISALLOW_MODULE_LOADING
},
67 {"exit-idle-time", 2, 0, ARG_EXIT_IDLE_TIME
},
68 {"module-idle-time", 2, 0, ARG_MODULE_IDLE_TIME
},
69 {"scache-idle-time", 2, 0, ARG_SCACHE_IDLE_TIME
},
70 {"log-target", 1, 0, ARG_LOG_TARGET
},
71 {"load", 1, 0, ARG_LOAD
},
72 {"file", 1, 0, ARG_FILE
},
73 {"dl-search-path", 1, 0, ARG_DL_SEARCH_PATH
},
78 void pa_cmdline_help(const char *argv0
) {
81 if ((e
= strrchr(argv0
, '/')))
86 printf("%s [options]\n"
87 " -h, --help Show this help\n"
88 " --version Show version\n"
89 " --dump-conf Dump default configuration\n"
90 " --dump-modules Dump list of available modules\n\n"
92 " -D, --daemonize[=BOOL] Daemonize after startup\n"
93 " --fail[=BOOL] Quit when startup fails\n"
94 " --verbose[=BOOL] Be slightly more verbose\n"
95 " --high-priority[=BOOL] Try to set high process priority (only available as root)\n"
96 " --disallow-module-loading[=BOOL] Disallow module loading after startup\n"
97 " --exit-idle-time=SECS Terminate the daemon when idle and this time passed\n"
98 " --module-idle-time=SECS Unload autoloaded modules when idle and this time passed\n"
99 " --scache-idle-time=SECS Unload autoloaded samples when idle and this time passed\n"
100 " --log-target={auto,syslog,stderr} Specify the log target\n"
101 " -p, --dl-search-path=PATH Set the search path for dynamic shared objects (plugins)\n\n"
103 " -L, --load=\"MODULE ARGUMENTS\" Load the specified plugin module with the specified argument\n"
104 " -F, --file=FILENAME Run the specified script\n"
105 " -C Open a command line on the running TTY after startup\n\n"
107 " -n Don't load default script file\n", e
);
110 int pa_cmdline_parse(struct pa_daemon_conf
*conf
, int argc
, char *const argv
[], int *d
) {
111 struct pa_strbuf
*buf
= NULL
;
113 assert(conf
&& argc
&& argv
);
115 buf
= pa_strbuf_new();
117 if (conf
->script_commands
)
118 pa_strbuf_puts(buf
, conf
->script_commands
);
120 while ((c
= getopt_long(argc
, argv
, "L:F:ChDnp:", long_options
, NULL
)) != -1) {
124 conf
->cmd
= PA_CMD_HELP
;
128 conf
->cmd
= PA_CMD_VERSION
;
132 conf
->cmd
= PA_CMD_DUMP_CONF
;
135 case ARG_DUMP_MODULES
:
136 conf
->cmd
= PA_CMD_DUMP_MODULES
;
141 pa_strbuf_printf(buf
, "load-module %s\n", optarg
);
146 pa_strbuf_printf(buf
, ".include %s\n", optarg
);
150 pa_strbuf_puts(buf
, "load-module module-cli\n");
155 if ((conf
->daemonize
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
156 pa_log(__FILE__
": --daemonize expects boolean argument\n");
162 if ((conf
->fail
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
163 pa_log(__FILE__
": --fail expects boolean argument\n");
169 if ((conf
->verbose
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
170 pa_log(__FILE__
": --verbose expects boolean argument\n");
175 case ARG_HIGH_PRIORITY
:
176 if ((conf
->high_priority
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
177 pa_log(__FILE__
": --high-priority expects boolean argument\n");
182 case ARG_DISALLOW_MODULE_LOADING
:
183 if ((conf
->disallow_module_loading
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
184 pa_log(__FILE__
": --disallow-module-loading expects boolean argument\n");
190 case ARG_DL_SEARCH_PATH
:
191 pa_xfree(conf
->dl_search_path
);
192 conf
->dl_search_path
= *optarg
? pa_xstrdup(optarg
) : NULL
;
196 pa_xfree(conf
->default_script_file
);
197 conf
->default_script_file
= NULL
;
201 if (!strcmp(optarg
, "syslog")) {
202 conf
->auto_log_target
= 0;
203 conf
->log_target
= PA_LOG_SYSLOG
;
204 } else if (!strcmp(optarg
, "stderr")) {
205 conf
->auto_log_target
= 0;
206 conf
->log_target
= PA_LOG_STDERR
;
207 } else if (!strcmp(optarg
, "auto"))
208 conf
->auto_log_target
= 1;
210 pa_log(__FILE__
": Invalid log target: use either 'syslog', 'stderr' or 'auto'.\n");
215 case ARG_EXIT_IDLE_TIME
:
216 conf
->exit_idle_time
= atoi(optarg
);
219 case ARG_MODULE_IDLE_TIME
:
220 conf
->module_idle_time
= atoi(optarg
);
223 case ARG_SCACHE_IDLE_TIME
:
224 conf
->scache_idle_time
= atoi(optarg
);
232 pa_xfree(conf
->script_commands
);
233 conf
->script_commands
= pa_strbuf_tostring_free(buf
);
235 if (!conf
->script_commands
) {
236 pa_xfree(conf
->script_commands
);
237 conf
->script_commands
= NULL
;