summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaul <paul>2004-01-19 21:31:15 +0000
committerpaul <paul>2004-01-19 21:31:15 +0000
commit2d75d05218b76230bbd608cab8d08a5f47d77056 (patch)
tree7087570a7dbb8b650349b98a8f1963dfdcedceb1
parent9a76e2ddb6c4dc303ce7ed937c0cfa9430c3ed27 (diff)
2004-01-19 Paul Jakma <paul@dishone.st>
* tests/test-sig.c: New file, regression test for sigevents. * lib/Makefile.am: add sigevent.{c,h} * (isis|rip|ripng|ospf|ospf6|bgp)d/\1_main.c: modify for sigevents. * zebra/main.c: ditto.
-rw-r--r--ChangeLog7
-rw-r--r--bgpd/bgp_main.c64
-rw-r--r--isisd/isis_main.c74
-rw-r--r--lib/Makefile.am5
-rw-r--r--ospfd/ospf_main.c69
-rw-r--r--ripd/rip_main.c55
-rw-r--r--ripngd/ripng_main.c55
-rw-r--r--zebra/main.c55
8 files changed, 138 insertions, 246 deletions
diff --git a/ChangeLog b/ChangeLog
index ab9b67cb..c2493284 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-01-19 Paul Jakma <paul@dishone.st>
+
+ * tests/test-sig.c: New file, regression test for sigevents.
+ * lib/Makefile.am: add sigevent.{c,h}
+ * (isis|rip|ripng|ospf|ospf6|bgp)d/\1_main.c: modify for sigevents.
+ * zebra/main.c: ditto.
+
2004-01-10 Paul Jakma <paul@dishone.st>
* Makefile.am: redhat/ is a dist subdir too.
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
index 04729229..effddddb 100644
--- a/bgpd/bgp_main.c
+++ b/bgpd/bgp_main.c
@@ -30,6 +30,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#include "prefix.h"
#include "log.h"
#include "privs.h"
+#include "sigevent.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_attr.h"
@@ -52,6 +53,27 @@ struct option longopts[] =
{ 0 }
};
+/* signal definitions */
+void sighup (void);
+void sigint (void);
+void sigusr1 (void);
+
+struct quagga_signal_t bgp_signals[] =
+{
+ {
+ .signal = SIGHUP,
+ .handler = &sighup,
+ },
+ {
+ .signal = SIGUSR1,
+ .handler = &sigusr1,
+ },
+ {
+ .signal = SIGINT,
+ .handler = &sigint,
+ },
+};
+
/* Configuration file and directory. */
char config_current[] = BGP_DEFAULT_CONFIG;
char config_default[] = SYSCONFDIR BGP_DEFAULT_CONFIG;
@@ -123,7 +145,7 @@ Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
/* SIGHUP handler. */
void
-sighup (int sig)
+sighup (void)
{
zlog (NULL, LOG_INFO, "SIGHUP received");
@@ -143,7 +165,7 @@ sighup (int sig)
/* SIGINT handler. */
void
-sigint (int sig)
+sigint (void)
{
zlog (NULL, LOG_INFO, "Terminating on signal");
@@ -155,44 +177,10 @@ sigint (int sig)
/* SIGUSR1 handler. */
void
-sigusr1 (int sig)
+sigusr1 (void)
{
zlog_rotate (NULL);
}
-
-/* Signale wrapper. */
-RETSIGTYPE *
-signal_set (int signo, void (*func)(int))
-{
- int ret;
- struct sigaction sig;
- struct sigaction osig;
-
- sig.sa_handler = func;
- sigemptyset (&sig.sa_mask);
- sig.sa_flags = 0;
-#ifdef SA_RESTART
- sig.sa_flags |= SA_RESTART;
-#endif /* SA_RESTART */
-
- ret = sigaction (signo, &sig, &osig);
-
- if (ret < 0)
- return (SIG_ERR);
- else
- return (osig.sa_handler);
-}
-
-/* Initialization of signal handles. */
-void
-signal_init ()
-{
- signal_set (SIGHUP, sighup);
- signal_set (SIGINT, sigint);
- signal_set (SIGTERM, sigint);
- signal_set (SIGPIPE, SIG_IGN);
- signal_set (SIGUSR1, sigusr1);
-}
/* Main routine of bgpd. Treatment of argument and start bgp finite
state machine is handled at here. */
@@ -282,7 +270,7 @@ main (int argc, char **argv)
/* Initializations. */
srand (time (NULL));
- signal_init ();
+ signal_init (master, Q_SIGC(bgp_signals), bgp_signals);
zprivs_init (&bgpd_privs);
cmd_init (1);
vty_init (master);
diff --git a/isisd/isis_main.c b/isisd/isis_main.c
index 56813503..51249c5d 100644
--- a/isisd/isis_main.c
+++ b/isisd/isis_main.c
@@ -34,6 +34,7 @@
#include "stream.h"
#include "if.h"
#include "privs.h"
+#include "sigevent.h"
#include "isisd/dict.h"
#include "include-netbsd/iso.h"
@@ -148,8 +149,9 @@ terminate (int i)
/*
* Signal handlers
*/
+
void
-sighup (int sig)
+sighup (void)
{
zlog_info ("SIGHUP received");
reload ();
@@ -158,7 +160,7 @@ sighup (int sig)
}
void
-sigint (int sig)
+sigint (void)
{
zlog_info ("SIGINT received");
terminate (0);
@@ -167,62 +169,38 @@ sigint (int sig)
}
void
-sigterm (int sig)
+sigterm (void)
{
zlog_info ("SIGTERM received");
terminate (0);
}
void
-sigusr1 (int sig)
+sigusr1 (void)
{
zlog_info ("SIGUSR1 received");
zlog_rotate (NULL);
}
-/*
- * Signal wrapper.
- */
-RETSIGTYPE *
-signal_set (int signo, void (*func)(int))
-{
- int ret;
- struct sigaction sig;
- struct sigaction osig;
-
- sig.sa_handler = func;
- sigemptyset (&sig.sa_mask);
- sig.sa_flags = 0;
-#ifdef SA_RESTART
- sig.sa_flags |= SA_RESTART;
-#endif /* SA_RESTART */
-
- ret = sigaction (signo, &sig, &osig);
-
- if (ret < 0)
- return (SIG_ERR);
- else
- return (osig.sa_handler);
-}
-
-void
-signal_init ()
-{
- signal_set (SIGHUP, sighup);
- signal_set (SIGINT, sigint);
- signal_set (SIGTERM, sigterm);
- signal_set (SIGPIPE, SIG_IGN);
-#ifdef SIGTSTP
- signal_set (SIGTSTP, SIG_IGN);
-#endif
-#ifdef SIGTTIN
- signal_set (SIGTTIN, SIG_IGN);
-#endif
-#ifdef SIGTTOU
- signal_set (SIGTTOU, SIG_IGN);
-#endif
- signal_set (SIGUSR1, sigusr1);
-}
+struct quagga_signal_t isisd_signals[] =
+{
+ {
+ .signal = SIGHUP,
+ .handler = &sighup,
+ },
+ {
+ .signal = SIGUSR1,
+ .handler = &sigusr1,
+ },
+ {
+ .signal = SIGINT,
+ .handler = &sigint,
+ },
+ {
+ .signal = SIGTERM,
+ .handler = &sigterm,
+ },
+};
/*
* Main routine of isisd. Parse arguments and handle IS-IS state machine.
@@ -315,7 +293,7 @@ main (int argc, char **argv, char **envp)
* initializations
*/
zprivs_init (&isisd_privs);
- signal_init ();
+ signal_init (master, Q_SIGC(isisd_signals), isisd_signals);
cmd_init (1);
vty_init (master);
memory_init ();
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 391c2b7e..d8621c56 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -10,7 +10,8 @@ libzebra_a_SOURCES = \
print_version.c checksum.c vector.c linklist.c vty.c command.c \
sockunion.c prefix.c thread.c if.c memory.c buffer.c table.c hash.c \
filter.c routemap.c distribute.c stream.c str.c log.c plist.c \
- zclient.c sockopt.c smux.c md5.c if_rmap.c keychain.c privs.c debug.c
+ zclient.c sockopt.c smux.c md5.c if_rmap.c keychain.c privs.c \
+ debug.c sigevent.c
libzebra_a_DEPENDENCIES = @LIB_REGEX@
@@ -21,7 +22,7 @@ pkginclude_HEADERS = \
memory.h network.h prefix.h routemap.h distribute.h sockunion.h \
str.h stream.h table.h thread.h vector.h version.h vty.h zebra.h \
plist.h zclient.h sockopt.h smux.h md5-gnu.h if_rmap.h keychain.h \
- privs.h debug.h
+ privs.h debug.h sigevent.h
EXTRA_DIST = regex.c regex-gnu.h
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index 51fa7b58..3f1e4fda 100644
--- a/ospfd/ospf_main.c
+++ b/ospfd/ospf_main.c
@@ -38,6 +38,7 @@
#include "memory.h"
#include "privs.h"
#include "debug.h"
+#include "sigevent.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
@@ -125,14 +126,14 @@ Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
/* SIGHUP handler. */
void
-sighup (int sig)
+sighup (void)
{
zlog (NULL, LOG_INFO, "SIGHUP received");
}
/* SIGINT handler. */
void
-sigint (int sig)
+sigint (void)
{
zlog (NULL, LOG_INFO, "Terminating on signal");
@@ -143,58 +144,26 @@ sigint (int sig)
/* SIGUSR1 handler. */
void
-sigusr1 (int sig)
+sigusr1 (void)
{
zlog_rotate (NULL);
}
-/* Signal wrapper. */
-RETSIGTYPE *
-signal_set (int signo, void (*func)(int))
+struct quagga_signal_t ospf_signals[] =
{
- int ret;
- struct sigaction sig;
- struct sigaction osig;
-
- sig.sa_handler = func;
- sigemptyset (&sig.sa_mask);
- sig.sa_flags = 0;
-#ifdef SA_RESTART
- sig.sa_flags |= SA_RESTART;
-#endif /* SA_RESTART */
-
- ret = sigaction (signo, &sig, &osig);
-
- if (ret < 0)
- return (SIG_ERR);
- else
- return (osig.sa_handler);
-}
-
-/* Initialization of signal handles. */
-void
-signal_init ()
-{
- signal_set (SIGHUP, sighup);
- signal_set (SIGINT, sigint);
- signal_set (SIGTERM, sigint);
- signal_set (SIGPIPE, SIG_IGN);
-#ifdef SIGTSTP
- signal_set (SIGTSTP, SIG_IGN);
-#endif
-#ifdef SIGTTIN
- signal_set (SIGTTIN, SIG_IGN);
-#endif
-#ifdef SIGTTOU
- signal_set (SIGTTOU, SIG_IGN);
-#endif
- signal_set (SIGUSR1, sigusr1);
-#ifdef HAVE_GLIBC_BACKTRACE
- signal_set (SIGBUS, debug_print_trace);
- signal_set (SIGSEGV, debug_print_trace);
- signal_set (SIGILL, debug_print_trace);
-#endif /* HAVE_GLIBC_BACKTRACE */
-}
+ {
+ .signal = SIGHUP,
+ .handler = &sighup,
+ },
+ {
+ .signal = SIGUSR1,
+ .handler = &sigusr1,
+ },
+ {
+ .signal = SIGINT,
+ .handler = &sigint,
+ },
+};
/* OSPFd main routine. */
int
@@ -285,7 +254,7 @@ main (int argc, char **argv)
/* Library inits. */
zprivs_init (&ospfd_privs);
- signal_init ();
+ signal_init (master, Q_SIGC(ospf_signals), ospf_signals);
cmd_init (1);
debug_init ();
vty_init (master);
diff --git a/ripd/rip_main.c b/ripd/rip_main.c
index a87e3b7e..8b0d2162 100644
--- a/ripd/rip_main.c
+++ b/ripd/rip_main.c
@@ -31,6 +31,7 @@
#include "keychain.h"
#include "log.h"
#include "privs.h"
+#include "sigevent.h"
#include "ripd/ripd.h"
@@ -120,32 +121,9 @@ Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
exit (status);
}
-/* Signale wrapper. */
-RETSIGTYPE *
-signal_set (int signo, void (*func)(int))
-{
- int ret;
- struct sigaction sig;
- struct sigaction osig;
-
- sig.sa_handler = func;
- sigemptyset (&sig.sa_mask);
- sig.sa_flags = 0;
-#ifdef SA_RESTART
- sig.sa_flags |= SA_RESTART;
-#endif /* SA_RESTART */
-
- ret = sigaction (signo, &sig, &osig);
-
- if (ret < 0)
- return (SIG_ERR);
- else
- return (osig.sa_handler);
-}
-
/* SIGHUP handler. */
void
-sighup (int sig)
+sighup (void)
{
zlog_info ("SIGHUP received");
rip_clean ();
@@ -163,7 +141,7 @@ sighup (int sig)
/* SIGINT handler. */
void
-sigint (int sig)
+sigint (void)
{
zlog (NULL, LOG_INFO, "Terminating on signal");
@@ -175,21 +153,26 @@ sigint (int sig)
/* SIGUSR1 handler. */
void
-sigusr1 (int sig)
+sigusr1 (void)
{
zlog_rotate (NULL);
}
-/* Initialization of signal handles. */
-void
-signal_init ()
+struct quagga_signal_t ripd_signals[] =
{
- signal_set (SIGHUP, sighup);
- signal_set (SIGINT, sigint);
- signal_set (SIGTERM, sigint);
- signal_set (SIGPIPE, SIG_IGN);
- signal_set (SIGUSR1, sigusr1);
-}
+ {
+ .signal = SIGHUP,
+ .handler = &sighup,
+ },
+ {
+ .signal = SIGUSR1,
+ .handler = &sigusr1,
+ },
+ {
+ .signal = SIGINT,
+ .handler = &sigusr1,
+ },
+};
/* Main routine of ripd. */
int
@@ -271,7 +254,7 @@ main (int argc, char **argv)
/* Library initialization. */
zprivs_init (&ripd_privs);
- signal_init ();
+ signal_init (master, Q_SIGC(ripd_signals), ripd_signals);
cmd_init (1);
vty_init (master);
memory_init ();
diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c
index 9b762674..3beb2279 100644
--- a/ripngd/ripng_main.c
+++ b/ripngd/ripng_main.c
@@ -33,6 +33,7 @@
#include "prefix.h"
#include "if.h"
#include "privs.h"
+#include "sigevent.h"
#include "ripngd/ripngd.h"
@@ -126,7 +127,7 @@ Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
/* SIGHUP handler. */
void
-sighup (int sig)
+sighup (void)
{
zlog_info ("SIGHUP received");
ripng_clean ();
@@ -143,7 +144,7 @@ sighup (int sig)
/* SIGINT handler. */
void
-sigint (int sig)
+sigint (void)
{
zlog_info ("Terminating on signal");
@@ -155,44 +156,26 @@ sigint (int sig)
/* SIGUSR1 handler. */
void
-sigusr1 (int sig)
+sigusr1 (void)
{
zlog_rotate (NULL);
}
-/* Signale wrapper. */
-RETSIGTYPE *
-signal_set (int signo, void (*func)(int))
+struct quagga_signal_t ripng_signals[] =
{
- int ret;
- struct sigaction sig;
- struct sigaction osig;
-
- sig.sa_handler = func;
- sigemptyset (&sig.sa_mask);
- sig.sa_flags = 0;
-#ifdef SA_RESTART
- sig.sa_flags |= SA_RESTART;
-#endif /* SA_RESTART */
-
- ret = sigaction (signo, &sig, &osig);
-
- if (ret < 0)
- return (SIG_ERR);
- else
- return (osig.sa_handler);
-}
-
-/* Initialization of signal handles. */
-void
-signal_init ()
-{
- signal_set (SIGHUP, sighup);
- signal_set (SIGINT, sigint);
- signal_set (SIGTERM, sigint);
- signal_set (SIGPIPE, SIG_IGN);
- signal_set (SIGUSR1, sigusr1);
-}
+ {
+ .signal = SIGHUP,
+ .handler = &sighup,
+ },
+ {
+ .signal = SIGUSR1,
+ .handler = &sigusr1,
+ },
+ {
+ .signal = SIGINT,
+ .handler = &sigint,
+ },
+};
/* RIPngd main routine. */
int
@@ -275,7 +258,7 @@ main (int argc, char **argv)
/* Library inits. */
zprivs_init (&ripngd_privs);
- signal_init ();
+ signal_init (master, Q_SIGC(ripng_signals), ripng_signals);
cmd_init (1);
vty_init (master);
memory_init ();
diff --git a/zebra/main.c b/zebra/main.c
index 98227ea5..a66734cc 100644
--- a/zebra/main.c
+++ b/zebra/main.c
@@ -30,6 +30,7 @@
#include "prefix.h"
#include "log.h"
#include "privs.h"
+#include "sigevent.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
@@ -131,7 +132,7 @@ Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
/* SIGHUP handler. */
void
-sighup (int sig)
+sighup (void)
{
zlog_info ("SIGHUP received");
@@ -141,7 +142,7 @@ sighup (int sig)
/* SIGINT handler. */
void
-sigint (int sig)
+sigint (void)
{
/* Decrared in rib.c */
void rib_close ();
@@ -156,44 +157,26 @@ sigint (int sig)
/* SIGUSR1 handler. */
void
-sigusr1 (int sig)
+sigusr1 (void)
{
zlog_rotate (NULL);
}
-/* Signale wrapper. */
-RETSIGTYPE *
-signal_set (int signo, void (*func)(int))
+struct quagga_signal_t zebra_signals[] =
{
- int ret;
- struct sigaction sig;
- struct sigaction osig;
-
- sig.sa_handler = func;
- sigemptyset (&sig.sa_mask);
- sig.sa_flags = 0;
-#ifdef SA_RESTART
- sig.sa_flags |= SA_RESTART;
-#endif /* SA_RESTART */
-
- ret = sigaction (signo, &sig, &osig);
-
- if (ret < 0)
- return (SIG_ERR);
- else
- return (osig.sa_handler);
-}
-
-/* Initialization of signal handles. */
-void
-signal_init ()
-{
- signal_set (SIGHUP, sighup);
- signal_set (SIGINT, sigint);
- signal_set (SIGTERM, sigint);
- signal_set (SIGPIPE, SIG_IGN);
- signal_set (SIGUSR1, sigusr1);
-}
+ {
+ .signal = SIGHUP,
+ .handler = &sighup,
+ },
+ {
+ .signal = SIGUSR1,
+ .handler = &sigusr1,
+ },
+ {
+ .signal = SIGINT,
+ .handler = &sigusr1,
+ },
+};
/* Main startup routine. */
int
@@ -289,7 +272,7 @@ main (int argc, char **argv)
zprivs_init (&zserv_privs);
/* Vty related initialize. */
- signal_init ();
+ signal_init (zebrad.master, Q_SIGC(zebra_signals), zebra_signals);
cmd_init (1);
vty_init (zebrad.master);
memory_init ();