Vladimir Kotal
2011-Sep-01 13:00 UTC
[dtrace-discuss] quotes in command arguments (pid provider)
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-Sep-01 13:19 UTC
[dtrace-discuss] quotes in command arguments (pid provider)
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 On Sep 1, 2011, at 9:00 AM, Vladimir Kotal wrote:> > 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. > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org
Adam Leventhal
2011-Sep-01 16:13 UTC
[dtrace-discuss] quotes in command arguments (pid provider)
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 <vladimir.kotal at oracle.com> wrote:> > 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. > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org >-- Adam Leventhal, Delphix http://dtrace.org/blogs/ahl 275 Middlefield Road, Suite 50 Menlo Park, CA 94025 http://www.delphix.com
Vladimir Kotal
2011-Sep-02 08:51 UTC
[dtrace-discuss] quotes in command arguments (pid provider)
On 09/01/11 18:13, Adam Leventhal wrote:> 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#274Oh, it''s using strtok() with "\f\n\r\t\v " as separators.> 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/1440I filed similar bug in Bugster :)> 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.