-
Notifications
You must be signed in to change notification settings - Fork 3
/
signal_ops.c
37 lines (30 loc) · 953 Bytes
/
signal_ops.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
sigset_t block_sigint;
void blocksigintfunc()
{
sigemptyset(&block_sigint);
sigaddset(&block_sigint, SIGINT);
sigprocmask(SIG_BLOCK, &block_sigint, NULL);
}
void unblocksigintfunc()
{
sigprocmask(SIG_UNBLOCK, &block_sigint, NULL);
}
void forkfunc()
{
// This function mainly exists so that a multi-client capable tcp/web server
// can be had. It is assumed that the return value will be caught, inspected,
// and handled by the caller, so this is really quite a simple c->dclang mapping.
// TODO: a future enhancement might be to have a counting system in place for
// avoiding fork-bomb DoS attacks. So, the introspection of a connection limit
// before granting a new `fork`.
push((DCLANG_INT) fork());
}
void exitfunc()
{
if (data_stack_ptr < 1) {
printf("exit -- need an integer exit code on the stack");
return;
}
DCLANG_INT code = (DCLANG_INT) dclang_pop();
exit(code);
}