File: sighandler.c

package info (click to toggle)
nat 1:1.0-6
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 524 kB
  • ctags: 1,528
  • sloc: ansic: 9,771; makefile: 79
file content (113 lines) | stat: -rw-r--r-- 2,223 bytes parent folder | download
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
/* Nessus
 * Copyright (C) 1998 - 2004 Renaud Deraison
 *
 * Adapted for the Netbios Auditing Tool by Javier Fernandez-Sanguino
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation
 *
 * 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.
 *
 *
 * Signals handlers
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "sighandler.h"
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif


void (*set_signal(int signum, void (*handler)(int)))(int)
{
	struct sigaction saNew,saOld;

	/* Init new handler */
	sigfillset(&saNew.sa_mask);
	sigdelset(&saNew.sa_mask, SIGALRM); /* make sleep() work */

	saNew.sa_flags = 0;
# ifdef HAVE_SIGNAL_SA_RESTORER
	saNew.sa_restorer = 0; /* not avail on Solaris - jordan */
# endif
	saNew.sa_handler = handler;

	sigaction(signum, &saNew, &saOld);
	return saOld.sa_handler;
}


void sighandler(sign)
	int sign;
{
	char * sig = NULL;
	int murderer = 0;

	switch(sign)
	{
		case SIGTERM:
			sig = "TERM";
			close_sockets();
			break;
		case SIGINT :
			sig = "INT";
			close_sockets();
			break;
		case SIGPIPE :
			sig = "PIPE";
			close_sockets();
			break;
		case SIGSEGV :
#ifdef HAVE__EXIT
			signal(SIGSEGV, _exit);
#else
			signal(SIGSEGV, exit);
#endif
			sig = "SEGV";
			break;
		default:
			sig = "unknown signal";
	}
	fprintf(stderr, "Received signal %s!\n", sig);
#ifdef HAVE__EXIT
	_exit(1);
#else
	exit(1);
#endif

}


void sighand_segv()
{
#ifdef HAVE__EXIT
	signal(SIGSEGV, _exit);
#else
	signal(SIGSEGV, exit);
#endif
	fprintf(stderr, "Received SIGSEGV!\n");
#ifdef HAVE__EXIT
	_exit(1);
#else
	exit(1);
#endif
}