GNUnet  0.11.x
Typedefs | Functions
Signal library

Manage signal handlers. More...

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 58 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 51 of file signal.c.

52 {
53  struct GNUNET_SIGNAL_Context *ret;
54 
55  struct sigaction sig;
56 
58  ret->sig = signum;
59  ret->method = handler;
60 
61  memset (&sig, 0, sizeof(sig));
62  sig.sa_handler = (void *) handler;
63  sigemptyset (&sig.sa_mask);
64 #ifdef SA_INTERRUPT
65  sig.sa_flags = SA_INTERRUPT; /* SunOS */
66 #else
67  sig.sa_flags = SA_RESTART;
68 #endif
69  sigaction (signum, &sig, &ret->oldsig);
70 
72  return ret;
73 }
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:46
static struct GNUNET_SIGNAL_Context * sc_tail
Definition: signal.c:48

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(), gnunet_uri(), 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 77 of file signal.c.

78 {
79  struct sigaction sig;
80 
81  sigemptyset (&sig.sa_mask);
82  sigaction (ctx->sig, &ctx->oldsig, &sig);
83 
85  GNUNET_free (ctx);
86 }
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(), main(), and maint_child_death().

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 97 of file signal.c.

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

References ctx, sc_head, and GNUNET_SIGNAL_Context::sig.

Referenced by parent_control_handler().

Here is the caller graph for this function: