[pulseaudio-discuss] [PATCH] pacmd: Added unloading modules by name.
poljar
poljarinho at gmail.com
Thu May 17 05:56:00 PDT 2012
pacmd should allow unloading modules by name.
The command_unload() function was expanded to handle names while
unloading modules, if there are multiple modules with the same name all
of them are unloaded.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=48289
---
src/pulsecore/cli-command.c | 29 ++++++++++++++++++++++-------
src/utils/pacmd.c | 2 +-
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c
index 53042c1..4210f06 100644
--- a/src/pulsecore/cli-command.c
+++ b/src/pulsecore/cli-command.c
@@ -33,6 +33,7 @@
#include <sys/stat.h>
#include <dirent.h>
#include <time.h>
+#include <ctype.h>
#include <pulse/xmalloc.h>
#include <pulse/error.h>
@@ -150,7 +151,7 @@ static const struct command commands[] = {
{ "ls", pa_cli_command_info, NULL, 1 },
{ "list", pa_cli_command_info, NULL, 1 },
{ "load-module", pa_cli_command_load, "Load a module (args: name, arguments)", 3},
- { "unload-module", pa_cli_command_unload, "Unload a module (args: index)", 2},
+ { "unload-module", pa_cli_command_unload, "Unload a module (args: name|index)", 2},
{ "describe-module", pa_cli_command_describe, "Describe a module (arg: name)", 2},
{ "set-sink-volume", pa_cli_command_sink_volume, "Set the volume of a sink (args: index|name, volume)", 3},
{ "set-source-volume", pa_cli_command_source_volume, "Set the volume of a source (args: index|name, volume)", 3},
@@ -445,6 +446,7 @@ static int pa_cli_command_unload(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa
uint32_t idx;
const char *i;
char *e;
+ pa_bool_t unloaded = FALSE;
pa_core_assert_ref(c);
pa_assert(t);
@@ -456,13 +458,26 @@ static int pa_cli_command_unload(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa
return -1;
}
- idx = (uint32_t) strtoul(i, &e, 10);
- if (*e || !(m = pa_idxset_get_by_index(c->modules, idx))) {
- pa_strbuf_puts(buf, "Invalid module index.\n");
- return -1;
- }
+ if (isdigit(i[0])) {
+ idx = (uint32_t) strtoul(i, &e, 10);
+ if (*e || !(m = pa_idxset_get_by_index(c->modules, idx))) {
+ pa_strbuf_puts(buf, "Invalid module index.\n");
+ return -1;
+ }
- pa_module_unload_request(m, FALSE);
+ pa_module_unload_request(m, FALSE);
+ }
+ else {
+ for (m = pa_idxset_first(c->modules, &idx); m; m = pa_idxset_next(c->modules, &idx))
+ if (strcmp(i, m->name) == 0) {
+ unloaded = TRUE;
+ pa_module_unload_request(m, FALSE);
+ }
+ if(unloaded == FALSE) {
+ pa_strbuf_printf(buf, "Module %s not loaded.\n", i);
+ return -1;
+ }
+ }
return 0;
}
diff --git a/src/utils/pacmd.c b/src/utils/pacmd.c
index 7e1f33b..c7c693b 100644
--- a/src/utils/pacmd.c
+++ b/src/utils/pacmd.c
@@ -51,7 +51,7 @@ static void help(const char *argv0) {
printf("%s %s\n", argv0, "stat");
printf("%s %s\n", argv0, "info");
printf("%s %s %s\n", argv0, "load-module", _("NAME [ARGS ...]"));
- printf("%s %s %s\n", argv0, "unload-module", _("#N"));
+ printf("%s %s %s\n", argv0, "unload-module", _("NAME|#N"));
printf("%s %s %s\n", argv0, "describe-module", _("NAME"));
printf("%s %s %s\n", argv0, "set-(sink|source)-volume", _("NAME|#N VOLUME"));
printf("%s %s %s\n", argv0, "set-(sink-input|source-output)-volume", _("#N VOLUME"));
--
1.7.10.2
More information about the pulseaudio-discuss
mailing list