# On various places (mostly waitpid() calls) this patch makes sure # that if errno == EINTR on return, then the syscall is endlessly retried. # It also defines a simple generic way to do this. # # Signed-off-by: Index: um/arch/um/drivers/net_user.c =================================================================== --- um.orig/arch/um/drivers/net_user.c 2004-08-05 22:55:06.000000000 -0400 +++ um/arch/um/drivers/net_user.c 2004-08-12 14:26:20.000000000 -0400 @@ -176,7 +176,7 @@ read_output(fds[0], output, output_len); os_close_file(fds[0]); os_close_file(fds[1]); - waitpid(pid, NULL, 0); + CATCH_EINTR(waitpid(pid, NULL, 0)); return(pid); } Index: um/arch/um/drivers/slip_user.c =================================================================== --- um.orig/arch/um/drivers/slip_user.c 2004-07-27 16:49:10.000000000 -0400 +++ um/arch/um/drivers/slip_user.c 2004-08-12 14:26:20.000000000 -0400 @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include @@ -100,7 +100,9 @@ printk("%s", output); kfree(output); } - if(waitpid(pid, &status, 0) < 0) err = errno; + CATCH_EINTR(err = waitpid(pid, &status, 0)); + if(err < 0) + err = errno; else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)){ printk("'%s' didn't exit with status 0\n", argv[0]); err = -EINVAL; Index: um/arch/um/drivers/slirp_user.c =================================================================== --- um.orig/arch/um/drivers/slirp_user.c 2004-07-27 16:49:10.000000000 -0400 +++ um/arch/um/drivers/slirp_user.c 2004-08-12 14:26:20.000000000 -0400 @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include "user_util.h" @@ -113,13 +113,13 @@ } #endif - err = waitpid(pri->pid, &status, WNOHANG); - if(err<0) { + CATCH_EINTR(err = waitpid(pri->pid, &status, WNOHANG)); + if(err < 0) { printk("slirp_close: waitpid returned %d\n", errno); return; } - if(err==0) { + if(err == 0) { printk("slirp_close: process %d has not exited\n"); return; } Index: um/arch/um/include/user_util.h =================================================================== --- um.orig/arch/um/include/user_util.h 2004-08-06 15:02:45.000000000 -0400 +++ um/arch/um/include/user_util.h 2004-08-12 14:26:20.000000000 -0400 @@ -8,6 +8,8 @@ #include "sysdep/ptrace.h" +#define CATCH_EINTR(expr) while (((expr) < 0) && (errno == EINTR)) + extern int mode_tt; extern int grantpt(int __fd); Index: um/arch/um/kernel/frame.c =================================================================== --- um.orig/arch/um/kernel/frame.c 2004-07-27 16:49:10.000000000 -0400 +++ um/arch/um/kernel/frame.c 2004-08-12 14:26:20.000000000 -0400 @@ -21,6 +21,7 @@ #include "sysdep/sigcontext.h" #include "frame_user.h" #include "kern_util.h" +#include "user_util.h" #include "ptrace_user.h" #include "os.h" @@ -40,7 +41,7 @@ /* Wait for it to stop itself and continue it with a SIGUSR1 to force * it into the signal handler. */ - n = waitpid(pid, &status, WUNTRACED); + CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); if(n < 0){ printf("capture_stack : waitpid failed - errno = %d\n", errno); exit(1); @@ -60,7 +61,7 @@ * At this point, the handler has stuffed the addresses of * sig, sc, and SA_RESTORER in raw. */ - n = waitpid(pid, &status, WUNTRACED); + CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); if(n < 0){ printf("capture_stack : waitpid failed - errno = %d\n", errno); exit(1); @@ -82,7 +83,8 @@ errno); exit(1); } - if(waitpid(pid, &status, 0) < 0){ + CATCH_EINTR(n = waitpid(pid, &status, 0)); + if(n < 0){ printf("capture_stack : waitpid failed - errno = %d\n", errno); exit(1); } Index: um/arch/um/kernel/helper.c =================================================================== --- um.orig/arch/um/kernel/helper.c 2004-08-05 22:55:06.000000000 -0400 +++ um/arch/um/kernel/helper.c 2004-08-12 14:26:20.000000000 -0400 @@ -12,6 +12,7 @@ #include #include "user.h" #include "kern_util.h" +#include "user_util.h" #include "os.h" struct helper_data { @@ -96,7 +97,7 @@ os_kill_process(pid, 1); } else if(n != 0){ - waitpid(pid, NULL, 0); + CATCH_EINTR(n = waitpid(pid, NULL, 0)); pid = -errno; } err = pid; Index: um/arch/um/kernel/process.c =================================================================== --- um.orig/arch/um/kernel/process.c 2004-08-05 22:55:06.000000000 -0400 +++ um/arch/um/kernel/process.c 2004-08-12 14:26:20.000000000 -0400 @@ -120,7 +120,7 @@ /* Start the process and wait for it to kill itself */ new_pid = clone(outer_tramp, (void *) sp, clone_flags, &arg); if(new_pid < 0) return(-errno); - while(((err = waitpid(new_pid, &status, 0)) < 0) && (errno == EINTR)) ; + CATCH_EINTR(err = waitpid(new_pid, &status, 0)); if(err < 0) panic("Waiting for outer trampoline failed - errno = %d", errno); if(!WIFSIGNALED(status) || (WTERMSIG(status) != SIGKILL)) @@ -156,7 +156,7 @@ pid = clone(ptrace_child, (void *) sp, SIGCHLD, NULL); if(pid < 0) panic("check_ptrace : clone failed, errno = %d", errno); - n = waitpid(pid, &status, WUNTRACED); + CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); if(n < 0) panic("check_ptrace : wait failed, errno = %d", errno); if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP)) @@ -173,7 +173,7 @@ if(ptrace(PTRACE_CONT, pid, 0, 0) < 0) panic("check_ptrace : ptrace failed, errno = %d", errno); - n = waitpid(pid, &status, 0); + CATCH_EINTR(n = waitpid(pid, &status, 0)); if(!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) panic("check_ptrace : child exited with status 0x%x", status); @@ -193,7 +193,7 @@ if(ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) panic("check_ptrace : ptrace failed, errno = %d", errno); - n = waitpid(pid, &status, WUNTRACED); + CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); if(n < 0) panic("check_ptrace : wait failed, errno = %d", errno); if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGTRAP)) Index: um/arch/um/kernel/skas/exec_user.c =================================================================== --- um.orig/arch/um/kernel/skas/exec_user.c 2004-05-09 22:32:02.000000000 -0400 +++ um/arch/um/kernel/skas/exec_user.c 2004-08-12 14:26:20.000000000 -0400 @@ -11,6 +11,7 @@ #include #include "user.h" #include "kern_util.h" +#include "user_util.h" #include "os.h" #include "time_user.h" @@ -26,7 +27,7 @@ int user_thread(unsigned long stack, int flags) { - int pid, status; + int pid, status, err; pid = clone(user_thread_tramp, (void *) stack_sp(stack), flags | CLONE_FILES | SIGCHLD, NULL); @@ -35,7 +36,8 @@ return(pid); } - if(waitpid(pid, &status, WUNTRACED) < 0){ + CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED)); + if(err < 0){ printk("user_thread - waitpid failed, errno = %d\n", errno); return(-errno); } Index: um/arch/um/kernel/skas/process.c =================================================================== --- um.orig/arch/um/kernel/skas/process.c 2004-08-12 14:23:12.000000000 -0400 +++ um/arch/um/kernel/skas/process.c 2004-08-12 14:26:20.000000000 -0400 @@ -78,7 +78,7 @@ panic("handle_trap - continuing to end of syscall failed, " "errno = %d\n", errno); - err = waitpid(pid, &status, WUNTRACED); + CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED)); if((err < 0) || !WIFSTOPPED(status) || (WSTOPSIG(status) != SIGTRAP)) panic("handle_trap - failed to wait at end of syscall, " "errno = %d, status = %d\n", errno, status); @@ -117,7 +117,7 @@ panic("start_userspace : clone failed, errno = %d", errno); do { - n = waitpid(pid, &status, WUNTRACED); + CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); if(n < 0) panic("start_userspace : wait failed, errno = %d", errno); @@ -144,7 +144,7 @@ panic("userspace - PTRACE_SYSCALL failed, errno = %d\n", errno); while(1){ - err = waitpid(pid, &status, WUNTRACED); + CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED)); if(err < 0) panic("userspace - waitpid failed, errno = %d\n", errno); Index: um/arch/um/kernel/trap_user.c =================================================================== --- um.orig/arch/um/kernel/trap_user.c 2004-08-05 22:55:06.000000000 -0400 +++ um/arch/um/kernel/trap_user.c 2004-08-12 14:26:20.000000000 -0400 @@ -32,7 +32,14 @@ { kill(pid, SIGKILL); kill(pid, SIGCONT); - while(waitpid(pid, NULL, 0) > 0) kill(pid, SIGCONT); + do { + int n; + CATCH_EINTR(n = waitpid(pid, NULL, 0)); + if (n > 0) + kill(pid, SIGCONT); + else + break; + } while(1); } /* Unlocked - don't care if this is a bit off */ Index: um/arch/um/kernel/tt/exec_user.c =================================================================== --- um.orig/arch/um/kernel/tt/exec_user.c 2004-05-09 22:33:13.000000000 -0400 +++ um/arch/um/kernel/tt/exec_user.c 2004-08-12 14:26:20.000000000 -0400 @@ -19,13 +19,18 @@ void do_exec(int old_pid, int new_pid) { unsigned long regs[FRAME_SIZE]; + int err; if((ptrace(PTRACE_ATTACH, new_pid, 0, 0) < 0) || - (ptrace(PTRACE_CONT, new_pid, 0, 0) < 0) || - (waitpid(new_pid, 0, WUNTRACED) < 0)) + (ptrace(PTRACE_CONT, new_pid, 0, 0) < 0)) tracer_panic("do_exec failed to attach proc - errno = %d", errno); + CATCH_EINTR(err = waitpid(new_pid, 0, WUNTRACED)); + if (err < 0) + tracer_panic("do_exec failed to attach proc in waitpid - errno = %d", + errno); + if(ptrace_getregs(old_pid, regs) < 0) tracer_panic("do_exec failed to get registers - errno = %d", errno); Index: um/arch/um/kernel/tt/ptproxy/proxy.c =================================================================== --- um.orig/arch/um/kernel/tt/ptproxy/proxy.c 2004-07-27 16:49:10.000000000 -0400 +++ um/arch/um/kernel/tt/ptproxy/proxy.c 2004-08-12 14:26:20.000000000 -0400 @@ -272,7 +272,7 @@ child_proxy(1, W_EXITCODE(0, 0)); while(debugger.waiting == 1){ - pid = waitpid(debugger.pid, &status, WUNTRACED); + CATCH_EINTR(pid = waitpid(debugger.pid, &status, WUNTRACED)); if(pid != debugger.pid){ printk("fake_child_exit - waitpid failed, " "errno = %d\n", errno); @@ -280,7 +280,7 @@ } debugger_proxy(status, debugger.pid); } - pid = waitpid(debugger.pid, &status, WUNTRACED); + CATCH_EINTR(pid = waitpid(debugger.pid, &status, WUNTRACED)); if(pid != debugger.pid){ printk("fake_child_exit - waitpid failed, " "errno = %d\n", errno); Index: um/arch/um/kernel/tt/tracer.c =================================================================== --- um.orig/arch/um/kernel/tt/tracer.c 2004-07-27 16:49:10.000000000 -0400 +++ um/arch/um/kernel/tt/tracer.c 2004-08-12 14:26:20.000000000 -0400 @@ -192,7 +192,7 @@ printf("tracing thread pid = %d\n", tracing_pid); pid = clone(signal_tramp, sp, CLONE_FILES | SIGCHLD, init_proc); - n = waitpid(pid, &status, WUNTRACED); + CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); if(n < 0){ printf("waitpid on idle thread failed, errno = %d\n", errno); exit(1); @@ -233,7 +233,7 @@ } set_cmdline("(tracing thread)"); while(1){ - pid = waitpid(-1, &status, WUNTRACED); + CATCH_EINTR(pid = waitpid(-1, &status, WUNTRACED)); if(pid <= 0){ if(errno != ECHILD){ printf("wait failed - errno = %d\n", errno); Index: um/arch/um/kernel/user_util.c =================================================================== --- um.orig/arch/um/kernel/user_util.c 2004-08-06 15:02:45.000000000 -0400 +++ um/arch/um/kernel/user_util.c 2004-08-12 14:26:20.000000000 -0400 @@ -82,11 +82,10 @@ int status, ret; while(1){ - ret = waitpid(pid, &status, WUNTRACED); + CATCH_EINTR(ret = waitpid(pid, &status, WUNTRACED)); if((ret < 0) || !WIFSTOPPED(status) || (WSTOPSIG(status) != sig)){ if(ret < 0){ - if(errno == EINTR) continue; printk("wait failed, errno = %d\n", errno); } @@ -125,9 +124,9 @@ struct termios tt; int err; - tcgetattr(fd, &tt); + CATCH_EINTR(tcgetattr(fd, &tt)); cfmakeraw(&tt); - err = tcsetattr(fd, TCSANOW, &tt); + CATCH_EINTR(err = tcsetattr(fd, TCSANOW, &tt)); if((err < 0) && complain){ printk("tcsetattr failed, errno = %d\n", errno); return(-errno); Index: um/arch/um/os-Linux/drivers/ethertap_user.c =================================================================== --- um.orig/arch/um/os-Linux/drivers/ethertap_user.c 2004-07-27 16:49:10.000000000 -0400 +++ um/arch/um/os-Linux/drivers/ethertap_user.c 2004-08-12 14:26:20.000000000 -0400 @@ -16,6 +16,7 @@ #include #include "user.h" #include "kern_util.h" +#include "user_util.h" #include "net_user.h" #include "etap.h" #include "helper.h" @@ -125,7 +126,8 @@ if(c != 1){ printk("etap_tramp : uml_net failed\n"); err = -EINVAL; - if(waitpid(pid, &status, 0) < 0) + CATCH_EINTR(n = waitpid(pid, &status, 0)); + if(n < 0) err = -errno; else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 1)) printk("uml_net didn't exit with status 1\n"); Index: um/arch/um/os-Linux/drivers/tuntap_user.c =================================================================== --- um.orig/arch/um/os-Linux/drivers/tuntap_user.c 2004-07-27 16:49:10.000000000 -0400 +++ um/arch/um/os-Linux/drivers/tuntap_user.c 2004-08-12 14:26:20.000000000 -0400 @@ -18,6 +18,7 @@ #include "net_user.h" #include "tuntap.h" #include "kern_util.h" +#include "user_util.h" #include "user.h" #include "helper.h" #include "os.h" @@ -108,7 +109,7 @@ errno); return(-errno); } - waitpid(pid, NULL, 0); + CATCH_EINTR(waitpid(pid, NULL, 0)); cmsg = CMSG_FIRSTHDR(&msg); if(cmsg == NULL){ Index: um/arch/um/os-Linux/process.c =================================================================== --- um.orig/arch/um/os-Linux/process.c 2004-08-05 22:55:06.000000000 -0400 +++ um/arch/um/os-Linux/process.c 2004-08-12 14:26:20.000000000 -0400 @@ -12,6 +12,7 @@ #include #include "os.h" #include "user.h" +#include "user_util.h" #define ARBITRARY_ADDR -1 #define FAILURE_PID -1 @@ -89,7 +90,7 @@ { kill(pid, SIGKILL); if(reap_child) - waitpid(pid, NULL, 0); + CATCH_EINTR(waitpid(pid, NULL, 0)); }