File: ipc.h

package info (click to toggle)
openvas-scanner 23.35.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 22,416 kB
  • sloc: ansic: 41,615; xml: 6,251; pascal: 3,723; yacc: 1,250; sh: 1,068; makefile: 333; sql: 273; javascript: 12
file content (94 lines) | stat: -rw-r--r-- 2,050 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* SPDX-FileCopyrightText: 2023 Greenbone AG
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef MISC_IPC_H
#define MISC_IPC_H

#include <sys/types.h>

enum ipc_protocol
{
  IPC_PIPE
};

enum ipc_relation
{
  IPC_MAIN,
  IPC_CHILD
};

/**
 * ipc_context contains information about an inter process communication
 * process.
 *
 * @param type indicates what type of ipc it represents
 * @param pid is set on ipc_exec_as_process and contains the pid of the child
 * process.
 * @param context contextual data for ipc. Is only used internally.
 */
struct ipc_context
{
  enum ipc_protocol type;
  enum ipc_relation relation;
  unsigned int closed;
  pid_t pid;
  void *context;
};

struct ipc_contexts
{
  int len;
  int cap;
  struct ipc_context *ctxs;
};

typedef void (*ipc_process_func) (struct ipc_context *, void *);

struct ipc_exec_context
{
  // function to be executed before func is executed
  ipc_process_func pre_func;
  // function to be executed
  ipc_process_func func;
  // function to be executed after func is executed
  ipc_process_func post_func;
  void *pre_arg;        // argument for pre_func
  void *func_arg;       // argument for func
  void *post_arg;       // argument for post_func
  void *shared_context; // context to be included in ipc_context
};

// ipc_process_func is a type for the function to be executed.

int
ipc_send (struct ipc_context *context, enum ipc_relation to, const char *msg,
          size_t len);

char *
ipc_retrieve (struct ipc_context *context, enum ipc_relation from);

int
ipc_destroy (struct ipc_context *context);

int
ipc_close (struct ipc_context *context);

struct ipc_context *
ipc_exec_as_process (enum ipc_protocol type,
                     struct ipc_exec_context exec_context);

struct ipc_context *
ipc_init (enum ipc_protocol protocol, enum ipc_relation relation);

struct ipc_contexts *
ipc_contexts_init (int len);

struct ipc_contexts *
ipc_add_context (struct ipc_contexts *ctxs, struct ipc_context *ctx);

int
ipc_destroy_contexts (struct ipc_contexts *ctxs);

#endif