Re: [PATCH] prctl: add PR_{SET,GET}_CHILD_SUBREAPER to allow simple process supervision

From: Valdis . Kletnieks
Date: Sat Jan 07 2012 - 11:14:19 EST


On Sat, 07 Jan 2012 16:56:37 +0100, Kay Sievers said:
> Resending this, it got lost last year's September.
>
> We still need it to properly implement init-like service managers.

> From: Lennart Poettering <lennart@xxxxxxxxxxxxxx>
> Subject: prctl: add PR_{SET,GET}_CHILD_SUBREAPER to allow simple process supervision

> Users of this will be the systemd per-user instance, which provides
> init-like functionality for the user's login session and D-Bus, which
> activates bus services on-demand. Both need init-like capabilities
> to be able to properly keep track of the services they start.

> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -552,6 +552,18 @@ struct signal_struct {
> int group_stop_count;
> unsigned int flags; /* see SIGNAL_* flags below */
>
> + /*
> + * PR_SET_CHILD_SUBREAPER marks a process, like a service
> + * manager, to re-parent orphan (double-forking) child processes
> + * to this process instead of 'init'. The service manager is
> + * able to receive SIGCHLD signals and is able to investigate
> + * the process until it calls wait(). All children of this
> + * process will inherit a flag if they should look for a
> + * child_subreaper process at exit.
> + */
> + unsigned int is_child_subreaper:1;
> + unsigned int has_child_subreaper:1;

Is there someplace we can stick these two fields where they won't expand the
signal_struct? Can we stick them in signal_struct->flags instead? Looks like we've
only burned 3 bits of that unsigned int. Yes, I know that would complicate the
prctl get/set code.

> + /* find the first ancestor marked as child_subreaper */
> + for (reaper = father->real_parent;
> + reaper != &init_task;
> + reaper = reaper->real_parent) {

I admit being insufficiently caffienated - does this DTRT in a PID namespace? That
&init_task looks fishy to me...

Attachment: pgp00000.pgp
Description: PGP signature