提交 91d44ff8 编写于 作者: R Richard Weinberger

um: Cleanup SIGTERM handling

Richard reported that some UML processes survive if the UML
main process receives a SIGTERM.
This issue was caused by a wrongly placed signal(SIGTERM, SIG_DFL)
in init_new_thread_signals().
It disabled the UML exit handler accidently for some processes.
The correct solution is to disable the fatal handler for all
UML helper threads/processes.
Such that last_ditch_exit() does not get called multiple times
and all processes can exit due to SIGTERM.
Reported-and-tested-by: NRichard W.M. Jones <rjones@redhat.com>
Signed-off-by: NRichard Weinberger <richard@nod.at>
上级 bc1d72e7
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#ifndef __UM_UBD_USER_H #ifndef __UM_UBD_USER_H
#define __UM_UBD_USER_H #define __UM_UBD_USER_H
extern void ignore_sigwinch_sig(void);
extern int start_io_thread(unsigned long sp, int *fds_out); extern int start_io_thread(unsigned long sp, int *fds_out);
extern int io_thread(void *arg); extern int io_thread(void *arg);
extern int kernel_fd; extern int kernel_fd;
......
...@@ -1476,7 +1476,8 @@ int io_thread(void *arg) ...@@ -1476,7 +1476,8 @@ int io_thread(void *arg)
struct io_thread_req *req; struct io_thread_req *req;
int n; int n;
ignore_sigwinch_sig(); os_fix_helper_signals();
while(1){ while(1){
n = os_read_file(kernel_fd, &req, n = os_read_file(kernel_fd, &req,
sizeof(struct io_thread_req *)); sizeof(struct io_thread_req *));
......
...@@ -21,11 +21,6 @@ ...@@ -21,11 +21,6 @@
#include "ubd.h" #include "ubd.h"
#include <os.h> #include <os.h>
void ignore_sigwinch_sig(void)
{
signal(SIGWINCH, SIG_IGN);
}
int start_io_thread(unsigned long sp, int *fd_out) int start_io_thread(unsigned long sp, int *fd_out)
{ {
int pid, fds[2], err; int pid, fds[2], err;
......
...@@ -235,6 +235,7 @@ extern void setup_machinename(char *machine_out); ...@@ -235,6 +235,7 @@ extern void setup_machinename(char *machine_out);
extern void setup_hostinfo(char *buf, int len); extern void setup_hostinfo(char *buf, int len);
extern void os_dump_core(void) __attribute__ ((noreturn)); extern void os_dump_core(void) __attribute__ ((noreturn));
extern void um_early_printk(const char *s, unsigned int n); extern void um_early_printk(const char *s, unsigned int n);
extern void os_fix_helper_signals(void);
/* time.c */ /* time.c */
extern void idle_sleep(unsigned long long nsecs); extern void idle_sleep(unsigned long long nsecs);
......
...@@ -104,8 +104,7 @@ static int aio_thread(void *arg) ...@@ -104,8 +104,7 @@ static int aio_thread(void *arg)
struct io_event event; struct io_event event;
int err, n, reply_fd; int err, n, reply_fd;
signal(SIGWINCH, SIG_IGN); os_fix_helper_signals();
while (1) { while (1) {
n = io_getevents(ctx, 1, 1, &event, NULL); n = io_getevents(ctx, 1, 1, &event, NULL);
if (n < 0) { if (n < 0) {
...@@ -173,7 +172,7 @@ static int not_aio_thread(void *arg) ...@@ -173,7 +172,7 @@ static int not_aio_thread(void *arg)
struct aio_thread_reply reply; struct aio_thread_reply reply;
int err; int err;
signal(SIGWINCH, SIG_IGN); os_fix_helper_signals();
while (1) { while (1) {
err = read(aio_req_fd_r, &req, sizeof(req)); err = read(aio_req_fd_r, &req, sizeof(req));
if (err != sizeof(req)) { if (err != sizeof(req)) {
......
...@@ -294,5 +294,4 @@ void init_new_thread_signals(void) ...@@ -294,5 +294,4 @@ void init_new_thread_signals(void)
signal(SIGHUP, SIG_IGN); signal(SIGHUP, SIG_IGN);
set_handler(SIGIO); set_handler(SIGIO);
signal(SIGWINCH, SIG_IGN); signal(SIGWINCH, SIG_IGN);
signal(SIGTERM, SIG_DFL);
} }
...@@ -55,7 +55,7 @@ static int write_sigio_thread(void *unused) ...@@ -55,7 +55,7 @@ static int write_sigio_thread(void *unused)
int i, n, respond_fd; int i, n, respond_fd;
char c; char c;
signal(SIGWINCH, SIG_IGN); os_fix_helper_signals();
fds = &current_poll; fds = &current_poll;
while (1) { while (1) {
n = poll(fds->poll, fds->used, -1); n = poll(fds->poll, fds->used, -1);
......
...@@ -94,6 +94,16 @@ static inline void __attribute__ ((noreturn)) uml_abort(void) ...@@ -94,6 +94,16 @@ static inline void __attribute__ ((noreturn)) uml_abort(void)
exit(127); exit(127);
} }
/*
* UML helper threads must not handle SIGWINCH/INT/TERM
*/
void os_fix_helper_signals(void)
{
signal(SIGWINCH, SIG_IGN);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
}
void os_dump_core(void) void os_dump_core(void)
{ {
int pid; int pid;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册