[PATCH 1/2] pactl: Add unloading modules by name.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2012-05-30 at 14:27 +0200, poljar wrote:
> pactl should allow unloading modules by name.
> 
> If there are multiple modules with the same name all
> of them will be unloaded.

Thanks, I'll fix the small issues pointed out below, and apply the
patch.

> BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=48289
> ---
>  man/pactl.1.xml.in |    4 ++--
>  src/utils/pactl.c  |   40 ++++++++++++++++++++++++++++++++++++----
>  2 files changed, 38 insertions(+), 6 deletions(-)
> 
> diff --git a/man/pactl.1.xml.in b/man/pactl.1.xml.in
> index 86e7609..693a5c5 100644
> --- a/man/pactl.1.xml.in
> +++ b/man/pactl.1.xml.in
> @@ -119,8 +119,8 @@ USA.
>      </option>
>  
>      <option>
> -      <p><opt>unload-module</opt> <arg>ID</arg></p>
> -      <optdesc><p>Unload the module instance identified by the specified numeric index.</p></optdesc>
> +      <p><opt>unload-module</opt> <arg>ID|NAME</arg></p>
> +      <optdesc><p>Unload the module instance identified by the specified numeric index or unload all modules by the sepcified name.</p></optdesc>

Typo: "sepcified" -> "specified".

> @@ -844,6 +845,31 @@ static void volume_relative_adjust(pa_cvolume *cv) {
>      }
>  }
>  
> +static void unload_module_by_name_callback(pa_context *c, const pa_module_info *i, int is_last, void *userdata) {
> +    static pa_bool_t unloaded = FALSE;
> +
> +    if (is_last < 0) {
> +        pa_log(_("Failed to get module information: %s"), pa_strerror(pa_context_errno(c)));
> +        quit(1);
> +        return;
> +    }
> +
> +    if (is_last) {
> +        if (unloaded == FALSE)
> +            pa_log(_("Failed to unload moduel: Module %s not loaded"), module_name);

Typo: "moduel" -> "module".

> @@ -1568,11 +1597,14 @@ int main(int argc, char *argv[]) {
>              action = UNLOAD_MODULE;
>  
>              if (argc != optind+2) {
> -                pa_log(_("You have to specify a module index"));
> +                pa_log(_("You have to specify a module index or name"));
>                  goto quit;
>              }
>  
> -            module_index = (uint32_t) atoi(argv[optind+1]);
> +            if (isdigit(argv[optind+1][0]))
> +                module_index = (uint32_t) atoi(argv[optind+1]);
> +            else
> +                module_name = argv[optind+1];

atoi() accepts "42foo" as a valid number. This would be shorter and not
accept invalid strings as numbers:

    if (pa_atou(argv[optind + 1], &module_index) < 0)
        module_name = argv[optind + 1];

-- 
Tanu



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux