OpenVAS Scanner  5.1.3
processes.c File Reference
#include <signal.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <setjmp.h>
#include "processes.h"
#include "sighand.h"
#include "log.h"
Include dependency graph for processes.c:

Go to the source code of this file.

Functions

int terminate_process (pid_t pid)
 
pid_t create_process (process_func_t function, void *argument)
 Create a new process (fork). More...
 

Function Documentation

◆ create_process()

pid_t create_process ( process_func_t  function,
void *  argument 
)

Create a new process (fork).

Definition at line 77 of file processes.c.

Referenced by nasl_plugin_launch().

78 {
79  int pid;
80 
81  pid = fork ();
82 
83  if (pid == 0)
84  {
85  init_child_signal_handlers ();
86  srand48 (getpid () + getppid () + (long) time (NULL));
87  (*function) (argument);
88  exit (0);
89  }
90  if (pid < 0)
91  log_write ("Error : could not fork ! Error : %s", strerror (errno));
92  return pid;
93 }
void log_write(const char *str,...)
Write into the logfile / syslog.
Definition: log.c:140
Here is the caller graph for this function:

◆ terminate_process()

int terminate_process ( pid_t  pid)

Definition at line 43 of file processes.c.

Referenced by loading_handler_stop().

44 {
45  int ret;
46 
47  if (pid <= 0)
48  return 0;
49 
50  ret = kill (pid, SIGTERM);
51 
52  if (ret == 0)
53  {
54  usleep (1000);
55  if (waitpid (pid, NULL, WNOHANG) >= 0)
56  kill (pid, SIGKILL);
57  }
58  return -1;
59 }
Here is the caller graph for this function: