~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/lib/subcmd/sigchain.c

Version: ~ [ linux-6.3-rc3 ] ~ [ linux-6.2.7 ] ~ [ linux-6.1.20 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.103 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.175 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.237 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.278 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.310 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <signal.h>
  3 #include "subcmd-util.h"
  4 #include "sigchain.h"
  5 
  6 #define SIGCHAIN_MAX_SIGNALS 32
  7 
  8 struct sigchain_signal {
  9         sigchain_fun *old;
 10         int n;
 11         int alloc;
 12 };
 13 static struct sigchain_signal signals[SIGCHAIN_MAX_SIGNALS];
 14 
 15 static void check_signum(int sig)
 16 {
 17         if (sig < 1 || sig >= SIGCHAIN_MAX_SIGNALS)
 18                 die("BUG: signal out of range: %d", sig);
 19 }
 20 
 21 static int sigchain_push(int sig, sigchain_fun f)
 22 {
 23         struct sigchain_signal *s = signals + sig;
 24         check_signum(sig);
 25 
 26         ALLOC_GROW(s->old, s->n + 1, s->alloc);
 27         s->old[s->n] = signal(sig, f);
 28         if (s->old[s->n] == SIG_ERR)
 29                 return -1;
 30         s->n++;
 31         return 0;
 32 }
 33 
 34 int sigchain_pop(int sig)
 35 {
 36         struct sigchain_signal *s = signals + sig;
 37         check_signum(sig);
 38         if (s->n < 1)
 39                 return 0;
 40 
 41         if (signal(sig, s->old[s->n - 1]) == SIG_ERR)
 42                 return -1;
 43         s->n--;
 44         return 0;
 45 }
 46 
 47 void sigchain_push_common(sigchain_fun f)
 48 {
 49         sigchain_push(SIGINT, f);
 50         sigchain_push(SIGHUP, f);
 51         sigchain_push(SIGTERM, f);
 52         sigchain_push(SIGQUIT, f);
 53         sigchain_push(SIGPIPE, f);
 54 }
 55 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp