[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: potential exec/nohup/timeout improvement for Linux: prctl(PR_SET_PDE
From: |
Richard W.M. Jones |
Subject: |
Re: potential exec/nohup/timeout improvement for Linux: prctl(PR_SET_PDEATHSIG) |
Date: |
Thu, 31 Aug 2017 14:52:58 +0100 |
User-agent: |
Mutt/1.5.20 (2009-12-10) |
On Thu, Aug 31, 2017 at 07:59:41AM -0500, Eric Blake wrote:
> Rich Jones just taught me about Linux' prctl(PR_SET_PDEATHSIG), which
> allows you to run a helper executable that will automatically be killed
> if its parent process dies. I'm trying to figure out if coreutils
> should provide support for that API via any of its existing wrapper
> utilities (in fact, it sounds somewhat like the opposite of nohup -
> instead of spawning a child process that survives the shell's death, we
> want to be able to spawn a child process that automatically cleans
> itself up on the shell's death). Or maybe we make a new wrapper
> utility. However, since the functionality is currently Linux-only, I'm
> also wondering if coreutils is still a good choice for this
> functionality, or if we should pursue exposing it in some other package
> of useful shell utilities.
My idea (I'll leave it to someone else to implement) would be some
kind of cleanup wrapper for shell scripts, like:
autocleanup [-s TERM] someprog &
If the main script exits, someprog gets killed automatically. No need
for traps etc.
Note that ‘PR_SET_PDEATHSIG’ is passed through exec to non-setuid
processes so this is fairly simple to implement. For setuid it would
fail silently, and testing for setuid might be problematic or racy I
suppose.
Of course this is all Linux-only. Do other kernels implement anything
like this? We could use it for nbdkit:
https://github.com/libguestfs/nbdkit/commit/370b554fb38be7360815af70d5e0175842c451c6
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/