Skip to content

Commit 91d44ff

Browse files
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: Richard W.M. Jones <rjones@redhat.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent bc1d72e commit 91d44ff

8 files changed

Lines changed: 16 additions & 12 deletions

File tree

‎arch/um/drivers/ubd.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#ifndef __UM_UBD_USER_H
88
#define __UM_UBD_USER_H
99

10-
extern void ignore_sigwinch_sig(void);
1110
extern int start_io_thread(unsigned long sp, int *fds_out);
1211
extern int io_thread(void *arg);
1312
extern int kernel_fd;

‎arch/um/drivers/ubd_kern.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,8 @@ int io_thread(void *arg)
14761476
struct io_thread_req *req;
14771477
int n;
14781478

1479-
ignore_sigwinch_sig();
1479+
os_fix_helper_signals();
1480+
14801481
while(1){
14811482
n = os_read_file(kernel_fd, &req,
14821483
sizeof(struct io_thread_req *));

‎arch/um/drivers/ubd_user.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
#include "ubd.h"
2222
#include <os.h>
2323

24-
void ignore_sigwinch_sig(void)
25-
{
26-
signal(SIGWINCH, SIG_IGN);
27-
}
28-
2924
int start_io_thread(unsigned long sp, int *fd_out)
3025
{
3126
int pid, fds[2], err;

‎arch/um/include/shared/os.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ extern void setup_machinename(char *machine_out);
235235
extern void setup_hostinfo(char *buf, int len);
236236
extern void os_dump_core(void) __attribute__ ((noreturn));
237237
extern void um_early_printk(const char *s, unsigned int n);
238+
extern void os_fix_helper_signals(void);
238239

239240
/* time.c */
240241
extern void idle_sleep(unsigned long long nsecs);

‎arch/um/os-Linux/aio.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ static int aio_thread(void *arg)
104104
struct io_event event;
105105
int err, n, reply_fd;
106106

107-
signal(SIGWINCH, SIG_IGN);
108-
107+
os_fix_helper_signals();
109108
while (1) {
110109
n = io_getevents(ctx, 1, 1, &event, NULL);
111110
if (n < 0) {
@@ -173,7 +172,7 @@ static int not_aio_thread(void *arg)
173172
struct aio_thread_reply reply;
174173
int err;
175174

176-
signal(SIGWINCH, SIG_IGN);
175+
os_fix_helper_signals();
177176
while (1) {
178177
err = read(aio_req_fd_r, &req, sizeof(req));
179178
if (err != sizeof(req)) {

‎arch/um/os-Linux/process.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,5 +294,4 @@ void init_new_thread_signals(void)
294294
signal(SIGHUP, SIG_IGN);
295295
set_handler(SIGIO);
296296
signal(SIGWINCH, SIG_IGN);
297-
signal(SIGTERM, SIG_DFL);
298297
}

‎arch/um/os-Linux/sigio.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static int write_sigio_thread(void *unused)
5555
int i, n, respond_fd;
5656
char c;
5757

58-
signal(SIGWINCH, SIG_IGN);
58+
os_fix_helper_signals();
5959
fds = &current_poll;
6060
while (1) {
6161
n = poll(fds->poll, fds->used, -1);

‎arch/um/os-Linux/util.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ static inline void __attribute__ ((noreturn)) uml_abort(void)
9494
exit(127);
9595
}
9696

97+
/*
98+
* UML helper threads must not handle SIGWINCH/INT/TERM
99+
*/
100+
void os_fix_helper_signals(void)
101+
{
102+
signal(SIGWINCH, SIG_IGN);
103+
signal(SIGINT, SIG_DFL);
104+
signal(SIGTERM, SIG_DFL);
105+
}
106+
97107
void os_dump_core(void)
98108
{
99109
int pid;

0 commit comments

Comments
 (0)