Skip to content

Commit

Permalink
shared/shell: Fix --init-script commandline option
Browse files Browse the repository at this point in the history
The newly added option -i/--init-script introduced a short option
namespace collision with btmgmt's --index, both of which use '-i'.

As a result, a provided --index is treated as a file name:

$ sudo btmgmt --index 0 info
Unable to open 0: No such file or directory (2)

Fix this by using '-s' for --init-script.

Fixes: bluez/bluez#639
Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
  • Loading branch information
juergh authored and tedd-an committed Oct 30, 2023
1 parent bfa4df0 commit b028c30
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/shared/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ static void rl_init(void)
static const struct option main_options[] = {
{ "version", no_argument, 0, 'v' },
{ "help", no_argument, 0, 'h' },
{ "init-script", required_argument, 0, 'i' },
{ "init-script", required_argument, 0, 's' },
{ "timeout", required_argument, 0, 't' },
{ "monitor", no_argument, 0, 'm' },
{ "zsh-complete", no_argument, 0, 'z' },
Expand Down Expand Up @@ -1169,9 +1169,9 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
if (opt) {
memcpy(options + offset, opt->options,
sizeof(struct option) * opt->optno);
snprintf(optstr, sizeof(optstr), "+mhvi:t:%s", opt->optstr);
snprintf(optstr, sizeof(optstr), "+mhvs:t:%s", opt->optstr);
} else
snprintf(optstr, sizeof(optstr), "+mhvi:t:");
snprintf(optstr, sizeof(optstr), "+mhvs:t:");

data.name = strrchr(argv[0], '/');
if (!data.name)
Expand All @@ -1193,7 +1193,7 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
data.argv = &cmplt;
data.mode = 1;
goto done;
case 'i':
case 's':
if (optarg)
data.init_fd = open(optarg, O_RDONLY);
if (data.init_fd < 0)
Expand Down

0 comments on commit b028c30

Please sign in to comment.