make/signame.c

252 lines
6.7 KiB
C
Raw Normal View History

1993-07-26 20:20:42 +00:00
/* Convert between signal names and numbers.
Copyright (C) 1990,92,93,95,96,99, 2002 Free Software Foundation, Inc.
This file was part of the GNU C Library, but is now part of GNU make.
1997-06-23 22:48:40 +00:00
GNU Make is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
1997-06-23 22:48:40 +00:00
GNU Make is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
1997-06-23 22:48:40 +00:00
You should have received a copy of the GNU General Public License
along with GNU Make; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
1993-07-26 20:20:42 +00:00
#include "make.h"
/* If the system provides strsignal, we don't need it. */
#if !defined(HAVE_STRSIGNAL)
/* If the system provides sys_siglist, we'll use that.
Otherwise create our own.
*/
#if !defined(SYS_SIGLIST_DECLARED)
1993-07-26 20:20:42 +00:00
/* Some systems do not define NSIG in <signal.h>. */
#ifndef NSIG
#ifdef _NSIG
#define NSIG _NSIG
#else
#define NSIG 32
#endif
#endif
/* There is too much variation in Sys V signal numbers and names, so
we must initialize them at runtime. */
static const char *undoc;
1993-07-26 20:20:42 +00:00
static const char *sys_siglist[NSIG];
1993-07-26 20:20:42 +00:00
/* Table of abbreviations for signals. Note: A given number can
appear more than once with different abbreviations. */
#define SIG_TABLE_SIZE (NSIG*2)
1993-07-26 20:20:42 +00:00
typedef struct
{
int number;
const char *abbrev;
} num_abbrev;
static num_abbrev sig_table[SIG_TABLE_SIZE];
1993-07-26 20:20:42 +00:00
/* Number of elements of sig_table used. */
static int sig_table_nelts = 0;
/* Enter signal number NUMBER into the tables with ABBREV and NAME. */
static void
init_sig (int number, const char *abbrev, const char *name)
1993-07-26 20:20:42 +00:00
{
/* If this value is ever greater than NSIG it seems like it'd be a bug in
the system headers, but... better safe than sorry. We know, for
example, that this isn't always true on VMS. */
if (number >= 0 && number < NSIG)
sys_siglist[number] = name;
if (sig_table_nelts < SIG_TABLE_SIZE)
{
sig_table[sig_table_nelts].number = number;
sig_table[sig_table_nelts++].abbrev = abbrev;
}
1993-07-26 20:20:42 +00:00
}
static int
signame_init (void)
1993-07-26 20:20:42 +00:00
{
int i;
undoc = xstrdup (_("unknown signal"));
1993-07-26 20:20:42 +00:00
/* Initialize signal names. */
for (i = 0; i < NSIG; i++)
sys_siglist[i] = undoc;
/* Initialize signal names. */
#if defined (SIGHUP)
init_sig (SIGHUP, "HUP", _("Hangup"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGINT)
init_sig (SIGINT, "INT", _("Interrupt"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGQUIT)
init_sig (SIGQUIT, "QUIT", _("Quit"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGILL)
init_sig (SIGILL, "ILL", _("Illegal Instruction"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGTRAP)
init_sig (SIGTRAP, "TRAP", _("Trace/breakpoint trap"));
1993-07-26 20:20:42 +00:00
#endif
/* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
#if defined (SIGABRT)
init_sig (SIGABRT, "ABRT", _("Aborted"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGIOT)
init_sig (SIGIOT, "IOT", _("IOT trap"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGEMT)
init_sig (SIGEMT, "EMT", _("EMT trap"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGFPE)
init_sig (SIGFPE, "FPE", _("Floating point exception"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGKILL)
init_sig (SIGKILL, "KILL", _("Killed"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGBUS)
init_sig (SIGBUS, "BUS", _("Bus error"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGSEGV)
init_sig (SIGSEGV, "SEGV", _("Segmentation fault"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGSYS)
init_sig (SIGSYS, "SYS", _("Bad system call"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGPIPE)
init_sig (SIGPIPE, "PIPE", _("Broken pipe"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGALRM)
init_sig (SIGALRM, "ALRM", _("Alarm clock"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGTERM)
init_sig (SIGTERM, "TERM", _("Terminated"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGUSR1)
init_sig (SIGUSR1, "USR1", _("User defined signal 1"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGUSR2)
init_sig (SIGUSR2, "USR2", _("User defined signal 2"));
1993-07-26 20:20:42 +00:00
#endif
/* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
is what is in POSIX.1. */
#if defined (SIGCHLD)
init_sig (SIGCHLD, "CHLD", _("Child exited"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGCLD)
init_sig (SIGCLD, "CLD", _("Child exited"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGPWR)
init_sig (SIGPWR, "PWR", _("Power failure"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGTSTP)
init_sig (SIGTSTP, "TSTP", _("Stopped"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGTTIN)
init_sig (SIGTTIN, "TTIN", _("Stopped (tty input)"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGTTOU)
init_sig (SIGTTOU, "TTOU", _("Stopped (tty output)"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGSTOP)
init_sig (SIGSTOP, "STOP", _("Stopped (signal)"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGXCPU)
init_sig (SIGXCPU, "XCPU", _("CPU time limit exceeded"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGXFSZ)
init_sig (SIGXFSZ, "XFSZ", _("File size limit exceeded"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGVTALRM)
init_sig (SIGVTALRM, "VTALRM", _("Virtual timer expired"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGPROF)
init_sig (SIGPROF, "PROF", _("Profiling timer expired"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGWINCH)
/* "Window size changed" might be more accurate, but even if that
is all that it means now, perhaps in the future it will be
extended to cover other kinds of window changes. */
init_sig (SIGWINCH, "WINCH", _("Window changed"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGCONT)
init_sig (SIGCONT, "CONT", _("Continued"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGURG)
init_sig (SIGURG, "URG", _("Urgent I/O condition"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGIO)
/* "I/O pending" has also been suggested. A disadvantage is
that signal only happens when the process has
asked for it, not everytime I/O is pending. Another disadvantage
is the confusion from giving it a different name than under Unix. */
init_sig (SIGIO, "IO", _("I/O possible"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGWIND)
init_sig (SIGWIND, "WIND", _("SIGWIND"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGPHONE)
init_sig (SIGPHONE, "PHONE", _("SIGPHONE"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGPOLL)
init_sig (SIGPOLL, "POLL", _("I/O possible"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGLOST)
init_sig (SIGLOST, "LOST", _("Resource lost"));
1993-07-26 20:20:42 +00:00
#endif
#if defined (SIGDANGER)
init_sig (SIGDANGER, "DANGER", _("Danger signal"));
1993-07-26 20:20:42 +00:00
#endif
1995-03-21 21:44:32 +00:00
#if defined (SIGINFO)
init_sig (SIGINFO, "INFO", _("Information request"));
1995-03-21 21:44:32 +00:00
#endif
1997-04-07 07:21:16 +00:00
#if defined (SIGNOFP)
init_sig (SIGNOFP, "NOFP", _("Floating point co-processor not available"));
1997-04-07 07:21:16 +00:00
#endif
1993-07-26 20:20:42 +00:00
return 1;
1993-07-26 20:20:42 +00:00
}
#endif /* SYS_SIGLIST_DECLARED */
1993-07-26 20:20:42 +00:00
char *
strsignal (int signal)
{
static char buf[] = "Signal 12345678901234567890";
1996-03-20 14:59:27 +00:00
#if !defined(SYS_SIGLIST_DECLARED)
static char sig_initted = 0;
if (!sig_initted)
sig_initted = signame_init ();
#endif
if (signal > 0 || signal < NSIG)
return (char *) sys_siglist[signal];
1996-03-20 14:59:27 +00:00
sprintf (buf, "Signal %d", signal);
return buf;
}
#endif /* HAVE_STRSIGNAL */