forked from vadimkantorov/busyboxnanozipdiff3
-
Notifications
You must be signed in to change notification settings - Fork 3
/
em-shell.c
43 lines (38 loc) · 900 Bytes
/
em-shell.c
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
#include "em-shell.h"
#include <emscripten.h>
#include <errno.h>
#undef _exit
jmp_buf vfork_jump_buffer;
static int vfork_child_active = 0;
static int vfork_child_pid = 0;
int js_fork();
void js_unfork(int status);
int em_vfork(int is_parent) {
if (is_parent) {
vfork_child_active = 0;
errno = 0;
return vfork_child_pid;
}
else {
vfork_child_active = 1;
vfork_child_pid = js_fork();
return 0;
}
}
void em_exit(int status) {
if (vfork_child_active) {
js_unfork(status);
longjmp(vfork_jump_buffer, 1);
} else
_exit(status);
}
int js_spawn(const char *file, char *const argv[]);
int em_execvp(const char *file, char *const argv[]) {
errno = js_spawn(file, argv);
if (errno)
return -1;
else if (vfork_child_active)
longjmp(vfork_jump_buffer, 1);
else
_exit(0);
}