1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
static int (*real_clone)(int (*)(void *), void *, int, void *) = NULL;
int
wrap_clone(int (*fn)(void *), void *child_stack, int flags, void *arg) {
/* unused */
return 0;
}
int
clone(int (*fn)(void *), void *child_stack, int flags, void *arg) {
sigset_t saved;
va_list ap;
pid_t *pid;
struct user_desc *tls;
pid_t *ctid;
int rc = -1;
if (!pseudo_check_wrappers() || !real_clone) {
/* rc was initialized to the "failure" value */
pseudo_enosys("clone");
return rc;
}
pseudo_debug(4, "called: clone\n");
pseudo_sigblock(&saved);
if (pseudo_getlock()) {
errno = EBUSY;
sigprocmask(SIG_SETMASK, &saved, NULL);
return -1;
}
int save_errno;
int save_disabled = pseudo_disabled;
/* because clone() doesn't actually continue in this function, we
* can't check the return and fix up environment variables in the
* child. Instead, we have to temporarily do any fixup, then possibly
* undo it later. UGH!
*/
#include "guts/clone.c"
if (save_disabled != pseudo_disabled) {
if (pseudo_disabled) {
pseudo_disabled = 0;
pseudo_magic();
} else {
pseudo_disabled = 1;
pseudo_antimagic();
}
}
save_errno = errno;
pseudo_droplock();
sigprocmask(SIG_SETMASK, &saved, NULL);
pseudo_debug(4, "completed: clone\n");
errno = save_errno;
return rc;
}
|