OpenVAS Scanner  7.0.0~git
sighand.c File Reference

Provides signal handling functions. More...

#include <execinfo.h>
#include <glib.h>
#include <signal.h>
#include <sys/wait.h>
#include <unistd.h>
Include dependency graph for sighand.c:

Go to the source code of this file.

Macros

#define G_LOG_DOMAIN   "sd main"
 GLib log domain. More...
 

Functions

void let_em_die (int pid)
 
void make_em_die (int sig)
 
void sighand_chld (pid_t pid)
 
static void print_trace ()
 
void sighand_segv (int given_signal)
 

Variables

void(*)(int) openvas_signal (int signum, void(*handler)(int))
 

Detailed Description

Provides signal handling functions.

Definition in file sighand.c.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "sd main"

GLib log domain.

Definition at line 36 of file sighand.c.

Function Documentation

◆ let_em_die()

void let_em_die ( int  pid)

Definition at line 40 of file sighand.c.

41 {
42  int status;
43 
44  waitpid (pid, &status, WNOHANG);
45 }

References pid.

Referenced by make_em_die().

Here is the caller graph for this function:

◆ make_em_die()

void make_em_die ( int  sig)

Definition at line 48 of file sighand.c.

49 {
50  /* number of times, the sig is sent at most */
51  int n = 3;
52 
53  /* leave if we are session leader */
54  if (getpgrp () != getpid ())
55  return;
56 
57  /* quickly send signals and check the result */
58  if (kill (0, sig) < 0)
59  return;
60  let_em_die (0);
61  if (kill (0, 0) < 0)
62  return;
63 
64  do
65  {
66  /* send the signal to everybody in the group */
67  if (kill (0, sig) < 0)
68  return;
69  sleep (1);
70  /* do not leave a zombie, hanging around if possible */
71  let_em_die (0);
72  }
73  while (--n > 0);
74 
75  if (kill (0, 0) < 0)
76  return;
77 
78  kill (0, SIGKILL);
79  sleep (1);
80  let_em_die (0);
81 }

References let_em_die().

Referenced by init_child_signal_handlers(), and sighand_segv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_trace()

static void print_trace ( )
static

Definition at line 111 of file sighand.c.

112 {
113  void *array[10];
114  int ret = 0, left;
115  char *message = "SIGSEGV occurred!\n";
116  char **strings;
117 
118  /*It used log_get_fd() in log.h to know where to log the backtrace.*/
119  ret = backtrace (array, 10);
120  strings = backtrace_symbols (array, ret);
121  g_warning ("%s", message);
122 
123  for (left = 0; left < 10; left++)
124  g_warning ("%s\n", strings[left]);
125 
126  g_free (strings);
127 }

Referenced by sighand_segv().

Here is the caller graph for this function:

◆ sighand_chld()

void sighand_chld ( pid_t  pid)

Definition at line 103 of file sighand.c.

104 {
105  int status;
106 
107  waitpid (pid, &status, WNOHANG);
108 }

References pid.

Referenced by init_signal_handlers().

Here is the caller graph for this function:

◆ sighand_segv()

void sighand_segv ( int  given_signal)

Definition at line 130 of file sighand.c.

131 {
132  signal (SIGSEGV, _exit);
133  print_trace ();
134  make_em_die (SIGTERM);
135  /* Raise signal again, to exit with the correct return value,
136  * and to enable core dumping. */
137  openvas_signal (given_signal, SIG_DFL);
138  raise (given_signal);
139 }

References make_em_die(), openvas_signal, and print_trace().

Referenced by init_child_signal_handlers().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ openvas_signal

void(*)(int) openvas_signal(int signum, void(*handler)(int))

Definition at line 87 of file sighand.c.

88 {
89  struct sigaction saNew, saOld;
90 
91  /* Init new handler */
92  sigfillset (&saNew.sa_mask);
93  sigdelset (&saNew.sa_mask, SIGALRM); /* make sleep() work */
94 
95  saNew.sa_flags = 0;
96  saNew.sa_handler = handler;
97 
98  sigaction (signum, &saNew, &saOld);
99  return saOld.sa_handler;
100 }

Referenced by attack_host(), attack_network(), init_child_signal_handlers(), init_signal_handlers(), openvas(), plugins_reload_from_dir(), reload_openvas(), sighand_segv(), and start_single_task_scan().

pid
static pid_t pid
Definition: nasl_builtin_nmap.c:499
openvas_signal
void(*)(int) openvas_signal(int signum, void(*handler)(int))
Definition: sighand.c:87
make_em_die
void make_em_die(int sig)
Definition: sighand.c:48
print_trace
static void print_trace()
Definition: sighand.c:111
let_em_die
void let_em_die(int pid)
Definition: sighand.c:40