um: Set parent-death signal for sub-processes
cover um: Set parent-death signal for sub-processes
The ubd io and write_sigio threads/processes may leak e.g. when the main process is killed by "kill -9". Fix it by setting the parent-death signal for them.
Tiwei Bie (4):
um: Add os_set_pdeathsig helper function
um: Set parent-death signal for ubd io thread/process
um: Set parent-death signal for write_sigio thread/process
um: Use os_set_pdeathsig helper in winch thread/process
arch/um/drivers/chan_user.c | 3 +-- arch/um/drivers/ubd_kern.c | 1 + arch/um/include/shared/os.h | 2 ++ arch/um/os-Linux/process.c | 6 ++++++ arch/um/os-Linux/sigio.c | 1 + 5 files changed, 11 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/4 um: Add os_set_pdeathsig helper function
This helper can be used to set the parent-death signal of the calling process to SIGKILL to ensure that the process will be killed if the UML kernel dies unexpectedly without proper cleanup. This helper will be used in the follow-up patches.
--- arch/um/include/shared/os.h | 2 ++ arch/um/os-Linux/process.c | 6 ++++++ 2 files changed, 8 insertions(+)
arch/um/include/shared/os.h +2 -0
@@ -216,6 +216,8 @@ extern int os_drop_memory(void *addr, int length);extern int can_drop_memory (void );extern int os_mincore (void *addr,unsigned long len); +void os_set_pdeathsig (void ); +/* execvp.c */ extern int execvp_noalloc (char *buf,const char *file,char *const argv[]);/* helper.c */
arch/um/os-Linux/process.c +6 -0
@@ -12,6 +12,7 @@#include <fcntl.h> #include <sys/mman.h> #include <sys/ptrace.h> +#include <sys/prctl.h> #include <sys/wait.h> #include <asm/unistd.h> #include <init.h>
@@ -203,3 +204,8 @@ void init_new_thread_signals(void)set_handler (SIGIO );signal (SIGWINCH ,SIG_IGN ); } + +void os_set_pdeathsig (void ) +{ +prctl (PR_SET_PDEATHSIG ,SIGKILL ); +}
Signature · 1 line
2.34.1
PATCH 2/4 um: Set parent-death signal for ubd io thread/process
In reply to Tiwei BieThe ubd io thread is not really a traditional thread. Set the parent-death signal for it to ensure that it will be killed if the UML kernel dies unexpectedly without proper cleanup.
--- arch/um/drivers/ubd_kern.c | 1 + 1 file changed, 1 insertion(+)
arch/um/drivers/ubd_kern.c +1 -0
@@ -1499,6 +1499,7 @@ int io_thread(void *arg) {int n, count, written, res; +os_set_pdeathsig ();os_fix_helper_signals ();while (1 ){
Signature · 1 line
2.34.1
PATCH 3/4 um: Set parent-death signal for write_sigio thread/process
In reply to Tiwei BieThe write_sigio thread is not really a traditional thread. Set the parent-death signal for it to ensure that it will be killed if the UML kernel dies unexpectedly without proper cleanup.
--- arch/um/os-Linux/sigio.c | 1 + 1 file changed, 1 insertion(+)
arch/um/os-Linux/sigio.c +1 -0
@@ -55,6 +55,7 @@ static int write_sigio_thread(void *unused)int i, n, respond_fd;char c; +os_set_pdeathsig ();os_fix_helper_signals (); fds = ¤t_poll;while (1 ) {
Signature · 1 line
2.34.1
PATCH 4/4 um: Use os_set_pdeathsig helper in winch thread/process
In reply to Tiwei BieSince we have a helper now, let's switch to using it. It will make the code slightly more consistent.
--- arch/um/drivers/chan_user.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/um/drivers/chan_user.c +1 -2
@@ -10,7 +10,6 @@#include <signal.h> #include <termios.h> #include <sys/ioctl.h> -#include <sys/prctl.h> #include "chan_user.h" #include <os.h> #include <um_malloc.h>
@@ -162,7 +161,7 @@ static __noreturn int winch_thread(void *arg)int count;char c =1 ; -prctl (PR_SET_PDEATHSIG ,SIGKILL ); +os_set_pdeathsig (); pty_fd = data->pty_fd; pipe_fd = data->pipe_fd;
Signature · 1 line
2.34.1
Johannes Berg
maintainerQuoted 4 lines · Tiwei Bie
The ubd io and
write_sigiothreads/processes may leak e.g. when the main process is killed by "kill -9". Fix it by setting the parent-death signal for them.
I always used killall, but yeah, good idea, thanks!
johannes