-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSignal.pc
More file actions
105 lines (92 loc) · 2.64 KB
/
Copy pathSignal.pc
File metadata and controls
105 lines (92 loc) · 2.64 KB
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
/**
* Signal.pc - Catch signals and finish chcsv.
*
* Copyright (C) 1995 Batayan. (kawabata@personal.email.ne.jp)
*
* This program 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 2 of the License, or
* any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
**/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#define _SQLEXTERN_
#include "extern.h"
#include "sqlhead.h"
#define SQLCA_STORAGE_CLASS extern
EXEC SQL INCLUDE sqlca.h;
EXEC SQL INCLUDE sqlda.h;
EXEC SQL INCLUDE chcsv.h;
#define BADSIG (void (*)())-1
int
CatchSignal()
{
strcpy(FUNCTION, "CatchSignal");
SetSig(SIGHUP, Cleanup);
SetSig(SIGINT, Cleanup);
SetSig(SIGQUIT, Cleanup);
SetSig(SIGTERM, Cleanup);
SetSig(SIGBUS, Cleanup);
SetSig(SIGSEGV, Cleanup);
}
void
SetSig(int sig, void (*fcn)())
{
void (*sts)();
strcpy(FUNCTION, "SetSig");
sts = signal(sig, SIG_IGN);
if( sts == SIG_DFL ){
if( signal(sig, fcn) == BADSIG){
SysErr("signal");
}
}else if( sts == SIG_IGN ){
return;
}else{
SysErr("signal");
}
}
void
Cleanup(int sig)
{
char sig_mes[128];
if( signal(sig, SIG_IGN) == BADSIG ){
SysErr("signal");
}
switch(sig){
case SIGHUP:
strcpy(sig_mes, "Terminated by hangup signal");
break;
case SIGINT:
strcpy(sig_mes, "Terminated by interrupt signal");
break;
case SIGBUS:
strcpy(sig_mes, "Terminated by internal Error: bus error");
break;
case SIGSEGV:
strcpy(sig_mes, "Terminated by internal Error: segmentation violation");
break;
default:
strcpy(sig_mes, "Terminated by signal");
}
fprintf(debug, "--------------------------------------------------------------------------------\n");
fprintf(debug, "%s: Catch signal %d\n", LDNAME, sig);
fprintf(debug, "%s\n", sig_mes);
fprintf(debug, "%s : Debugging Information\n", LDNAME);
fprintf(debug, "%s:\n", FUNCTION);
fprintf(debug, "--------------------------------------------------------------------------------\n");
FileClose();
exit(1);
}