summaryrefslogtreecommitdiffstats
path: root/applications/rasql/rasql_signal.cc
blob: 49ce7d4ccb179fce9f6b074bef61ded4838020a8 (plain)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
/

/**
* rasql_signal
*
* PURPOSE:	Provides signal handling
*
* COMMENTS:
*
* 	No comments
*/


static const char rcsid[] = "@(#)rasodmg/test,ImportOrthoUtil: $Id: rasql_signal.cc,v 1.1 2003/12/27 19:30:23 rasdev Exp $";

#ifdef EARLY_TEMPLATE
#define __EXECUTABLE__
#include "raslib/template_inst.hh"
#endif

#include <iostream>
#include <string>
#include <iostream>
#include <signal.h>
#ifdef SOLARIS
#include <strings.h>
#endif

#include "rasql_error.hh"
#include "rasql_signal.hh"

// debug facility; relies on -DDEBUG at compile time
#include "debug-clt.hh"

//signalCleanup function is called when a signal is received by the program.
//You should write your function in order to have signal management
void signalCleanup();

//signalHandler function is called when a signal occurs
void
signalHandler(int sig);

//installSignalHandlers function should be called first in main function
//in order to receive a signal in your program
void
signalHandler(int sig)
{
	static bool handleSignal = true;	// sema to prevent nested signals

	cout << "Caught signal " << sig << ": ";
	switch (sig)
		{
		case SIGHUP:
			cout << "Hangup (POSIX).  ";
			break;
		case SIGINT:
			cout << "Interrupt (ANSI).";
			break;
		case SIGQUIT:
			cout << "Quit (POSIX).";
			break;
		case SIGILL:
			cout << "Illegal instruction (ANSI).";
			break;
		case SIGTRAP:
			cout << "Trace trap (POSIX).";
			break;
		case SIGABRT:
			cout << "Abort (ANSI) or IOT trap (4.2 BSD).";
			break;
		case SIGBUS:
			cout << "BUS error (4.2 BSD).";
			break;
		case SIGFPE:
			cout << "Floating-point exception (ANSI).";
			break;
		case SIGKILL:
			cout << "Kill, unblockable (POSIX).";
			break;
		case SIGUSR1:
			cout << "User-defined signal 1 (POSIX).";
			break;
		case SIGSEGV:
			cout << "Segmentation violation (ANSI).";
			break;
		case SIGUSR2:
			cout << "User-defined signal 2 (POSIX).";
			break;
		case SIGPIPE:
			cout << "Broken pipe (POSIX).";
			break;
		case SIGALRM:
			cout << "Alarm clock (POSIX).";
			break;
		case SIGTERM:
			cout << "Termination (ANSI).";
			break;
#ifndef SOLARIS
#ifndef DECALPHA
		case SIGSTKFLT:
			cout << "Stack fault.";
			break;
#endif
#endif
		case SIGCLD:
			cout << "SIGCHLD (System V) or child status has changed (POSIX).";
			break;
		case SIGCONT:
			cout << "Continue (POSIX).";
			break;
		case SIGSTOP:
			cout << "Stop, unblockable (POSIX).";
			break;
		case SIGTSTP:
			cout << "Keyboard stop (POSIX). Continuing operation.";
			break;
		case SIGTTIN:
			cout << "Background read from tty (POSIX).";
			break;
		case SIGTTOU:
			cout << "Background write to tty (POSIX). Continuing operation";
			break;
		case SIGURG:
			cout << "Urgent condition on socket (4.2 BSD).";
			break;
		case SIGXCPU:
			cout << "CPU limit exceeded (4.2 BSD).";
			break;
		case SIGXFSZ:
			cout << "File size limit exceeded (4.2 BSD).";
			break;
		case SIGVTALRM:
			cout << "Virtual alarm clock (4.2 BSD).";
			break;
		case SIGPROF:
			cout << "Profiling alarm clock (4.2 BSD).";
			break;
		case SIGWINCH:
			cout << "Window size change (4.3 BSD, Sun). Continuing operation.";
			break;
		case SIGPOLL:
			cout << "Pollable event occurred (System V) or I/O now possible (4.2 BSD).";
			break;
		case SIGPWR:
			cout << "Power failure restart (System V).";
			break;
		case SIGSYS:
			cout << "Bad system call.";
			break;
		default:
			cout << "Unknown signal.";
			break;
		}
	cout << endl << flush; 

	// no repeated signals
	if (handleSignal)
		handleSignal = false;

	if (sig == SIGCONT || sig == SIGTSTP || sig == SIGTTIN || sig == SIGTTOU || sig == SIGWINCH)
		return;
	else
	{
		TALK( "fatal signal, exiting." << flush );
		exit(sig);
	}
}

void
installSignalHandlers()
{
        ENTER( "installSignalHandlers" );

	signal(SIGINT, signalHandler);
	signal(SIGTERM, signalHandler);
	signal(SIGHUP, signalHandler);
	signal(SIGPIPE, signalHandler);
	signal(SIGHUP, signalHandler);
	signal(SIGINT, signalHandler);
	signal(SIGQUIT, signalHandler);
	signal(SIGILL, signalHandler);
	signal(SIGTRAP, signalHandler);
	signal(SIGABRT, signalHandler);
	signal(SIGIOT, signalHandler);
	signal(SIGBUS, signalHandler);
	signal(SIGFPE, signalHandler);
	signal(SIGKILL, signalHandler);
	signal(SIGUSR1, signalHandler);
	signal(SIGSEGV, signalHandler);
	signal(SIGUSR2, signalHandler);
	signal(SIGPIPE, signalHandler);
	signal(SIGALRM, signalHandler);
	signal(SIGTERM, signalHandler);
#ifndef SOLARIS
#ifndef DECALPHA
	signal(SIGSTKFLT, signalHandler);
#endif
#endif
	signal(SIGCLD, signalHandler);
	signal(SIGCHLD, signalHandler);
	signal(SIGCONT, signalHandler);
	signal(SIGSTOP, signalHandler);
	signal(SIGTSTP, signalHandler);
	signal(SIGTTIN, signalHandler);
	signal(SIGTTOU, signalHandler);
	signal(SIGURG, signalHandler);
	signal(SIGXCPU, signalHandler);
	signal(SIGXFSZ, signalHandler);
	signal(SIGVTALRM, signalHandler);
	signal(SIGPROF, signalHandler);
	signal(SIGWINCH, signalHandler);
	signal(SIGPOLL, signalHandler);
	signal(SIGIO, signalHandler);
	signal(SIGPWR, signalHandler);
	signal(SIGSYS, signalHandler);
#if !defined SOLARIS
#if !defined DECALPHA
	signal(SIGUNUSED, signalHandler);
#endif
#endif
        LEAVE( "installSignalHandlers" );
}