linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] udevadm: fix option parsing breakage with klibc
@ 2008-11-14 21:34 Sergey Vlasov
  2008-11-15  1:03 ` Kay Sievers
  0 siblings, 1 reply; 2+ messages in thread
From: Sergey Vlasov @ 2008-11-14 21:34 UTC (permalink / raw)
  To: linux-hotplug

The klibc implementation of getopt_long() behaves slightly different
from the glibc one - in particular, it treats the change of the option
string argument between invocations as start of parsing a different
command line, and resets its state.  However, the udevadm code
expected getopt_long() invocations in subcommands to continue parsing
the rest of command line after initial options has been parsed at the
top level; with klibc this broke, causing all udevadm subcommands to
stop recognizing their options.

Instead of relying on the glibc behavior, reset the getopt_long()
state properly before invoking the subcommand handler: move argv to
point to the subcommand name, decrease argc appropriately, and set
optind = 0.  This also fixes a minor bug visible with glibc - without
setting optind = 0 all getopt_long() calls in subcommand handlers were
behaving as if "+" was specified as the first character of the option
string (which disables option reordering), because that state was set
by the first getopt_long() call at the top level, and was not reset
when parsing subcommand options.

Signed-off-by: Sergey Vlasov <vsu@altlinux.ru>
---
 udev/udevadm.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/udev/udevadm.c b/udev/udevadm.c
index 3671b9e..e7b0736 100644
--- a/udev/udevadm.c
+++ b/udev/udevadm.c
@@ -201,7 +201,9 @@ int main(int argc, char *argv[])
 	if (command != NULL)
 		for (i = 0; cmds[i].cmd != NULL; i++) {
 			if (strcmp(cmds[i].name, command) = 0) {
-				optind++;
+				argc -= optind;
+				argv += optind;
+				optind = 0;
 				rc = run_command(udev, &cmds[i], argc, argv);
 				goto out;
 			}
-- 
1.6.0.2.321.g8406


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] udevadm: fix option parsing breakage with klibc
  2008-11-14 21:34 [PATCH] udevadm: fix option parsing breakage with klibc Sergey Vlasov
@ 2008-11-15  1:03 ` Kay Sievers
  0 siblings, 0 replies; 2+ messages in thread
From: Kay Sievers @ 2008-11-15  1:03 UTC (permalink / raw)
  To: linux-hotplug

On Fri, Nov 14, 2008 at 22:34, Sergey Vlasov <vsu@altlinux.ru> wrote:
> The klibc implementation of getopt_long() behaves slightly different
> from the glibc one - in particular, it treats the change of the option
> string argument between invocations as start of parsing a different
> command line, and resets its state.  However, the udevadm code
> expected getopt_long() invocations in subcommands to continue parsing
> the rest of command line after initial options has been parsed at the
> top level; with klibc this broke, causing all udevadm subcommands to
> stop recognizing their options.
>
> Instead of relying on the glibc behavior, reset the getopt_long()
> state properly before invoking the subcommand handler: move argv to
> point to the subcommand name, decrease argc appropriately, and set
> optind = 0.  This also fixes a minor bug visible with glibc - without
> setting optind = 0 all getopt_long() calls in subcommand handlers were
> behaving as if "+" was specified as the first character of the option
> string (which disables option reordering), because that state was set
> by the first getopt_long() call at the top level, and was not reset
> when parsing subcommand options.
>
> Signed-off-by: Sergey Vlasov <vsu@altlinux.ru>
> ---
>  udev/udevadm.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)

Applied.

Thanks,
Kay

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-11-15  1:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-14 21:34 [PATCH] udevadm: fix option parsing breakage with klibc Sergey Vlasov
2008-11-15  1:03 ` Kay Sievers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).