-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSIGNAL.C
157 lines (145 loc) · 3 KB
/
SIGNAL.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* Copyright (c) 1990,1991,1992 Chris and John Downey */
#ifndef lint
static char *sccsid = "@(#)signal.c 2.1 (Chris & John Downey) 7/29/92";
#endif
/***
* program name:
xvi
* function:
PD version of UNIX "vi" editor, with extensions.
* module name:
signal.c
* module function:
Signal handling routines.
This is all fairly system-dependent, & may be replaced by more
system-specific routines if required. On MS-DOS, for instance,
this module isn't used at all: ignore_signals() &
catch_signals() are defined in msdos_c.c & msdos_a.asm instead.
* history:
STEVIE - ST Editor for VI Enthusiasts, Version 3.10
Originally by Tim Thompson (twitch!tjt)
Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
Heavily modified by Chris & John Downey
***/
#include "xvi.h"
/*
* Signal handlers.
*/
#ifdef SIGINT
static void int_handler P((int));
#endif
#ifdef SIGTSTP
static void tstp_handler P((int));
#endif
#ifdef SIGHUP
static void hup_handler P((int));
#endif
#ifdef SIGTERM
static void term_handler P((int));
#endif
void
ignore_signals()
{
#ifdef SIGINT
(void) signal(SIGINT, SIG_IGN);
#endif
#ifdef SIGBREAK
/*
* On OS/2, this is generated by pressing control-break.
*/
(void) signal(SIGBREAK, SIG_IGN);
#endif
#ifdef SIGQUIT
(void) signal(SIGQUIT, SIG_IGN);
#endif
#ifdef SIGTSTP
(void) signal(SIGTSTP, SIG_IGN);
#endif
/*
* There isn't much point in catching or ignoring SIGHUP
* signals until we have some modified buffers to preserve.
*/
#ifdef SIGTERM
(void) signal(SIGTERM, SIG_IGN);
#endif
}
void
catch_signals()
{
#ifdef SIGINT
(void) signal(SIGINT, int_handler);
#endif
#ifdef SIGBREAK
/*
* On OS/2, this is generated by pressing control-break.
*/
(void) signal(SIGBREAK, int_handler);
#endif
#ifdef SIGTSTP
(void) signal(SIGTSTP, tstp_handler);
#endif
#ifdef SIGHUP
(void) signal(SIGHUP, hup_handler);
#endif
#ifdef SIGTERM
(void) signal(SIGTERM, term_handler);
#endif
}
/*
* Handler for SIGINT (keyboard interrupt).
*/
#ifdef SIGINT
static void
int_handler(sig)
int sig;
{
signal(SIGINT, int_handler);
kbdintr = 1;
}
#endif
/*
* This function is used on UNIX as the signal handler
* for the keyboard-generated TSTP signal.
*/
#ifdef SIGTSTP
static void
tstp_handler(sig)
int sig;
{
do_suspend(curwin);
}
#endif
/*
* This one is used for the hangup signal, which generally means that
* the terminal line has gone dead. This means sys_exit() doesn't make
* much sense, so we call exit() instead.
*/
#ifdef SIGHUP
static void
hup_handler(sig)
int sig;
{
signal(SIGHUP, SIG_IGN);
/*
* Make backup copies of all modified buffers.
*/
(void) do_preserve();
exit(0);
}
#endif
/*
* This one is used for the software-generated terminate signal.
*/
#ifdef SIGTERM
static void
term_handler(sig)
int sig;
{
signal(SIGTERM, SIG_IGN);
/*
* Make backup copies of all modified buffers.
*/
(void) do_preserve();
sys_exit(0);
}
#endif