On Mon, Dec 28, 2020 at 3:16 PM Greg Wooledge <wool...@eeg.ccf.org> wrote:

> The problem is that the parent bash (the script) doesn't know, and
> cannot know, that the command was stillborn.  Only the child bash
> process can know this, and by the time this information has become
> available, the parent bash process has already moved on.
>

In principle, if the parent and child were to cooperate, I think the status
of the final execve()
could be communicated to the parent like this: Set up a pipe between the
parent and the child,
with the write side set to close-on-exec, and have the parent block on the
read side. If the
execve() call fails, the child can send an error message via the pipe, and
if it succeeds, the
parent will see the pipe being closed without a message.

Polling the child after some fraction of a second might not be able to tell
a failed execve()
apart from the exec'ed process exiting after the exec.

Reply via email to