Page MenuHomeFreeBSD

exec: Provide execpath in imgp for the process_exec hook.
ClosedPublic

Authored by bdrewery on May 24 2016, 9:32 PM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 28 2024, 10:50 AM
Unknown Object (File)
Feb 28 2024, 9:02 AM
Unknown Object (File)
Jan 28 2024, 5:37 PM
Unknown Object (File)
Jan 28 2024, 5:37 PM
Unknown Object (File)
Jan 28 2024, 5:35 PM
Unknown Object (File)
Jan 28 2024, 5:35 PM
Unknown Object (File)
Jan 28 2024, 5:35 PM
Unknown Object (File)
Jan 28 2024, 5:16 PM
Subscribers

Details

Summary

This was previously set after the hook and only if auxargs were present.
Now always provide it if possible.

MFC after: 2 weeks
Sponsored by: EMC / Isilon Storage Division

Test Plan

Used it in filemon, rather than vn_fullpath(9), and confirmed that the value
was correct.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bdrewery retitled this revision from to exec: Provide execpath in imgp for the process_exec hook..
bdrewery updated this object.
bdrewery edited the test plan for this revision. (Show Details)
bdrewery added a reviewer: kib.

I just realized I didn't drop the vnode lock before calling vn_fullpath.

Unlock before calling vn_fullpath(9).

It is too early to calculate file path before interpreter is parsed.

In D6546#138831, @kib wrote:

It is too early to calculate file path before interpreter is parsed.

Can we compromise with this and recalculate after the interpreter is known, if one is used? At least for my use case I don't mind getting the script's path as execpath in the hook instead of the interpreter path.

In D6546#138831, @kib wrote:

It is too early to calculate file path before interpreter is parsed.

Can we compromise with this and recalculate after the interpreter is known, if one is used? At least for my use case I don't mind getting the script's path as execpath in the hook instead of the interpreter path.

I do not mind but I would prefer that

  1. it was not called execpath in imgp, but e.g. scriptpath, with execpath preserving the current semantic
  2. might be, only fill scriptpath if some global flag is set, indicating that there is consumer ? vn_fullpath is expensive
  3. for the same reason, reuse scriptpath to set execpath if executable is not interpreted

2 is optional.

I'm going to put this off for now and explore the namecache fix discussed a few weeks ago briefly on IRC.

For interpreted it will go back and go over the execpath code I have. Couldn't I just cleanup execpath before the goto interpret and the code I have mostly works? I assume the process_exec hook is not called until the actual interpreter is handled in the activator.

For interpreted it will go back and go over the execpath code I have. Couldn't I just cleanup execpath before the goto interpret and the code I have mostly works? I assume the process_exec hook is not called until the actual interpreter is handled in the activator.

Yeah, the process_exec hook is called from exec_new_vmspace, after interpreter is looped and set into imgp->vp. So I should just be able to recalculate the execpath in this case. I think a downside is that vn_fullpath may be called on the first pass and its result thrown away.

bdrewery edited edge metadata.
  • Free freepath for interpreter cleanup
  • Tested with running a script and filemon's use of imgp->execpath showed the interpreter fine here, and NOT the script name.
  • Grab and coffee and really use the right syntax
sys/kern/kern_exec.c
645 ↗(On Diff #16926)

I think you need imgp->execpath = NULL;

sys/kern/kern_exec.c
645 ↗(On Diff #16926)

Sure, that would be safest. I think it would always be overwritten above though. I'll add it though.

  • NULL imgp->execpath when handling interpreter
sys/kern/kern_exec.c
645 ↗(On Diff #16926)

At least, it would allow potential imgp consumers to not care about stage of the do_execve() where they act. Either pointer is null, or it points to current path.

kib edited edge metadata.
This revision is now accepted and ready to land.May 26 2016, 9:09 PM
This revision was automatically updated to reflect the committed changes.