From: stephen@brennan.io
To: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Cc: rostedt@goodmis.org, linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH] kernel-shark: Provide parsing for quotation marks in Record command line
Date: Tue, 27 Aug 2019 22:10:18 -0700 [thread overview]
Message-ID: <20190828051018.GA5316@greed> (raw)
In-Reply-To: <20190827131418.18713-1-y.karadz@gmail.com>
Hi Yordan!
Thanks for the quick work on this issue :)
On Tue, Aug 27 16:14, Yordan Karadzhov (VMware) wrote:
> Shell-like parsing of quotation marks in the content of the "Command"
> field of the "Record" dialog will give more options to the users.
> For example, now we can trace
>
> python -c 'print("hello world")'
>
> Suggested-by: Stephen Brennan <stephen@brennan.io>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204679
> Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
> ---
> kernel-shark/src/KsCaptureDialog.cpp | 38 ++++++++++++++++++++++++++--
> 1 file changed, 36 insertions(+), 2 deletions(-)
>
> diff --git a/kernel-shark/src/KsCaptureDialog.cpp b/kernel-shark/src/KsCaptureDialog.cpp
> index dc1e9b2..b3393b6 100644
> --- a/kernel-shark/src/KsCaptureDialog.cpp
> +++ b/kernel-shark/src/KsCaptureDialog.cpp
> @@ -157,7 +157,9 @@ KsCaptureControl::KsCaptureControl(QWidget *parent)
> */
> QStringList KsCaptureControl::getArgs()
> {
> + QString::SplitBehavior opt = QString::SkipEmptyParts;
> QStringList argv;
> + QString cmdTmp;
>
> argv << "record";
>
> @@ -170,7 +172,36 @@ QStringList KsCaptureControl::getArgs()
> argv << _eventsWidget.getCheckedEvents(true);
>
> argv << "-o" << outputFileName();
> - argv << _commandLineEdit.text().split(" ");
> +
> + cmdTmp = _commandLineEdit.text();
> + if (!cmdTmp.contains('\'') && !cmdTmp.contains('\"')) {
> + /* Split all command line arguments. */
> + argv << cmdTmp.split(" ", opt);
> + } else {
> + int iOpenQuots, iCloseQuots, size = cmdTmp.size();
> + int iSingleQuots = (cmdTmp.count('\'') == 2) ? cmdTmp.indexOf('\'') : size;
> + int iDoubleQuots = (cmdTmp.count('\"') == 2) ? cmdTmp.indexOf('\"') : size;
> +
> + if (iSingleQuots < iDoubleQuots) {
> + iOpenQuots = iSingleQuots;
> + iCloseQuots = cmdTmp.lastIndexOf('\'') + 1;
> + } else if (iDoubleQuots < iSingleQuots) {
> + iOpenQuots = iDoubleQuots;
> + iCloseQuots = cmdTmp.lastIndexOf('\"') + 1;
> + } else {
> + emit print("\nERROR: Unable to parse the command.");
> + return {};
> + }
> +
> + /* Split the arguments. */
> + argv << cmdTmp.left(iOpenQuots).split(" ", opt);
> +
> + /* Everything in between the quotation marks goes in one piece. */
> + argv << cmdTmp.mid(iOpenQuots, iCloseQuots - iOpenQuots);
> +
> + /* Split the rest of the arguments. */
> + argv << cmdTmp.right(size - iCloseQuots).split(" ", opt);
> + }
It strikes me that this explicitly supports only a single set of quotes.
This sort of behavior would be pretty surprising for people expecting shell
quote support, and for people expecting just splitting on spaces.
I looked and couldn't really find any Qt utility for properly parsing shell
quoting (similar to python's shlex module). I totally get that it's a lot
of work to implement a correct shell quoting parser.
Maybe a compromise would be to add a checkbox to the capture dialog, which
tells kernel-shark to pass the entire textbox contents, unmodified, to the
shell implementation on the system. So, my example of:
python -c 'print("hello world")'
Would get put into the third argument of the command:
/bin/sh -c INSERT_TEXTBOX_CONTENTS_HERE
Then you could rely on /bin/sh doing the parsing for you. The downside is
that it adds a whole new process. But you can't always get everything in
life, right?
Hope this was helpful!
Stephen
next prev parent reply other threads:[~2019-08-28 5:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-27 13:14 [PATCH] kernel-shark: Provide parsing for quotation marks in Record command line Yordan Karadzhov (VMware)
2019-08-28 5:10 ` stephen [this message]
2019-08-28 13:06 ` Steven Rostedt
2019-08-28 14:10 ` Yordan Karadzhov (VMware)
2019-08-28 14:56 ` Steven Rostedt
2019-08-28 13:25 ` Steven Rostedt
2019-08-28 13:30 ` Steven Rostedt
2019-09-17 10:44 ` Yordan Karadzhov (VMware)
2019-09-17 13:17 ` Steven Rostedt
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=20190828051018.GA5316@greed \
--to=stephen@brennan.io \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=y.karadz@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.