GNUnet  0.10.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 hander. 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 59 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 50 of file signal.c.

References GNUNET_CONTAINER_DLL_insert_tail, GNUNET_new, and ret.

Referenced by GNUNET_SCHEDULER_driver_init(), and main().

51 {
52  struct GNUNET_SIGNAL_Context *ret;
53 
54  struct sigaction sig;
55 
56  ret = GNUNET_new(struct GNUNET_SIGNAL_Context);
57  ret->sig = signum;
58  ret->method = handler;
59 
60  memset(&sig, 0, sizeof(sig));
61  sig.sa_handler = (void *)handler;
62  sigemptyset(&sig.sa_mask);
63 #ifdef SA_INTERRUPT
64  sig.sa_flags = SA_INTERRUPT; /* SunOS */
65 #else
66  sig.sa_flags = SA_RESTART;
67 #endif
68  sigaction(signum, &sig, &ret->oldsig);
69 
71  return ret;
72 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
static struct GNUNET_SIGNAL_Context * sc_head
Definition: signal.c:45
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
static struct GNUNET_SIGNAL_Context * sc_tail
Definition: signal.c:47
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 hander.

Parameters
ctxcontext that was returned when the signal handler was installed

Definition at line 75 of file signal.c.

References GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_SIGNAL_Context::oldsig, and GNUNET_SIGNAL_Context::sig.

Referenced by GNUNET_SCHEDULER_driver_done(), and main().

76 {
77  struct sigaction sig;
78 
79  sigemptyset(&sig.sa_mask);
80  sigaction(ctx->sig, &ctx->oldsig, &sig);
81 
83  GNUNET_free(ctx);
84 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct GNUNET_SIGNAL_Context * sc_head
Definition: signal.c:45
static struct GNUNET_SIGNAL_Context * sc_tail
Definition: signal.c:47
struct sigaction oldsig
Definition: signal.c:42
#define GNUNET_free(ptr)
Wrapper around free.
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 95 of file signal.c.

References ctx, GNUNET_SIGNAL_Context::method, GNUNET_SIGNAL_Context::next, and GNUNET_SIGNAL_Context::sig.

Referenced by parent_control_handler().

96 {
97  struct GNUNET_SIGNAL_Context *ctx;
98 
99  for (ctx = sc_head; NULL != ctx; ctx = ctx->next)
100  {
101  if (sig != ctx->sig)
102  continue;
103  if (NULL == ctx->method)
104  continue;
105  ctx->method();
106  }
107 }
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static struct GNUNET_SIGNAL_Context * sc_head
Definition: signal.c:45
GNUNET_SIGNAL_Handler method
Definition: signal.c:40
struct GNUNET_SIGNAL_Context * next
Definition: signal.c:34
Here is the caller graph for this function: