-
Notifications
You must be signed in to change notification settings - Fork 4
/
suspend.c
67 lines (54 loc) · 1.08 KB
/
suspend.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include "errno.h"
#if HAVE_SIGNAL_H
# include <signal.h>
#endif
#if HAVE_STRING_H
# include <string.h>
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "init.h"
int do_tstp = 0;
static struct sigaction oact;
void
sigtstp(int unused)
{
do_tstp = 1;
}
int
reg_sigtstp(void)
{
struct sigaction act;
act.sa_handler = sigtstp;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_RESTART;
return sigaction(SIGTSTP, &act, &oact);
}
int
rm_sigtstp(void)
{
return sigaction(SIGTSTP, &oact, NULL);
}
void
setfg(void)
{
sigset_t osigset, nsigset;
/*
* Block the tty signals till things set correctly.
* Taken from util.c of csh in NetBSD.
*/
sigemptyset(&nsigset);
sigaddset(&nsigset, SIGTSTP);
sigaddset(&nsigset, SIGTTIN);
sigaddset(&nsigset, SIGTTOU);
sigprocmask(SIG_BLOCK, &nsigset, &osigset);
if (setpgid(0, 0))
fatal("setpgid %s", strerror(errno));
if (tcsetpgrp(0, getpid()))
fatal("tcsetpgrp %s", strerror(errno));
sigprocmask(SIG_SETMASK, &osigset, NULL);
}