Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register CP as a process subreaper #543

Open
mterron opened this issue Jan 18, 2018 · 7 comments
Open

Register CP as a process subreaper #543

mterron opened this issue Jan 18, 2018 · 7 comments

Comments

@mterron
Copy link
Contributor

mterron commented Jan 18, 2018

In systems that support it (Linux and BSD, not sure about Illumos) set Containerpilot as a subreaper. This will ensure that orphan processes get reparented to CP even if CP is not PID1.

I found this when running an interactive debugging session and finding that when sending a ^C to CP, after I got my terminal back there were still processes running that were started by processes started by CP.

On Linux the syscal to define a process as a "sub reaper" is prctl(PR_SET_CHILD_SUBREAPER) and was introduced with kernel 3.4.

PR_SET_CHILD_SUBREAPER (since Linux 3.4)
              If arg2 is nonzero, set the "child subreaper" attribute of the
              calling process; if arg2 is zero, unset the attribute.

              A subreaper fulfills the role of init(1) for its descendant
              processes.  When a process becomes orphaned (i.e., its
              immediate parent terminates) then that process will be
              reparented to the nearest still living ancestor subreaper.
              Subsequently, calls to getppid() in the orphaned process will
              now return the PID of the subreaper process, and when the
              orphan terminates, it is the subreaper process that will
              receive a SIGCHLD signal and will be able to wait(2) on the
              process to discover its termination status.

              The setting of this bit is not inherited by children created
              by fork(2) and clone(2).  The setting is preserved across
              execve(2).

              Establishing a subreaper process is useful in session
              management frameworks where a hierarchical group of processes
              is managed by a subreaper process that needs to be informed
              when one of the processes—for example, a double-forked daemon—
              terminates (perhaps so that it can restart that process).
              Some init(1) frameworks (e.g., systemd(1)) employ a subreaper
              process for similar reasons.

Original commit: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ebec18a6d3aa1e7d84aab16225e87fd25170ec2b

On FreeBSD the syscall is procctl(PROC_REAP_ACQUIRE) and was introduced with FreeBSD 10.2

PROC_REAP_ACQUIRE
    Acquires the reaper status for the current process. The status means that 
    children orphaned by the reaper’s descendants that were forked after the 
    acquisition of the status are reparented to the reaper. 
    After the system initialization,  init(8) is the default reaper.

Original commit: freebsd/freebsd-src@c014fd4#diff-48eaa394a5ef45d0b55c5c98793df21e

On Illumos I'm not sure, I'll dig into the source and come back if I find something.

@jwreagor
Copy link
Contributor

This is definitely interesting as anything we can do to enhance supervision ultimately makes ContainerPilot a more stable parent/init process. I'll have to find out what LX support there is under SmartOS as that is where most of our users are running containers.

Where did this come up? Any other examples or background would be greatly appreciated.

@mterron
Copy link
Contributor Author

mterron commented Feb 2, 2018

@cheapRoc I figured this one out myself, haven't seen it reported anywhere. What kind of background are you after?
I searched on the Illumos source for something similar but couldn't find anything.

@mterron
Copy link
Contributor Author

mterron commented Jun 25, 2018

@cheapRoc is there anywhere I can check which linux syscalls are emulated and which are not on an LX brand zone? Is there a roadmap to track this divergence?

@misterbisson
Copy link
Contributor

@mterron I have to admit that we've turned out attention to native Linux, rather than LX, but your question would be a great one for the SmartOS mailing list.

@mterron
Copy link
Contributor Author

mterron commented Jun 25, 2018

I'll ask over there. What does "we've turned out attention to native Linux" mean?

@misterbisson
Copy link
Contributor

Apologies for being vague. I should have said that we've turned out attention to running linux in VMs.

@mterron
Copy link
Contributor Author

mterron commented Jun 26, 2018

Kubernetes right? That is sad, hopefully there'll be a way to use zones directly from Kubernetes and bypass the whole VM affair.

Back to this Issue, do you know if there's any traction in making CP a SUBREAPER (in the context of Linux & maybe FreeBSD)?
I was looking into LX syscalls as from @cheapRoc comment it sounded like the blocker was the lack of support from LX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants