Hi, Is there a way to print out full path name of execname when the following probe is touched? proc:genunix:exec_common:exec-success Thanks. ************************************************ * C P Lin, Common Technology Project Lead. * * Sun Microsystems Inc. * * E-Mail: c.lin at sun.com * * Address: 4150 Network Circle, M/S UMPK12-210 * * Santa Clara, CA 95054 * * Phone: 650/352-4967 Fax: 650/786-7816 * ************************************************
Jonathan Adams
2005-Sep-14 22:16 UTC
[dtrace-discuss] How to get full path name of execname?
On 9/14/05, C Lin <c.lin at sun.com> wrote:> Hi, > > Is there a way to print out full path name of execname when the following > probe is touched? > > proc:genunix:exec_common:exec-successIt''s passed as args[0] to proc:::exec; something like: proc:::exec { self->path = args[0]; } proc:::exec-success /self->path/ { printf("execed %s\n", self->path); self->path = 0; } proc:::exec-failure { self->path = 0; } should do the trick. Cheers,
On 9/14/05, Jonathan Adams <jwadams at gmail.com> wrote:> > On 9/14/05, C Lin <c.lin at sun.com> wrote: > > Hi, > > > > Is there a way to print out full path name of execname when the > following > > probe is touched? > > > > proc:genunix:exec_common:exec-success > > It''s passed as args[0] to proc:::exec; something like: > > printf("execed %s\n", self->path);Having the _full_ pathname in _one_ string seems to be tricky, although you can of course print out both ''cwd'' and ''self->path'' separately. For example, / # cd /bin /bin # ./ls ... in this case, ''cwd'' is "/usr/bin/" , self-path is "ls" /bin # ls ... in this case, self->path is "/usr/xpg6/bin/ls" ( because I have xpg6 in front of /usr/bin in PATH ). You can''t simply add them into one string, because in the second case, "/usr/bin//usr/xpg6/bin/ls" would not be a valid path ... Tao -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20050914/9f2af0a4/attachment.html>
Jonathan Adams
2005-Sep-14 23:45 UTC
[dtrace-discuss] How to get full path name of execname?
On Wed, Sep 14, 2005 at 06:02:58PM -0500, Tao Chen wrote:> On 9/14/05, Jonathan Adams <jwadams at gmail.com> wrote: > > > > On 9/14/05, C Lin <c.lin at sun.com> wrote: > > > Hi, > > > > > > Is there a way to print out full path name of execname when the > > following > > > probe is touched? > > > > > > proc:genunix:exec_common:exec-success > > > > It''s passed as args[0] to proc:::exec; something like: > > > > printf("execed %s\n", self->path); > > > Having the _full_ pathname in _one_ string seems to be tricky, although you > can of course > print out both ''cwd'' and ''self->path'' separately. > > For example, > > / # cd /bin > /bin # ./ls > ... > in this case, ''cwd'' is "/usr/bin/" , self-path is "ls" > > /bin # ls > ... > in this case, self->path is "/usr/xpg6/bin/ls" ( because I have xpg6 in > front of /usr/bin in PATH ). > > You can''t simply add them into one string, because in the second case, > "/usr/bin//usr/xpg6/bin/ls" would not be a valid path ...Ah, that''s a wrinkle I''d missed. You could do something like: self->path = (((char *)arg0)[0] == ''/'') ? args[0] : strjoin(cwd, strjoin("/", self->name)); Or, on a recent OpenSolaris build (or when the new S10 dtrace patch is available): self->path = (index(arg0, "/") == 0) ? args[0] : strjoin(cwd, strjoin("/", self->name)); Cheers, - jonathan -- Jonathan Adams, Solaris Kernel Development
On 9/14/05, Jonathan Adams <jonathan.adams at sun.com> wrote:> > > self->path = (((char *)arg0)[0] == ''/'') ? args[0] : > strjoin(cwd, strjoin("/", self->name)); > > Or, on a recent OpenSolaris build (or when the new S10 dtrace patch is > available): > > self->path = (index(arg0, "/") == 0) ? args[0] : > strjoin(cwd, strjoin("/", self->name)); > >I didn''t get "(((char *)arg0)[0] == ''/'')" right when I first tried. "args[0][0]" or "(args[0])[0]" gives error: ... args has not yet been declared or assigned Also about arg0 v.s. args[0] : 1. arg0 in index() should be args[0] or (char *)arg0 instead. 2. if you assign args[0] to self->path, you cannot use self->path as a predicate since it''s not a scalar value. (Just for the sake of thread completeness.) Thanks, Tao -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20050915/49befe2e/attachment.html>