vserver 1.9.5.x5
[linux-2.6.git] / arch / um / kernel / tt / exec_user.c
1 /* 
2  * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #include <stdio.h>
7 #include <unistd.h>
8 #include <stdlib.h>
9 #include <sched.h>
10 #include <errno.h>
11 #include <sys/wait.h>
12 #include <sys/ptrace.h>
13 #include <linux/ptrace.h>
14 #include <signal.h>
15 #include "user_util.h"
16 #include "kern_util.h"
17 #include "user.h"
18 #include "ptrace_user.h"
19 #include "os.h"
20
21 void do_exec(int old_pid, int new_pid)
22 {
23         unsigned long regs[FRAME_SIZE];
24         int err;
25
26         if((ptrace(PTRACE_ATTACH, new_pid, 0, 0) < 0) ||
27            (ptrace(PTRACE_CONT, new_pid, 0, 0) < 0))
28                 tracer_panic("do_exec failed to attach proc - errno = %d",
29                              errno);
30
31         CATCH_EINTR(err = waitpid(new_pid, 0, WUNTRACED));
32         if (err < 0)
33                 tracer_panic("do_exec failed to attach proc in waitpid - errno = %d",
34                              errno);
35
36         if(ptrace_getregs(old_pid, regs) < 0)
37                 tracer_panic("do_exec failed to get registers - errno = %d",
38                              errno);
39
40         os_kill_ptraced_process(old_pid, 0);
41
42         if (ptrace(PTRACE_OLDSETOPTIONS, new_pid, 0, (void *)PTRACE_O_TRACESYSGOOD) < 0)
43                 tracer_panic("do_exec: PTRACE_SETOPTIONS failed, errno = %d", errno);
44
45         if(ptrace_setregs(new_pid, regs) < 0)
46                 tracer_panic("do_exec failed to start new proc - errno = %d",
47                              errno);
48 }
49
50 /*
51  * Overrides for Emacs so that we follow Linus's tabbing style.
52  * Emacs will notice this stuff at the end of the file and automatically
53  * adjust the settings for this buffer only.  This must remain at the end
54  * of the file.
55  * ---------------------------------------------------------------------------
56  * Local variables:
57  * c-file-style: "linux"
58  * End:
59  */