Re: [PATCH] allow execve'ing "/proc/self/exe" even if /proc is not mounted

From: Eric W. Biederman
Date: Thu Jun 25 2009 - 14:02:36 EST


Denys Vlasenko <vda.linux@xxxxxxxxxxxxxx> writes:

> In some circumstances running process needs to re-execute
> its image.
>
> Among other useful cases, it is _crucial_ for NOMMU arches.
>
> They need it to perform daemonization. Classic sequence
> of "fork, parent dies, child continues" can't be used
> due to lack of fork on NOMMU, and instead we have to do
> "vfork, child re-exec itself (with a flag to not daemonize)
> and therefore unblocks parent, parent dies".

Why?

I would expect a simple assembly wrapper around clone would work.
I.e. Create a new process but share the MM and reuse the same
stack. When clone returns if we are the parent exit, otherwise
continue on with life.

> Another crucial use case on NOMMU is POSIX shell support.
> Imagine a shell command of the form "func1 | func2 | func3".
> This can be implemented on NOMMU by vforking thrice,
> re-executing the shell in every child in the form
> "<shell> -c 'body of funcN'", and letting parent wait and collect
> exitcodes and such. As far as I can see, it's the only way
> to implement it correctly on NOMMU.
>
> The program may re-execute itself by name if it knows the name,
> but we generally may be unsure about it. Binary may be renamed,
> or even deleted while it is being run.

It really sounds like you want to implement fork for NOMMU.
If you have a base address register which everything is relative
to I can't imagine it would be too hard. Heck you might even be
able to do it in user space.

Eric

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/