21#include <gvm/base/logging.h>
22#include <gvm/util/mqtt.h>
35#define G_LOG_DOMAIN "sd main"
49 int freed = 0, i, status;
53 g_debug (
"%s: checking %d ipc.", __func__,
ipcc->len);
54 for (i = 0; i <
ipcc->len; i++)
56 if (
ipcc->ctxs[i].closed)
60 pid = waitpid (
ipcc->ctxs[i].pid, &status, WNOHANG);
63 && (WIFEXITED (status) || WIFSTOPPED (status)
64 || WIFSIGNALED (status))))
100 if (waitpid (
pid, NULL, WNOHANG))
118 for (
int i = 0; i <
ipcc->len; i++)
120 if (!
ipcc->ctxs[i].closed)
145 g_debug (
"%s: called", __func__);
151 srand48 (getpid () + getppid () + (
long) time (NULL));
153 g_debug (
"%s: exit", __func__);
161 g_debug (
"%s: called", __func__);
170 for (
int i = 0; i <
ipcc->len; i++)
172 if (
ipcc->ctxs[i].closed == 1)
178 ipcc->ctxs[i].closed = 0;
215 if (errno == EMFILE || errno == EAGAIN)
218 "%s: could not fork: %s (%d) retrying after trying to close fd.",
219 __func__, strerror (errno), errno);
222 g_warning (
"%s: could not fork: %s (%d)", __func__, strerror (errno),
227 child_pid = pctx->
pid;
int init_sentry(void)
Init sentry.
debug_utils.c headerfile.
int ipc_close(struct ipc_context *context)
closes given context
struct ipc_context * ipc_exec_as_process(enum ipc_protocol type, struct ipc_exec_context exec_ctx)
runs given functions with the given protocol type.
struct ipc_contexts * ipc_contexts_init(int cap)
initializes ipc_contexts with a given preallocated capacity.
struct ipc_contexts * ipc_add_context(struct ipc_contexts *ctxs, struct ipc_context *ctx)
adds a given context to contexts
int ipc_destroy_contexts(struct ipc_contexts *ctxs)
destroys given contexts
void(* ipc_process_func)(struct ipc_context *, void *)
Header file to cache main_kb.
const struct ipc_contexts * procs_get_ipc_contexts(void)
returns ipc_contexts.
static void post_fn_call(struct ipc_context *ctx, void *args)
int procs_cleanup_children(void)
iterates through ipcc and verify if a child is stopped or killed to free the file handler.
static void reuse_or_add_context(struct ipc_context *ctx)
static struct ipc_contexts * ipcc
void procs_terminate_childs(void)
This function terminates all processes spawned with create_process. Calls terminate_child for each pr...
int terminate_process(pid_t pid)
Terminates a given process. If termination does not work, the process will get killed....
static void init_child_signal_handlers(void)
static void pre_fn_call(struct ipc_context *ctx, void *args)
static void clean_procs(void)
Cleans the process list and frees memory. This will not terminate child processes....
pid_t create_ipc_process(ipc_process_func func, void *args)
initializes a communication channels and calls a function with a new process
void(*)(int) openvas_signal(int signum, void(*handler)(int))
void sighand_segv(int given_signal)
void make_em_die(int sig)
headerfile for sighand.c.
enum ipc_relation relation
ipc_process_func pre_func
ipc_process_func post_func