Subject: [bug#30637] [WIP] shepherd: Poll every 0.5s to find dead forked services

From: [email-masked] (Ludovic Courtès)
Date: Fri, 02 Mar 2018 13:42:41 +0100

Hello!

Carlo Zancanaro <[email-masked]> skribis:

> On Fri, Mar 02 2018, Ludovic Courtès wrote:

[...]

>> So what about this plan:
>>
>>   1. Add FFI bindings in (shepherd system) for prctl(2). We   should
>> arrange for it to throw to 'system-error when the   ‘prctl’ symbol
>> is missing, as is the case on GNU/Hurd.
>
> Are we okay with having this just not work on GNU/Hurd (or kernels
> older than 3.4, according to the prctl manpage)? We could fall back to
> a polling approach if prctl isn't available? I don't really like the
> idea of this working on some kernels but not others, given that
> process supervision is one of the main jobs of shepherd.

Yeah, I agree.

The ‘prctl’ procedure itself should simply throw to 'system-error on
GNU/Hurd.  But then, in (shepherd), we could add the polling thing when
(not (string-contains %host-type "linux")).

WDYT?

>>   2. Use prctl/PR_SET_CHILD_SUBREAPER in ‘exec-command’. Here we
>> must ‘catch-system-error’ around that call to cater to   GNU/Hurd.

Actually this should be done in ‘fork+exec-command’ in the child
process.

> Why would we need to set it in exec-command? It looks like it modifies
> the state of the calling process, which means we'd want to set it in
> the shepherd service, not in each of the child processes.

We want to set the “reaper” of child processes to Shepherd itself, so we
must do that in child processes.  The shepherd process cannot be its own
reaper I suppose.

BTW, we should do PR_SET_CHILD_SUBREAPER only when (not (= 1 (getpid))).

> I'll try to get this working in the next few days. Hopefully you'll
> see a patch from me soon.

Awesome, thank you!

Ludo’.