mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-02-04 06:00:28 +01:00
dbus-daemon: Avoid known options being interpreted as optional arguments
The man page and --help imply that
dbus-daemon --print-address --print-pid
is a valid/useful thing to do, but because --print-address takes an
optional argument, it is ambiguous whether --print-pid is meant to
be the argument for --print-address (same as --print-address=--print-pid)
or a new option (same as --print-address=1 --print-pid). In fact,
before this commit, the dbus-daemon would interpret --print-pid as
the optional argument to --print-address, and then fail to parse it
because it isn't an integer.
Because none of our options are syntactically valid as arguments for
any option that takes an optional argument, we can avoid the ambiguity
by delaying parsing of optional arguments until all known options
have been tried.
Resolves: dbus/dbus#467
Signed-off-by: Xin Shi <shixin21@huawei.com>
This commit is contained in:
parent
7ab384de57
commit
86a89967f2
1 changed files with 20 additions and 20 deletions
40
bus/main.c
40
bus/main.c
|
|
@ -584,16 +584,6 @@ main (int argc, char **argv)
|
|||
if (!_dbus_string_append (&addr_fd, desc))
|
||||
exit (1);
|
||||
|
||||
print_address = TRUE;
|
||||
}
|
||||
else if (prev_arg &&
|
||||
strcmp (prev_arg, "--print-address") == 0)
|
||||
{
|
||||
check_two_addr_descriptors (&addr_fd, "print-address");
|
||||
|
||||
if (!_dbus_string_append (&addr_fd, arg))
|
||||
exit (1);
|
||||
|
||||
print_address = TRUE;
|
||||
}
|
||||
else if (strcmp (arg, "--print-address") == 0)
|
||||
|
|
@ -612,16 +602,6 @@ main (int argc, char **argv)
|
|||
if (!_dbus_string_append (&pid_fd, desc))
|
||||
exit (1);
|
||||
|
||||
print_pid = TRUE;
|
||||
}
|
||||
else if (prev_arg &&
|
||||
strcmp (prev_arg, "--print-pid") == 0)
|
||||
{
|
||||
check_two_pid_descriptors (&pid_fd, "print-pid");
|
||||
|
||||
if (!_dbus_string_append (&pid_fd, arg))
|
||||
exit (1);
|
||||
|
||||
print_pid = TRUE;
|
||||
}
|
||||
else if (strcmp (arg, "--print-pid") == 0)
|
||||
|
|
@ -642,6 +622,26 @@ main (int argc, char **argv)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
else if (prev_arg &&
|
||||
strcmp (prev_arg, "--print-address") == 0)
|
||||
{
|
||||
check_two_addr_descriptors (&addr_fd, "print-address");
|
||||
|
||||
if (!_dbus_string_append (&addr_fd, arg))
|
||||
exit (1);
|
||||
|
||||
print_address = TRUE;
|
||||
}
|
||||
else if (prev_arg &&
|
||||
strcmp (prev_arg, "--print-pid") == 0)
|
||||
{
|
||||
check_two_pid_descriptors (&pid_fd, "print-pid");
|
||||
|
||||
if (!_dbus_string_append (&pid_fd, arg))
|
||||
exit (1);
|
||||
|
||||
print_pid = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
usage ();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue