4 This file is part of PulseAudio.
6 PulseAudio 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 PulseAudio 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 PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 #include <pulse/xmalloc.h>
35 #include <pulsecore/core-util.h>
36 #include <pulsecore/strbuf.h>
40 /* Argument codes for getopt_long() */
50 ARG_DISALLOW_MODULE_LOADING
,
66 /* Tabel for getopt_long() */
67 static struct option long_options
[] = {
68 {"help", 0, 0, ARG_HELP
},
69 {"version", 0, 0, ARG_VERSION
},
70 {"dump-conf", 0, 0, ARG_DUMP_CONF
},
71 {"dump-modules", 0, 0, ARG_DUMP_MODULES
},
72 {"daemonize", 2, 0, ARG_DAEMONIZE
},
73 {"fail", 2, 0, ARG_FAIL
},
74 {"verbose", 2, 0, ARG_LOG_LEVEL
},
75 {"log-level", 2, 0, ARG_LOG_LEVEL
},
76 {"high-priority", 2, 0, ARG_HIGH_PRIORITY
},
77 {"disallow-module-loading", 2, 0, ARG_DISALLOW_MODULE_LOADING
},
78 {"exit-idle-time", 2, 0, ARG_EXIT_IDLE_TIME
},
79 {"module-idle-time", 2, 0, ARG_MODULE_IDLE_TIME
},
80 {"scache-idle-time", 2, 0, ARG_SCACHE_IDLE_TIME
},
81 {"log-target", 1, 0, ARG_LOG_TARGET
},
82 {"load", 1, 0, ARG_LOAD
},
83 {"file", 1, 0, ARG_FILE
},
84 {"dl-search-path", 1, 0, ARG_DL_SEARCH_PATH
},
85 {"resample-method", 1, 0, ARG_RESAMPLE_METHOD
},
86 {"kill", 0, 0, ARG_KILL
},
87 {"use-pid-file", 2, 0, ARG_USE_PID_FILE
},
88 {"check", 0, 0, ARG_CHECK
},
89 {"system", 2, 0, ARG_SYSTEM
},
90 {"no-cpu-limit", 2, 0, ARG_NO_CPU_LIMIT
},
94 void pa_cmdline_help(const char *argv0
) {
97 if ((e
= strrchr(argv0
, '/')))
102 printf("%s [options]\n\n"
104 " -h, --help Show this help\n"
105 " --version Show version\n"
106 " --dump-conf Dump default configuration\n"
107 " --dump-modules Dump list of available modules\n"
108 " -k --kill Kill a running daemon\n"
109 " --check Check for a running daemon\n\n"
112 " --system[=BOOL] Run as system-wide instance\n"
113 " -D, --daemonize[=BOOL] Daemonize after startup\n"
114 " --fail[=BOOL] Quit when startup fails\n"
115 " --high-priority[=BOOL] Try to set high process priority\n"
116 " (only available as root)\n"
117 " --disallow-module-loading[=BOOL] Disallow module loading after startup\n"
118 " --exit-idle-time=SECS Terminate the daemon when idle and this\n"
120 " --module-idle-time=SECS Unload autoloaded modules when idle and\n"
121 " this time passed\n"
122 " --scache-idle-time=SECS Unload autoloaded samples when idle and\n"
123 " this time passed\n"
124 " --log-level[=LEVEL] Increase or set verbosity level\n"
125 " -v Increase the verbosity level\n"
126 " --log-target={auto,syslog,stderr} Specify the log target\n"
127 " -p, --dl-search-path=PATH Set the search path for dynamic shared\n"
128 " objects (plugins)\n"
129 " --resample-method=[METHOD] Use the specified resampling method\n"
130 " (one of src-sinc-medium-quality,\n"
131 " src-sinc-best-quality,src-sinc-fastest\n"
132 " src-zero-order-hold,src-linear,trivial)\n"
133 " --use-pid-file[=BOOL] Create a PID file\n"
134 " --no-cpu-limit[=BOOL] Do not install CPU load limiter on\n"
135 " platforms that support it.\n\n"
138 " -L, --load=\"MODULE ARGUMENTS\" Load the specified plugin module with\n"
139 " the specified argument\n"
140 " -F, --file=FILENAME Run the specified script\n"
141 " -C Open a command line on the running TTY\n"
144 " -n Don't load default script file\n", e
);
147 int pa_cmdline_parse(pa_daemon_conf
*conf
, int argc
, char *const argv
[], int *d
) {
148 pa_strbuf
*buf
= NULL
;
150 assert(conf
&& argc
&& argv
);
152 buf
= pa_strbuf_new();
154 if (conf
->script_commands
)
155 pa_strbuf_puts(buf
, conf
->script_commands
);
157 while ((c
= getopt_long(argc
, argv
, "L:F:ChDnp:kv", long_options
, NULL
)) != -1) {
161 conf
->cmd
= PA_CMD_HELP
;
165 conf
->cmd
= PA_CMD_VERSION
;
169 conf
->cmd
= PA_CMD_DUMP_CONF
;
172 case ARG_DUMP_MODULES
:
173 conf
->cmd
= PA_CMD_DUMP_MODULES
;
178 conf
->cmd
= PA_CMD_KILL
;
182 conf
->cmd
= PA_CMD_CHECK
;
187 pa_strbuf_printf(buf
, "load-module %s\n", optarg
);
192 pa_strbuf_printf(buf
, ".include %s\n", optarg
);
196 pa_strbuf_puts(buf
, "load-module module-cli exit_on_eof=1\n");
201 if ((conf
->daemonize
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
202 pa_log("--daemonize expects boolean argument");
208 if ((conf
->fail
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
209 pa_log("--fail expects boolean argument");
218 if (pa_daemon_conf_set_log_level(conf
, optarg
) < 0) {
219 pa_log("--log-level expects log level argument (either numeric in range 0..4 or one of debug, info, notice, warn, error).");
223 if (conf
->log_level
< PA_LOG_LEVEL_MAX
-1)
229 case ARG_HIGH_PRIORITY
:
230 if ((conf
->high_priority
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
231 pa_log("--high-priority expects boolean argument");
236 case ARG_DISALLOW_MODULE_LOADING
:
237 if ((conf
->disallow_module_loading
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
238 pa_log("--disallow-module-loading expects boolean argument");
243 case ARG_USE_PID_FILE
:
244 if ((conf
->use_pid_file
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
245 pa_log("--use-pid-file expects boolean argument");
251 case ARG_DL_SEARCH_PATH
:
252 pa_xfree(conf
->dl_search_path
);
253 conf
->dl_search_path
= *optarg
? pa_xstrdup(optarg
) : NULL
;
257 pa_xfree(conf
->default_script_file
);
258 conf
->default_script_file
= NULL
;
262 if (pa_daemon_conf_set_log_target(conf
, optarg
) < 0) {
263 pa_log("Invalid log target: use either 'syslog', 'stderr' or 'auto'.");
268 case ARG_EXIT_IDLE_TIME
:
269 conf
->exit_idle_time
= atoi(optarg
);
272 case ARG_MODULE_IDLE_TIME
:
273 conf
->module_idle_time
= atoi(optarg
);
276 case ARG_SCACHE_IDLE_TIME
:
277 conf
->scache_idle_time
= atoi(optarg
);
280 case ARG_RESAMPLE_METHOD
:
281 if (pa_daemon_conf_set_resample_method(conf
, optarg
) < 0) {
282 pa_log("Invalid resample method '%s'.", optarg
);
288 if ((conf
->system_instance
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
289 pa_log("--system expects boolean argument");
294 case ARG_NO_CPU_LIMIT
:
295 if ((conf
->no_cpu_limit
= optarg
? pa_parse_boolean(optarg
) : 1) < 0) {
296 pa_log("--no-cpu-limit expects boolean argument");
307 pa_xfree(conf
->script_commands
);
308 conf
->script_commands
= pa_strbuf_tostring_free(buf
);
310 if (!conf
->script_commands
) {
311 pa_xfree(conf
->script_commands
);
312 conf
->script_commands
= NULL
;