OpenVAS Scanner 23.32.3
ipc_pipe.c File Reference
#include "ipc_pipe.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
Include dependency graph for ipc_pipe.c:

Go to the source code of this file.

Macros

#define IPC_MAX_BUFFER   4096

Functions

int ipc_pipe_send (struct ipc_pipe_context *context, const char *msg, int len)
 sends given msg via the given context. Do not use this method directly, use ipc_send of ipc.h instead.
char * ipc_pipe_retrieve (struct ipc_pipe_context *context)
 retrieves message from the given context. Do not use this method directly, use ipc_retrieve of ipc.h instead.
int ipc_pipe_close (struct ipc_pipe_context *context)
 closes given context. Do not use this method directly, use ipc_close of ipc.h instead.
int ipc_pipe_destroy (struct ipc_pipe_context *context)
 destroys given context. Do not use this method directly, use ipc_destroy of ipc.h instead.
struct ipc_pipe_contextipc_init_pipe (void)
 initializes a new context. Do not use this method directly, use ipc_init of ipc.h instead.

Macro Definition Documentation

◆ IPC_MAX_BUFFER

#define IPC_MAX_BUFFER   4096

Definition at line 17 of file ipc_pipe.c.

Referenced by ipc_pipe_retrieve().

Function Documentation

◆ ipc_init_pipe()

struct ipc_pipe_context * ipc_init_pipe ( void )

initializes a new context. Do not use this method directly, use ipc_init of ipc.h instead.

Returns
a heap allocated ipc_pipe_context or NULL on failure.

Definition at line 132 of file ipc_pipe.c.

133{
134 struct ipc_pipe_context *pc = NULL;
135 if ((pc = calloc (1, sizeof (*pc))) == NULL)
136 goto error;
137 if (pipe (pc->fd) == -1)
138 {
139 goto error;
140 }
141 return pc;
142error:
143 if (pc != NULL)
144 free (pc);
145 return NULL;
146}
void free(void *)

References ipc_pipe_context::fd, and free().

Referenced by ipc_init().

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

◆ ipc_pipe_close()

int ipc_pipe_close ( struct ipc_pipe_context * context)

closes given context. Do not use this method directly, use ipc_close of ipc.h instead.

Parameters
contextthe ipc_pipe_context to be closed.
Returns
0 on success, -1 on failure.

Definition at line 85 of file ipc_pipe.c.

86{
87 int rc = 0;
88 if (context == NULL)
89 {
90 rc = -1;
91 goto exit;
92 }
93 if ((rc = close (context->fd[0])) < 0)
94 goto exit;
95 if ((rc = close (context->fd[1])) < 0)
96 goto exit;
97exit:
98 return rc;
99}

References ipc_pipe_context::fd.

Referenced by ipc_close(), and ipc_pipe_destroy().

Here is the caller graph for this function:

◆ ipc_pipe_destroy()

int ipc_pipe_destroy ( struct ipc_pipe_context * context)

destroys given context. Do not use this method directly, use ipc_destroy of ipc.h instead.

Parameters
contextthe ipc_pipe_context to be destroyed.
Returns
0 on success, -1 on failure.

Definition at line 110 of file ipc_pipe.c.

111{
112 int rc = 0;
113 if (context == NULL)
114 {
115 rc = -1;
116 goto exit;
117 }
118 if ((rc = ipc_pipe_close (context)) < 0)
119 goto exit;
120 free (context);
121exit:
122 return rc;
123}
int ipc_pipe_close(struct ipc_pipe_context *context)
closes given context. Do not use this method directly, use ipc_close of ipc.h instead.
Definition ipc_pipe.c:85

References free(), and ipc_pipe_close().

Referenced by ipc_destroy().

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

◆ ipc_pipe_retrieve()

char * ipc_pipe_retrieve ( struct ipc_pipe_context * context)

retrieves message from the given context. Do not use this method directly, use ipc_retrieve of ipc.h instead.

Parameters
contextthe ipc_pipe_context to be used; must be previously initialized via ipc_pipe_init.
Returns
a heap allocated char array or NULL on failure.

Definition at line 50 of file ipc_pipe.c.

51{
52 char *result = NULL;
53 int rfd, pf;
54 rfd = context->fd[0];
55 pf = fcntl (rfd, F_GETFL, 0);
56 if (pf < 0 && errno != EBADF)
57 // fd is closed or invalid; we assume closed
58 return NULL;
59 fcntl (rfd, F_SETFL, pf | O_NONBLOCK);
60 if ((result = calloc (1, IPC_MAX_BUFFER)) == NULL)
61 return NULL;
62
63 if (read (rfd, result, IPC_MAX_BUFFER) > 0)
64 {
65 return result;
66 }
67 else
68 {
69 free (result);
70 // if temporary unavailable or not a closed descriptor don't
71 // print an error.
72 return NULL;
73 }
74}
#define IPC_MAX_BUFFER
Definition ipc_pipe.c:17

References ipc_pipe_context::fd, free(), and IPC_MAX_BUFFER.

Referenced by ipc_retrieve().

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

◆ ipc_pipe_send()

int ipc_pipe_send ( struct ipc_pipe_context * context,
const char * msg,
int len )

sends given msg via the given context. Do not use this method directly, use ipc_send of ipc.h instead.

Parameters
contextthe ipc_pipe_context to be used; must be previously initialized via ipc_pipe_init.
msgthe message to send
lenthe length of msg
Returns
bytes written, 1 on write error

Definition at line 32 of file ipc_pipe.c.

33{
34 int wfd, wr;
35 wfd = context->fd[1];
36 wr = write (wfd, msg, len);
37 return wr;
38}
uint8_t len

References ipc_pipe_context::fd, and len.

Referenced by ipc_send().

Here is the caller graph for this function: