summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/modules.html.in4
-rw-r--r--doc/todo1
-rw-r--r--src/daemon/cmdline.c2
-rw-r--r--src/modules/module-cli.c58
4 files changed, 51 insertions, 14 deletions
diff --git a/doc/modules.html.in b/doc/modules.html.in
index af6b6de6..85479523 100644
--- a/doc/modules.html.in
+++ b/doc/modules.html.in
@@ -193,7 +193,9 @@ once.</p>
<p>For an explanation of the simple command line language used by this
module see <a href="cli.html"><tt>cli.html</tt></a>.
-<p>This module doesn't accept any arguments.</p>
+<table>
+ <tr><td><tt>exit_on_eof=</tt></td><td>Accepts a binary numerical argument specifying whether the daemon shuld exit after an EOF was recieved from STDIN (default: 0)</td></tr>
+</table>
<a name="module-cli-protocol-unix"/>
<a name="module-cli-protocol-tcp"/>
diff --git a/doc/todo b/doc/todo
index 7b83ea98..1ea40d3e 100644
--- a/doc/todo
+++ b/doc/todo
@@ -35,7 +35,6 @@ Post 0.9.0:
- check if using prctl(PR_GET_NAME) makes sense in pa_get_binary_name()
- gconf module + frontend
- hooks for creating sink inputs
-- module-cli argument exit-on-eof
Long term:
- pass meta info for hearing impaired
diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c
index 21fd5a25..b71be2e6 100644
--- a/src/daemon/cmdline.c
+++ b/src/daemon/cmdline.c
@@ -186,7 +186,7 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d
break;
case 'C':
- pa_strbuf_puts(buf, "load-module module-cli\n");
+ pa_strbuf_puts(buf, "load-module module-cli exit_on_eof=1\n");
break;
case ARG_DAEMONIZE:
diff --git a/src/modules/module-cli.c b/src/modules/module-cli.c
index 41e33c7f..ce50a46b 100644
--- a/src/modules/module-cli.c
+++ b/src/modules/module-cli.c
@@ -32,38 +32,64 @@
#include <polypcore/cli.h>
#include <polypcore/sioman.h>
#include <polypcore/log.h>
+#include <polypcore/modargs.h>
#include "module-cli-symdef.h"
PA_MODULE_AUTHOR("Lennart Poettering")
PA_MODULE_DESCRIPTION("Command line interface")
PA_MODULE_VERSION(PACKAGE_VERSION)
-PA_MODULE_USAGE("No arguments")
+PA_MODULE_USAGE("exit_on_eof=<exit daemon after EOF?>")
-static void eof_cb(pa_cli*c, void *userdata) {
+static const char* const valid_modargs[] = {
+ "exit_on_eof",
+ NULL
+};
+
+static void eof_and_unload_cb(pa_cli*c, void *userdata) {
pa_module *m = userdata;
- assert(c && m);
+
+ assert(c);
+ assert(m);
pa_module_unload_request(m);
}
+static void eof_and_exit_cb(pa_cli*c, void *userdata) {
+ pa_module *m = userdata;
+
+ assert(c);
+ assert(m);
+
+ m->core->mainloop->quit(m->core->mainloop, 0);
+}
+
int pa__init(pa_core *c, pa_module*m) {
pa_iochannel *io;
- assert(c && m);
+ pa_modargs *ma;
+ int exit_on_eof = 0;
+
+ assert(c);
+ assert(m);
if (c->running_as_daemon) {
- pa_log_info(__FILE__": Running as daemon so won't load this module.");
+ pa_log_info(__FILE__": Running as daemon, refusing to load this module.");
return 0;
}
- if (m->argument) {
- pa_log(__FILE__": module doesn't accept arguments.");
- return -1;
+ if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
+ pa_log(__FILE__": failed to parse module arguments.");
+ goto fail;
}
+ if (pa_modargs_get_value_boolean(ma, "exit_on_eof", &exit_on_eof) < 0) {
+ pa_log(__FILE__": exit_on_eof= expects boolean argument.");
+ goto fail;
+ }
+
if (pa_stdio_acquire() < 0) {
pa_log(__FILE__": STDIN/STDUSE already in use.");
- return -1;
+ goto fail;
}
io = pa_iochannel_new(c->mainloop, STDIN_FILENO, STDOUT_FILENO);
@@ -73,13 +99,23 @@ int pa__init(pa_core *c, pa_module*m) {
m->userdata = pa_cli_new(c, io, m);
assert(m->userdata);
- pa_cli_set_eof_callback(m->userdata, eof_cb, m);
+ pa_cli_set_eof_callback(m->userdata, exit_on_eof ? eof_and_exit_cb : eof_and_unload_cb, m);
+
+ pa_modargs_free(ma);
return 0;
+
+fail:
+
+ if (ma)
+ pa_modargs_free(ma);
+
+ return -1;
}
void pa__done(pa_core *c, pa_module*m) {
- assert(c && m);
+ assert(c);
+ assert(m);
if (c->running_as_daemon == 0) {
pa_cli_free(m->userdata);