tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Introduction to posix_spawn/chdir



On Sun, Jun 27, 2021 at 1:15 PM Chris Hanson <cmhanson%eschatologist.net@localhost> wrote:
> What are the straightforward changes needed to implement this minor addition? That’s all I’m wondering.
>
> Let’s say I wanted to add something like xnu’s posix_spawn_file_attr_addinherit_np(). I’d hope that the plan for chdir would provide some guidance that would at least help > someone get started.
>

Well the implementation plan is simple-
file_actions is a struct, that is one of the arguments to posix_spawn().
One of the struct's members is a pointer to an array of structures.
Every index of this array can be thought of as a file-actions object,
which performs various actions on any file descriptor which is open in
the parent.

For now the only actions available were- open, dup2 and close.
They behave exactly how the corresponding system/library calls would
have behaved,
if called in a child process (before the implicit exec).
I added two more actions - chdir and fchdir.
this is visible in src/sys/sys/spawn.h
The corresponding userland functions are in -
src/lib/libc/gen/posix_spawn_fileactions.c

These objects are read by the kernel and the file actions are
performed inside the kernel space.
In the kern_exec.c file- inside handle_posix_spawn_file_actions() function
I have added two more cases to handle chdir and fchdir.
These cases make calls to chdir fchdir's kernel routines, to
accomplish the desired effect.

I have updated all the changes to my NetBSD source's mirror.
A simple git diff would give you all the specifics.

Piyush


Home | Main Index | Thread Index | Old Index