Discussion:
quotes in command arguments (pid provider)
(too old to reply)
Vladimir Kotal
2011-09-01 13:00:34 UTC
Permalink
Raw Message
Hi all,

Sorry for a beginner's question but I can't find the answer anywhere and
do not have time to investigate so I decided to exploit this forum. Is
there a way how to instrument a command which has arguments containing
whitespace with PID provider ?

I am doing something like this:

dtrace -Z -n 'pid$target::myfunc:return/arg1 == 1/ { ustack(); }' -c
"/usr/bin/mycmd -a \"foo bar\" -b another"

but everything I tried lead to usage printed by the command or dtrace(1)
for one reason or another.

Thanks for the answers,


v.
Angelo Rajadurai
2011-09-01 13:19:17 UTC
Permalink
Raw Message
I've not tested this but can you try adding an escape char ( \ ) before the $target as well. Shell can do bad things to it.

So something like…

dtrace -Z -n 'pid\$target::myfunc:return/arg1 == 1/ { ustack(); }' -c "/usr/bin/mycmd -a \"foo bar\" -b another"

-Angelo
Post by Vladimir Kotal
Hi all,
Sorry for a beginner's question but I can't find the answer anywhere and do not have time to investigate so I decided to exploit this forum. Is there a way how to instrument a command which has arguments containing whitespace with PID provider ?
dtrace -Z -n 'pid$target::myfunc:return/arg1 == 1/ { ustack(); }' -c "/usr/bin/mycmd -a \"foo bar\" -b another"
but everything I tried lead to usage printed by the command or dtrace(1) for one reason or another.
Thanks for the answers,
v.
_______________________________________________
dtrace-discuss mailing list
Adam Leventhal
2011-09-01 16:13:10 UTC
Permalink
Raw Message
Hey Vladimir,

This is a bug in the way that DTrace composes arguments to the command
it executes as a result of the -c option.

http://src.illumos.org/source/xref/illumos-gate/usr/src/cmd/dtrace/dtrace.c#274

You can see that make_argv() just tokenizes the string based on
whitespace -- it doesn't use the tokenizing logic that the shell would
use. dtrace(1M) should probably do something like libast`sfnew() of
the command string, followed by an libshell`sh_parse() and
libshell`sh_exec() -- i.e. we want dtrace -c to act like sh -c.

I've filed this bug to track the issue:

https://www.illumos.org/issues/1440

To work around this, you can probably create a shell script that
simply does an exec of the command you want to run with the arguments
you want.

Adam

On Thu, Sep 1, 2011 at 1:00 PM, Vladimir Kotal
Post by Vladimir Kotal
Hi all,
Sorry for a beginner's question but I can't find the answer anywhere and do
not have time to investigate so I decided to exploit this forum. Is there a
way how to instrument a command which has arguments containing whitespace
with PID provider ?
dtrace -Z -n 'pid$target::myfunc:return/arg1 == 1/ { ustack(); }' -c
"/usr/bin/mycmd -a \"foo bar\" -b another"
but everything I tried lead to usage printed by the command or dtrace(1) for
one reason or another.
Thanks for the answers,
v.
_______________________________________________
dtrace-discuss mailing list
--
Adam Leventhal, Delphix
http://dtrace.org/blogs/ahl

275 Middlefield Road, Suite 50
Menlo Park, CA 94025
http://www.delphix.com
Vladimir Kotal
2011-09-02 08:51:32 UTC
Permalink
Raw Message
Post by Adam Leventhal
Hey Vladimir,
This is a bug in the way that DTrace composes arguments to the command
it executes as a result of the -c option.
http://src.illumos.org/source/xref/illumos-gate/usr/src/cmd/dtrace/dtrace.c#274
Oh, it's using strtok() with "\f\n\r\t\v " as separators.
Post by Adam Leventhal
You can see that make_argv() just tokenizes the string based on
whitespace -- it doesn't use the tokenizing logic that the shell would
use. dtrace(1M) should probably do something like libast`sfnew() of
the command string, followed by an libshell`sh_parse() and
libshell`sh_exec() -- i.e. we want dtrace -c to act like sh -c.
https://www.illumos.org/issues/1440
I filed similar bug in Bugster :)
Post by Adam Leventhal
To work around this, you can probably create a shell script that
simply does an exec of the command you want to run with the arguments
you want.
Works fine, thanks.


v.

Loading...