GNUnet 0.21.1
child_management.c File Reference

Handling of child processes in GNUnet. More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for child_management.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_ChildWaitHandle
 Struct which defines a Child Wait handle. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log (kind, __VA_ARGS__)
 Generic logging shortcut. More...
 

Functions

static void maint_child_death (void *cls)
 Task triggered whenever we receive a SIGCHLD (child process died) or when user presses CTRL-C. More...
 
static void sighandler_child_death (void)
 Signal handler called for SIGCHLD. More...
 
static void child_management_start (void)
 Initializing the signal pipe for child handling. More...
 
static void child_management_done (void)
 Clean up. More...
 
struct GNUNET_ChildWaitHandleGNUNET_wait_child (struct GNUNET_OS_Process *proc, GNUNET_ChildCompletedCallback cb, void *cb_cls)
 Starts the handling of the child processes. More...
 
void GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh)
 Stop waiting on this child. More...
 

Variables

static struct GNUNET_DISK_PipeHandlesigpipe
 Pipe used to communicate shutdown via signal. More...
 
static struct GNUNET_SIGNAL_Contextshc_chld
 
static struct GNUNET_SCHEDULER_Tasksig_task
 
static struct GNUNET_ChildWaitHandlecwh_head
 
static struct GNUNET_ChildWaitHandlecwh_tail
 

Detailed Description

Handling of child processes in GNUnet.

Author
Christian Grothoff (ANASTASIS)
Dominik Meister (ANASTASIS)
t3sserakt

Definition in file child_management.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log (kind, __VA_ARGS__)

Generic logging shortcut.

Definition at line 35 of file child_management.c.

Function Documentation

◆ maint_child_death()

static void maint_child_death ( void *  cls)
static

Task triggered whenever we receive a SIGCHLD (child process died) or when user presses CTRL-C.

Parameters
clsclosure, NULL

Definition at line 86 of file child_management.c.

87{
88 char buf[16];
89 const struct GNUNET_DISK_FileHandle *pr;
90 struct GNUNET_ChildWaitHandle *nxt;
91
92 (void) cls;
93 sig_task = NULL;
94 /* drain pipe */
98 (void) GNUNET_DISK_file_read (pr,
99 buf,
100 sizeof(buf));
101
102 /* find applicable processes that exited */
103 for (struct GNUNET_ChildWaitHandle *cwh = cwh_head;
104 NULL != cwh;
105 cwh = nxt)
106 {
108 long unsigned int exit_code = 0;
109
110 nxt = cwh->next;
111 if (GNUNET_OK ==
112 GNUNET_OS_process_status (cwh->proc,
113 &type,
114 &exit_code))
115 {
117 cwh_tail,
118 cwh);
119 cwh->cb (cwh->cb_cls,
120 type,
121 exit_code);
122 GNUNET_free (cwh);
123 }
124 }
125 if (NULL == cwh_head)
126 return;
127 /* wait for more */
133 NULL);
134}
static struct GNUNET_ChildWaitHandle * cwh_tail
static void maint_child_death(void *cls)
Task triggered whenever we receive a SIGCHLD (child process died) or when user presses CTRL-C.
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
static struct GNUNET_ChildWaitHandle * cwh_head
static struct GNUNET_SCHEDULER_Task * sig_task
static uint32_t type
Type string converted to DNS type value.
static int exit_code
Global exit code.
Definition: gnunet-qr.c:43
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition: disk.c:1617
enum GNUNET_GenericReturnValue GNUNET_DISK_handle_invalid(const struct GNUNET_DISK_FileHandle *h)
Checks whether a handle is invalid.
Definition: disk.c:185
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:622
@ GNUNET_DISK_PIPE_END_READ
The reading-end of a pipe.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
@ GNUNET_OK
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_OS_ProcessStatusType
Process status types.
enum GNUNET_GenericReturnValue GNUNET_OS_process_status(struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Retrieve the status of a process.
Definition: os_priority.c:859
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1662
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Struct which defines a Child Wait handle.
struct GNUNET_ChildWaitHandle * next
Linked list to the next child.
Handle used to access files (and pipes).

References cwh_head, cwh_tail, exit_code, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_DISK_file_read(), GNUNET_DISK_handle_invalid(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_pipe_handle(), GNUNET_free, GNUNET_OK, GNUNET_OS_process_status(), GNUNET_SCHEDULER_add_read_file(), GNUNET_TIME_UNIT_FOREVER_REL, maint_child_death(), GNUNET_ChildWaitHandle::next, sig_task, sigpipe, and type.

Referenced by GNUNET_wait_child(), and maint_child_death().

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

◆ sighandler_child_death()

static void sighandler_child_death ( void  )
static

Signal handler called for SIGCHLD.

Triggers the respective handler by writing to the trigger pipe.

Definition at line 142 of file child_management.c.

143{
144 static char c;
145 int old_errno = errno; /* back-up errno */
146
148 1 ==
151 &c,
152 sizeof(c)));
153 errno = old_errno; /* restore errno */
154}
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:686
@ GNUNET_DISK_PIPE_END_WRITE
The writing-end of a pipe.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

