OpenVAS Scanner  7.0.1~git
processes.c File Reference

Creates new threads. More...

#include "processes.h"
#include "sighand.h"
#include <errno.h>
#include <glib.h>
#include <setjmp.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
Include dependency graph for processes.c:

Go to the source code of this file.

Macros

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

Functions

int terminate_process (pid_t pid)
 Send SIGTERM to the pid process. Try to wait the the process. In case of the process has still not change the state, it sends SIGKILL to the process and must be waited later to avoid leaving a zombie process. More...
 
static void init_child_signal_handlers ()
 
pid_t create_process (process_func_t function, void *argument)
 Create a new process (fork). More...
 

Detailed Description

Creates new threads.

Definition in file processes.c.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "sd main"

GLib log domain.

Definition at line 44 of file processes.c.

Function Documentation

◆ create_process()

pid_t create_process ( process_func_t  function,
void *  argument 
)

Create a new process (fork).

Definition at line 97 of file processes.c.

98 {
99  int pid;
100 
101  pid = fork ();
102 
103  if (pid == 0)
104  {
106  srand48 (getpid () + getppid () + (long) time (NULL));
107  (*function) (argument);
108  exit (0);
109  }
110  if (pid < 0)
111  g_error ("Error : could not fork ! Error : %s", strerror (errno));
112  return pid;
113 }

References init_child_signal_handlers(), and pid.

Referenced by attack_network(), nasl_plugin_launch(), and plugins_init().

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

◆ init_child_signal_handlers()

static void init_child_signal_handlers ( )
static

Definition at line 82 of file processes.c.

83 {
84  /* SIGHUP is only for reloading main scanner process. */
85  openvas_signal (SIGHUP, SIG_IGN);
86  openvas_signal (SIGTERM, make_em_die);
87  openvas_signal (SIGINT, make_em_die);
88  openvas_signal (SIGQUIT, make_em_die);
89  openvas_signal (SIGSEGV, sighand_segv);
90  openvas_signal (SIGPIPE, SIG_IGN);
91 }

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

Referenced by create_process().

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

◆ terminate_process()

int terminate_process ( pid_t  pid)

Send SIGTERM to the pid process. Try to wait the the process. In case of the process has still not change the state, it sends SIGKILL to the process and must be waited later to avoid leaving a zombie process.

Parameters
[in]pidProcess id to terminate.
Returns
0 on success, -1 if the process was waited but not changed the state

Definition at line 58 of file processes.c.

59 {
60  int ret;
61 
62  if (pid == 0)
63  return 0;
64 
65  ret = kill (pid, SIGTERM);
66 
67  if (ret == 0)
68  {
69  usleep (1000);
70 
71  if (waitpid (pid, NULL, WNOHANG) >= 0)
72  {
73  kill (pid, SIGKILL);
74  return -1;
75  }
76  }
77 
78  return 0;
79 }

References pid.

Referenced by pluginlaunch_stop(), and update_running_processes().

Here is the caller graph for this function:
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
sighand_segv
void sighand_segv(int given_signal)
Definition: sighand.c:130
init_child_signal_handlers
static void init_child_signal_handlers()
Definition: processes.c:82