OpenVAS Scanner  22.7.9
sighand.c File Reference

Provides signal handling functions. More...

#include "sighand.h"
#include "debug_utils.h"
#include "processes.h"
#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 (int sig)
 
static void print_trace (void)
 
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 28 of file sighand.c.

Function Documentation

◆ let_em_die()

void let_em_die ( int  pid)

Definition at line 32 of file sighand.c.

33 {
34  int status;
35 
36  waitpid (pid, &status, WNOHANG);
37 }

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 40 of file sighand.c.

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

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 ( void  )
static

Definition at line 104 of file sighand.c.

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

Referenced by sighand_segv().

Here is the caller graph for this function:

◆ sighand_chld()

void sighand_chld ( int  sig)

Definition at line 95 of file sighand.c.

96 {
97  (void) sig;
98  // if we call multiple times waitpid it will disturb the attack loop.
99  // therefore we cannot cleanup multiple ipc here
100  waitpid (-1, NULL, WNOHANG);
101 }

Referenced by init_signal_handlers().

Here is the caller graph for this function:

◆ sighand_segv()

void sighand_segv ( int  given_signal)

Definition at line 123 of file sighand.c.

124 {
125  print_trace ();
126  make_em_die (SIGTERM);
127  gvm_close_sentry ();
128  /* Raise signal again, to exit with the correct return value,
129  * and to enable core dumping. */
130  openvas_signal (given_signal, SIG_DFL);
131  raise (given_signal);
132 }

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 79 of file sighand.c.

80 {
81  struct sigaction saNew, saOld;
82 
83  /* Init new handler */
84  sigfillset (&saNew.sa_mask);
85  sigdelset (&saNew.sa_mask, SIGALRM); /* make sleep() work */
86 
87  saNew.sa_flags = 0;
88  saNew.sa_handler = handler;
89 
90  sigaction (signum, &saNew, &saOld);
91  return saOld.sa_handler;
92 }

Referenced by attack_network(), init_child_signal_handlers(), init_signal_handlers(), plugins_reload_from_dir(), and sighand_segv().

openvas_signal
void(*)(int) openvas_signal(int signum, void(*handler)(int))
Definition: sighand.c:79
make_em_die
void make_em_die(int sig)
Definition: sighand.c:40
pid
static pid_t pid
Definition: nasl_cmd_exec.c:39
print_trace
static void print_trace(void)
Definition: sighand.c:104
let_em_die
void let_em_die(int pid)
Definition: sighand.c:32