References GNUNET_break, GNUNET_DISK_file_write(), GNUNET_DISK_PIPE_END_WRITE, GNUNET_DISK_pipe_handle(), and sigpipe.

Referenced by child_management_start(), and GNUNET_wait_child().

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

◆ child_management_start()

static void child_management_start ( void  )
static

Initializing the signal pipe for child handling.

Definition at line 161 of file child_management.c.

162{
164 "Trying to start child management.\n");
165 if (NULL != sigpipe)
166 return; /* already initialized */
168 GNUNET_assert (sigpipe != NULL);
169 shc_chld =
173 "Child management started.\n");
174}
static void sighandler_child_death(void)
Signal handler called for SIGCHLD.
static struct GNUNET_SIGNAL_Context * shc_chld
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition: disk.c:1444
@ GNUNET_DISK_PF_NONE
No special options, use non-blocking read/write operations.
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_INFO
struct GNUNET_SIGNAL_Context * GNUNET_SIGNAL_handler_install(int signal, GNUNET_SIGNAL_Handler handler)
Install a signal handler that will be run if the given signal is received.
Definition: signal.c:52
#define GNUNET_SIGCHLD
Definition: platform.h:42

References GNUNET_assert, GNUNET_DISK_PF_NONE, GNUNET_DISK_pipe(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_SIGCHLD, GNUNET_SIGNAL_handler_install(), shc_chld, sighandler_child_death(), and sigpipe.

Referenced by GNUNET_wait_child().

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

◆ child_management_done()

static void child_management_done ( void  )
static

Clean up.

Definition at line 181 of file child_management.c.

182{
183 if (NULL != sig_task)
184 {
186 sig_task = NULL;
187 }
189 shc_chld = NULL;
191 sigpipe = NULL;
193 "Child management stopped.\n");
194}
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1587
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
Uninstall a previously installed signal handler.
Definition: signal.c:78

References GNUNET_DISK_pipe_close(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_SIGNAL_handler_uninstall(), shc_chld, sig_task, and sigpipe.

Referenced by GNUNET_wait_child_cancel().

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

Variable Documentation

◆ sigpipe

struct GNUNET_DISK_PipeHandle* sigpipe
static

Pipe used to communicate shutdown via signal.

Definition at line 69 of file child_management.c.

Referenced by child_management_done(), child_management_start(), GNUNET_wait_child(), maint_child_death(), and sighandler_child_death().

◆ shc_chld

struct GNUNET_SIGNAL_Context* shc_chld
static

Definition at line 71 of file child_management.c.

Referenced by child_management_done(), child_management_start(), and main().

◆ sig_task

struct GNUNET_SCHEDULER_Task* sig_task
static

Definition at line 73 of file child_management.c.

Referenced by child_management_done(), GNUNET_wait_child(), and maint_child_death().

◆ cwh_head

struct GNUNET_ChildWaitHandle* cwh_head
static

◆ cwh_tail

struct GNUNET_ChildWaitHandle* cwh_tail
static