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

References _, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_ERROR_TYPE_WARNING, GNUNET_new, GNUNET_SIGCHLD, LOG, and ret.

Referenced by GNUNET_SCHEDULER_driver_init(), and main().

60 {
61  struct GNUNET_SIGNAL_Context *ret;
62 
63 #ifndef MINGW
64  struct sigaction sig;
65 #endif
66 
67  ret = GNUNET_new (struct GNUNET_SIGNAL_Context);
68  ret->sig = signum;
69  ret->method = handler;
70 #ifndef MINGW
71  memset (&sig, 0, sizeof (sig));
72  sig.sa_handler = (void *) handler;
73  sigemptyset (&sig.sa_mask);
74 #ifdef SA_INTERRUPT
75  sig.sa_flags = SA_INTERRUPT; /* SunOS */
76 #else
77  sig.sa_flags = SA_RESTART;
78 #endif
79  sigaction (signum, &sig, &ret->oldsig);
80 #else
81  if (signum == GNUNET_SIGCHLD)
82  w32_sigchld_handler = handler;
83  else
84  {
85  __p_sig_fn_t sigret = signal (signum, (__p_sig_fn_t) handler);
86 
87  if (sigret == SIG_ERR)
88  {
89  LOG (GNUNET_ERROR_TYPE_WARNING, _("signal (%d, %p) returned %d.\n"),
90  signum, handler, sigret);
91  }
92  }
93 #endif
95  return ret;
96 }
#define GNUNET_SIGCHLD
Definition: platform.h:46
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct GNUNET_SIGNAL_Context * sc_head
Definition: signal.c:49
#define LOG(kind,...)
Definition: signal.c:30
#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:51
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 99 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().

100 {
101 #ifndef MINGW
102  struct sigaction sig;
103 
104  sigemptyset (&sig.sa_mask);
105  sigaction (ctx->sig, &ctx->oldsig, &sig);
106 #endif
108  GNUNET_free (ctx);
109 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct GNUNET_SIGNAL_Context * sc_head
Definition: signal.c:49
static struct GNUNET_SIGNAL_Context * sc_tail
Definition: signal.c:51
struct sigaction oldsig
Definition: signal.c:45
#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 120 of file signal.c.

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

Referenced by parent_control_handler().

121 {
122  struct GNUNET_SIGNAL_Context *ctx;
123 
124  for (ctx = sc_head; NULL != ctx; ctx = ctx->next)
125  {
126  if (sig != ctx->sig)
127  continue;
128  if (NULL == ctx->method)
129  continue;
130  ctx->method ();
131  }
132 }
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static struct GNUNET_SIGNAL_Context * sc_head
Definition: signal.c:49
GNUNET_SIGNAL_Handler method
Definition: signal.c:42
struct GNUNET_SIGNAL_Context * next
Definition: signal.c:36
Here is the caller graph for this function: