maelstrom-software / maelstrom

Maelstrom is a fast Rust, Go, and Python test runner that runs every test in its own container. Tests are either run locally or distributed to a clustered job runner.
https://maelstrom-software.com/
Apache License 2.0
466 stars 9 forks source link

Provide a way to not run a job as pid 1 in its pid namespace #52

Open nfachan opened 10 months ago

nfachan commented 10 months ago

This is pretty optional because a job could always include its own init, like https://github.com/krallin/tini

nfachan commented 2 months ago

Just a note. It turns out that the init process can only receive signals for which has explicitly registered handlers. This may be a problem with the allocate_tty option as it means that the process won't receive the sighup unless it registers for it.

Anyway, I imagine this feature would work something like this. We'd first clone the init process, which would just clone the child process and then immediately start waiting in a loop. The child process would do the setup as we do today, culminating in an exec. The init process, on the other hand, would have just do waits in a loop until the child process terminated, then it would complete.

There area few tricky bits about all of this. One is that the init process would need a stack of its own. We couldn't let it run completely asynchronous because we would have to leak the stacks used by these init processes (since all of the children share the same VM). The other is that we couldn't wait for the child ourselves: since it would be our grandchild. I think we could have the init process write out the status to some shared memory before exiting. We'd then wait for the init process.