GNUnet  0.19.0
Signal library

Manage signal handlers. More...

Collaboration diagram for Signal library:

Typedefs

typedef void(* GNUNET_SIGNAL_Handler) (void)
 A signal handler. More...
 

Functions

struct GNUNET_SIGNAL_ContextGNUNET_SIGNAL_handler_install (int signal, GNUNET_SIGNAL_Handler handler)
 Install a signal handler that will be run if the given signal is received. More...
 
void GNUNET_SIGNAL_handler_uninstall (struct GNUNET_SIGNAL_Context *ctx)
 Uninstall a previously installed signal handler. More...
 
void GNUNET_SIGNAL_raise (const int sig)
 Raise the given signal by calling the installed signal handlers. More...
 

Detailed Description

Manage signal handlers.

Typedef Documentation

◆ GNUNET_SIGNAL_Handler

typedef void(* GNUNET_SIGNAL_Handler) (void)

A signal handler.

Since different OSes have different signatures for their handlers, the API only gives the most restrictive signature – no arguments, no return value. Note that this will work even if the OS expects a function with arguments. However, the implementation must guarantee that this handler is not called for signals other than the one that it has been registered for.

Definition at line 66 of file gnunet_signal_lib.h.

Function Documentation

◆ GNUNET_SIGNAL_handler_install()

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.

Parameters
signalthe number of the signal
handlerthe function to call
Returns
context that can be used to restore, NULL on error

Definition at line 52 of file signal.c.

53 {
54  struct GNUNET_SIGNAL_Context *ret;
55 
56  struct sigaction sig;
57 
59  ret->sig = signum;
60  ret->method = handler;
61 
62  memset (&sig, 0, sizeof(sig));
63  sig.sa_handler = (void *) handler;
64  sigemptyset (&sig.sa_mask);
65 #ifdef SA_INTERRUPT
66  sig.sa_flags = SA_INTERRUPT; /* SunOS */
67 #else
68  sig.sa_flags = SA_RESTART;
69 #endif
70  sigaction (signum, &sig, &ret->oldsig);
71 
73  return ret;
74 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_SIGNAL_Context * sc_head
Definition: signal.c:47
static struct GNUNET_SIGNAL_Context * sc_tail
Definition: signal.c:49

References GNUNET_CONTAINER_DLL_insert_tail, GNUNET_new, gnunet_testing::handler, ret, sc_head, and sc_tail.

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

Here is the caller graph for this function:

◆ GNUNET_SIGNAL_handler_uninstall()

void GNUNET_SIGNAL_handler_uninstall ( struct GNUNET_SIGNAL_Context ctx)

Uninstall a previously installed signal handler.

Parameters
ctxcontext that was returned when the signal handler was installed

Definition at line 78 of file signal.c.

79 {
80  struct sigaction sig;
81 
82  sigemptyset (&sig.sa_mask);
83  sigaction (ctx->sig, &ctx->oldsig, &sig);
84 
86  GNUNET_free (ctx);
87 }
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.

References ctx, GNUNET_CONTAINER_DLL_remove, GNUNET_free, sc_head, and sc_tail.

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

Here is the caller graph for this function:

◆ GNUNET_SIGNAL_raise()

void GNUNET_SIGNAL_raise ( const int  sig)

Raise the given signal by calling the installed signal handlers.

This will not use the raise() system call but only calls the handlers registered through GNUNET_SIGNAL_handler_install().

Parameters
sigthe signal to raise

Definition at line 98 of file signal.c.

99 {
100  struct GNUNET_SIGNAL_Context *ctx;
101 
102  for (ctx = sc_head; NULL != ctx; ctx = ctx->next)
103  {
104  if (sig != ctx->sig)
105  continue;
106  if (NULL == ctx->method)
107  continue;
108  ctx->method ();
109  }
110 }

References ctx, sc_head, and GNUNET_SIGNAL_Context::sig.

Referenced by parent_control_handler().

Here is the caller graph for this function: