public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Juerg Haefliger <juerg.haefliger@canonical.com>
To: linux-bluetooth@vger.kernel.org
Subject: bluez: btmgmt --index broken
Date: Thu, 26 Oct 2023 18:24:26 +0200	[thread overview]
Message-ID: <20231026182426.032a776d@gollum> (raw)

[-- Attachment #1: Type: text/plain, Size: 2255 bytes --]

Hi,

Commit 648b4362521b ("shared/shell: Add support for -i/--init-script")
introduced a short option namespace collision with btmgmt's --index option,
both of which use '-i'.

As a result, a provided --index is treated as an init-script...

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


On a separate note, should btmgmt actually support --init-script since it
doesn't seem to do anything and just enters interactive mode?

$ cat test
help
info
quit

$ btmgmt --init-script test
[mgmt]#


Simple fix for the first issue, use -s/--init-script instead:

diff --git a/src/shared/shell.c b/src/shared/shell.c
index db79c882c..fbccff5b5 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -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' },
@@ -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)
@@ -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)

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

             reply	other threads:[~2023-10-26 16:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-26 16:24 Juerg Haefliger [this message]
2023-10-26 16:37 ` bluez: btmgmt --index broken bluez.test.bot
2023-10-27  5:54 ` [BlueZ PATCH] shared/shell: Fix --init-script commandline option Juerg Haefliger
2023-10-27  7:29   ` [BlueZ] " bluez.test.bot
2023-10-30  6:53   ` [PATCH v2] " Juerg Haefliger
2023-10-30  8:18     ` [v2] " bluez.test.bot
2023-11-06 16:26     ` [PATCH v2] " Luiz Augusto von Dentz
2023-11-07  8:37       ` Juerg Haefliger
2023-11-13 19:22     ` patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231026182426.032a776d@gollum \
    --to=juerg.haefliger@canonical.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox