Re: [PATCH] modprobe: add --resolve-alias option

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

 



On 8/26/09, Thomas Bächler <thomas@xxxxxxxxxxxxx> wrote:
> The --resolve-alias option prints all module names that match the
> alias given on the commandline and exits. If no valid alias is specified,
> it does nothing.

Why?

I.e. we already have "--verbose --dry-run" for humans, so I assume
this is for scripting purposes.  Which scripts would you like to use
this in?

>  doc/modprobe.sgml |    9 +++++++++
>  modprobe.c        |   35 ++++++++++++++++++++++-------------
>  2 files changed, 31 insertions(+), 13 deletions(-)
>
> diff --git a/doc/modprobe.sgml b/doc/modprobe.sgml
> index fde8ca7..4f8c5ab 100644
> --- a/doc/modprobe.sgml
> +++ b/doc/modprobe.sgml
> @@ -367,6 +367,15 @@
>          </listitem>
>        </varlistentry>
>        <varlistentry>
> +        <term><option>--resolve-alias</option>
> +        </term>
> +        <listitem>
> +          <para>
> +	    Resolve all module names matching an alias.

s/Resolve/Print/

> +	  </para>
> +        </listitem>
> +      </varlistentry>
> +      <varlistentry>
>          <term><option>-o</option> <option>--name</option>
>          </term>
>          <listitem>
> diff --git a/modprobe.c b/modprobe.c
> index 21a3111..6a0da22 100644
> --- a/modprobe.c
> +++ b/modprobe.c
> @@ -69,7 +69,8 @@ typedef enum
>  	mit_ignore_commands = 16,
>  	mit_ignore_loaded = 32,
>  	mit_strip_vermagic = 64,
> -	mit_strip_modversion = 128
> +	mit_strip_modversion = 128,
> +	mit_resolve_alias = 256
>
>  } modprobe_flags_t;
>
> @@ -1342,20 +1343,23 @@ int do_modprobe(char *modname,
>  		if (aliases->next)
>  			err = warn;
>  		while (aliases) {
> -			/* Add the options for this alias. */
> -			char *opts = NOFAIL(strdup(cmdline_opts));
> -			opts = add_extra_options(modname,
> -						 opts, modoptions);
> -
> -			read_depends(dirname, aliases->module, &list);
> -			failed |= handle_module(aliases->module,
> -				&list, newname, opts, modoptions,
> -				commands, cmdline_opts, err, flags);
> -
> +			if(flags & mit_resolve_alias) {
> +				info("%s\n", aliases->module);

I think printf() would be better.

> +			} else {
> +				/* Add the options for this alias. */
> +				char *opts = NOFAIL(strdup(cmdline_opts));
> +				opts = add_extra_options(modname,
> +							 opts, modoptions);
> +
> +				read_depends(dirname, aliases->module, &list);
> +				failed |= handle_module(aliases->module,
> +					&list, newname, opts, modoptions,
> +					commands, cmdline_opts, err, flags);
> +				INIT_LIST_HEAD(&list);
> +			}
>  			aliases = aliases->next;
> -			INIT_LIST_HEAD(&list);
>  		}
> -	} else {
> +	} else if(!(flags & mit_resolve_alias)) {
>  		if (flags & mit_use_blacklist
>  		    && find_blacklist(modname, blacklist))
>  			return failed;

Yay, more special cases and higher nesting levels :-).

How about this instead?

 	aliases = apply_blacklist(aliases, blacklist);
+	if(flags & mit_resolve_alias) {
+		while(aliases) {
+			printf("%s\n", aliases->module);
+			aliases = aliases->next;
+		}
+		return 0;
+	}

It could be even shorter if you don't mind switching the while() loops
to for() loops as well.

> @@ -1373,6 +1377,7 @@ static struct option options[] = { { "version", 0,
> NULL, 'V' },
>  				   { "show", 0, NULL, 'n' },
>  				   { "dry-run", 0, NULL, 'n' },
>  				   { "show-depends", 0, NULL, 'D' },
> +				   { "resolve-alias", 0, NULL, 'R' },
>  				   { "dirname", 1, NULL, 'd' },
>  				   { "set-version", 1, NULL, 'S' },
>  				   { "config", 1, NULL, 'C' },
> @@ -1453,6 +1458,10 @@ int main(int argc, char *argv[])
>  			flags |= mit_ignore_loaded;
>  			verbose = 1;
>  			break;
> +		case 'R':
> +			flags |= mit_resolve_alias;
> +			verbose = 1;
> +			break;
>  		case 'o':
>  			newname = optarg;
>  			break;

Regards
Alan
--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux