mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-09 19:13:58 +00:00
2005-01-18 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* log.h: Test for SA_SIGINFO to see whether zlog_signal takes final two args (siginfo and program_counter). * log.c: (hex_append) Include this function only if SA_SIGINFO or HAVE_GLIBC_BACKTRACE is defined. (zlog_signal) Final two args (siginfo and program_counter) now depend on whether SA_SIGINFO is defined on this platform. * sigevent.c: (program_counter) Do not include this function if SA_SIGINFO is not defined on this platform. (exit_handler,core_handler) Test for SA_SIGINFO to decide whether 2nd & 3rd arguments are present and to decide how to invoke zlog_signal. (trap_default_signals) Test for SA_SIGINFO and invoke sigaction appropriately.
This commit is contained in:
parent
92365889d1
commit
31364274dd
@ -1,3 +1,19 @@
|
|||||||
|
2005-01-18 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
|
||||||
|
|
||||||
|
* log.h: Test for SA_SIGINFO to see whether zlog_signal takes final
|
||||||
|
two args (siginfo and program_counter).
|
||||||
|
* log.c: (hex_append) Include this function only if SA_SIGINFO or
|
||||||
|
HAVE_GLIBC_BACKTRACE is defined.
|
||||||
|
(zlog_signal) Final two args (siginfo and program_counter) now
|
||||||
|
depend on whether SA_SIGINFO is defined on this platform.
|
||||||
|
* sigevent.c: (program_counter) Do not include this function if
|
||||||
|
SA_SIGINFO is not defined on this platform.
|
||||||
|
(exit_handler,core_handler) Test for SA_SIGINFO to decide whether
|
||||||
|
2nd & 3rd arguments are present and to decide how to invoke
|
||||||
|
zlog_signal.
|
||||||
|
(trap_default_signals) Test for SA_SIGINFO and invoke sigaction
|
||||||
|
appropriately.
|
||||||
|
|
||||||
2005-01-17 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
|
2005-01-17 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
|
||||||
|
|
||||||
* log.h: Change prototype for zlog_backtrace_sigsafe to take additional
|
* log.h: Change prototype for zlog_backtrace_sigsafe to take additional
|
||||||
|
23
lib/log.c
23
lib/log.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: log.c,v 1.22 2005/01/17 15:22:28 ajs Exp $
|
* $Id: log.c,v 1.23 2005/01/18 22:18:59 ajs Exp $
|
||||||
*
|
*
|
||||||
* Logging of zebra
|
* Logging of zebra
|
||||||
* Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
|
* Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
|
||||||
@ -177,6 +177,7 @@ num_append(char *s, int len, u_long x)
|
|||||||
return str_append(s,len,t);
|
return str_append(s,len,t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(SA_SIGINFO) || defined(HAVE_GLIBC_BACKTRACE)
|
||||||
static char *
|
static char *
|
||||||
hex_append(char *s, int len, u_long x)
|
hex_append(char *s, int len, u_long x)
|
||||||
{
|
{
|
||||||
@ -194,6 +195,7 @@ hex_append(char *s, int len, u_long x)
|
|||||||
}
|
}
|
||||||
return str_append(s,len,t);
|
return str_append(s,len,t);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int syslog_fd = -1;
|
static int syslog_fd = -1;
|
||||||
|
|
||||||
@ -258,8 +260,11 @@ syslog_sigsafe(int priority, const char *msg, size_t msglen)
|
|||||||
|
|
||||||
/* Note: the goal here is to use only async-signal-safe functions. */
|
/* Note: the goal here is to use only async-signal-safe functions. */
|
||||||
void
|
void
|
||||||
zlog_signal(int signo, const char *action, siginfo_t *siginfo,
|
zlog_signal(int signo, const char *action
|
||||||
void *program_counter)
|
#ifdef SA_SIGINFO
|
||||||
|
, siginfo_t *siginfo, void *program_counter
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
time_t now;
|
time_t now;
|
||||||
char buf[sizeof("DEFAULT: Received signal S at T (si_addr 0xP, PC 0xP); aborting...")+100];
|
char buf[sizeof("DEFAULT: Received signal S at T (si_addr 0xP, PC 0xP); aborting...")+100];
|
||||||
@ -279,6 +284,7 @@ zlog_signal(int signo, const char *action, siginfo_t *siginfo,
|
|||||||
s = num_append(LOC,signo);
|
s = num_append(LOC,signo);
|
||||||
s = str_append(LOC," at ");
|
s = str_append(LOC," at ");
|
||||||
s = num_append(LOC,now);
|
s = num_append(LOC,now);
|
||||||
|
#ifdef SA_SIGINFO
|
||||||
s = str_append(LOC," (si_addr 0x");
|
s = str_append(LOC," (si_addr 0x");
|
||||||
s = hex_append(LOC,(u_long)(siginfo->si_addr));
|
s = hex_append(LOC,(u_long)(siginfo->si_addr));
|
||||||
if (program_counter)
|
if (program_counter)
|
||||||
@ -287,6 +293,9 @@ zlog_signal(int signo, const char *action, siginfo_t *siginfo,
|
|||||||
s = hex_append(LOC,(u_long)program_counter);
|
s = hex_append(LOC,(u_long)program_counter);
|
||||||
}
|
}
|
||||||
s = str_append(LOC,"); ");
|
s = str_append(LOC,"); ");
|
||||||
|
#else /* SA_SIGINFO */
|
||||||
|
s = str_append(LOC,"; ");
|
||||||
|
#endif /* SA_SIGINFO */
|
||||||
s = str_append(LOC,action);
|
s = str_append(LOC,action);
|
||||||
if (s < buf+sizeof(buf))
|
if (s < buf+sizeof(buf))
|
||||||
*s++ = '\n';
|
*s++ = '\n';
|
||||||
@ -312,7 +321,13 @@ zlog_signal(int signo, const char *action, siginfo_t *siginfo,
|
|||||||
}
|
}
|
||||||
#undef DUMP
|
#undef DUMP
|
||||||
|
|
||||||
zlog_backtrace_sigsafe(PRI, program_counter);
|
zlog_backtrace_sigsafe(PRI,
|
||||||
|
#ifdef SA_SIGINFO
|
||||||
|
program_counter
|
||||||
|
#else
|
||||||
|
NULL
|
||||||
|
#endif
|
||||||
|
);
|
||||||
#undef PRI
|
#undef PRI
|
||||||
#undef LOC
|
#undef LOC
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: log.h,v 1.16 2005/01/17 15:22:28 ajs Exp $
|
* $Id: log.h,v 1.17 2005/01/18 22:18:59 ajs Exp $
|
||||||
*
|
*
|
||||||
* Zebra logging funcions.
|
* Zebra logging funcions.
|
||||||
* Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
|
* Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
|
||||||
@ -153,8 +153,11 @@ extern const char *zlog_proto_names[];
|
|||||||
extern const char *safe_strerror(int errnum);
|
extern const char *safe_strerror(int errnum);
|
||||||
|
|
||||||
/* To be called when a fatal signal is caught. */
|
/* To be called when a fatal signal is caught. */
|
||||||
extern void zlog_signal(int signo, const char *action,
|
extern void zlog_signal(int signo, const char *action
|
||||||
siginfo_t *siginfo, void *program_counter);
|
#ifdef SA_SIGINFO
|
||||||
|
, siginfo_t *siginfo, void *program_counter
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
/* Log a backtrace. */
|
/* Log a backtrace. */
|
||||||
extern void zlog_backtrace(int priority);
|
extern void zlog_backtrace(int priority);
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <sigevent.h>
|
#include <sigevent.h>
|
||||||
#include <log.h>
|
#include <log.h>
|
||||||
|
|
||||||
|
#ifdef SA_SIGINFO
|
||||||
#ifdef HAVE_UCONTEXT_H
|
#ifdef HAVE_UCONTEXT_H
|
||||||
#ifdef GNU_LINUX
|
#ifdef GNU_LINUX
|
||||||
/* get REG_EIP from ucontext.h */
|
/* get REG_EIP from ucontext.h */
|
||||||
@ -30,6 +31,7 @@
|
|||||||
#endif /* GNU_LINUX */
|
#endif /* GNU_LINUX */
|
||||||
#include <ucontext.h>
|
#include <ucontext.h>
|
||||||
#endif /* HAVE_UCONTEXT_H */
|
#endif /* HAVE_UCONTEXT_H */
|
||||||
|
#endif /* SA_SIGINFO */
|
||||||
|
|
||||||
|
|
||||||
/* master signals descriptor struct */
|
/* master signals descriptor struct */
|
||||||
@ -161,6 +163,8 @@ signal_set (int signo)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SA_SIGINFO
|
||||||
|
|
||||||
/* XXX This function should be enhanced to support more platforms
|
/* XXX This function should be enhanced to support more platforms
|
||||||
(it currently works only on Linux/x86). */
|
(it currently works only on Linux/x86). */
|
||||||
static void *
|
static void *
|
||||||
@ -177,17 +181,35 @@ program_counter(void *context)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* SA_SIGINFO */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
exit_handler(int signo, siginfo_t *siginfo, void *context)
|
exit_handler(int signo
|
||||||
|
#ifdef SA_SIGINFO
|
||||||
|
, siginfo_t *siginfo, void *context
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
zlog_signal(signo, "exiting...", siginfo, program_counter(context));
|
zlog_signal(signo, "exiting..."
|
||||||
|
#ifdef SA_SIGINFO
|
||||||
|
, siginfo, program_counter(context)
|
||||||
|
#endif
|
||||||
|
);
|
||||||
_exit(128+signo);
|
_exit(128+signo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
core_handler(int signo, siginfo_t *siginfo, void *context)
|
core_handler(int signo
|
||||||
|
#ifdef SA_SIGINFO
|
||||||
|
, siginfo_t *siginfo, void *context
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
zlog_signal(signo, "aborting...", siginfo, program_counter(context));
|
zlog_signal(signo, "aborting..."
|
||||||
|
#ifdef SA_SIGINFO
|
||||||
|
, siginfo, program_counter(context)
|
||||||
|
#endif
|
||||||
|
);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +258,11 @@ trap_default_signals(void)
|
|||||||
static const struct {
|
static const struct {
|
||||||
const int *sigs;
|
const int *sigs;
|
||||||
u_int nsigs;
|
u_int nsigs;
|
||||||
void (*handler)(int signo, siginfo_t *info, void *context);
|
void (*handler)(int signo
|
||||||
|
#ifdef SA_SIGINFO
|
||||||
|
, siginfo_t *info, void *context
|
||||||
|
#endif
|
||||||
|
);
|
||||||
} sigmap[] = {
|
} sigmap[] = {
|
||||||
{ core_signals, sizeof(core_signals)/sizeof(core_signals[0]), core_handler},
|
{ core_signals, sizeof(core_signals)/sizeof(core_signals[0]), core_handler},
|
||||||
{ exit_signals, sizeof(exit_signals)/sizeof(exit_signals[0]), exit_handler},
|
{ exit_signals, sizeof(exit_signals)/sizeof(exit_signals[0]), exit_handler},
|
||||||
@ -263,9 +289,14 @@ trap_default_signals(void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#ifdef SA_SIGINFO
|
||||||
/* Request extra arguments to signal handler. */
|
/* Request extra arguments to signal handler. */
|
||||||
act.sa_sigaction = sigmap[i].handler;
|
act.sa_sigaction = sigmap[i].handler;
|
||||||
act.sa_flags = SA_SIGINFO;
|
act.sa_flags = SA_SIGINFO;
|
||||||
|
#else
|
||||||
|
act.sa_handler = sigmap[i].handler;
|
||||||
|
act.sa_flags = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (sigaction(sigmap[i].sigs[j],&act,NULL) < 0)
|
if (sigaction(sigmap[i].sigs[j],&act,NULL) < 0)
|
||||||
zlog_warn("Unable to set signal handler for signal %d: %s",
|
zlog_warn("Unable to set signal handler for signal %d: %s",
|
||||||
|
Loading…
Reference in New Issue
Block a user