Show misc_signals.c syntax highlighted
/*
*
* Copyright (c) 2003 The Regents of the University of California. All
* rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* misc_signals.c: Various utilities for handling UNIX signals
*
* $Id: misc_signals.c,v 1.4 2004/12/07 00:02:40 jelson Exp $
*/
char misc_signals_cvsid[] = "$Id: misc_signals.c,v 1.4 2004/12/07 00:02:40 jelson Exp $";
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include "misc.h"
struct {
char *name;
int num;
} signalnames[] = {
#ifdef SIGHUP
{ "SIGHUP" , SIGHUP },
#endif /* SIGHUP */
#ifdef SIGINT
{ "SIGINT" , SIGINT },
#endif /* SIGINT */
#ifdef SIGQUIT
{ "SIGQUIT" , SIGQUIT },
#endif /* SIGQUIT */
#ifdef SIGILL
{ "SIGILL" , SIGILL },
#endif /* SIGILL */
#ifdef SIGTRAP
{ "SIGTRAP" , SIGTRAP },
#endif /* SIGTRAP */
#ifdef SIGABRT
{ "SIGABRT" , SIGABRT },
#endif /* SIGABRT */
#ifdef SIGIOT
{ "SIGIOT" , SIGIOT },
#endif /* SIGIOT */
#ifdef SIGBUS
{ "SIGBUS" , SIGBUS },
#endif /* SIGBUS */
#ifdef SIGFPE
{ "SIGFPE" , SIGFPE },
#endif /* SIGFPE */
#ifdef SIGKILL
{ "SIGKILL" , SIGKILL },
#endif /* SIGKILL */
#ifdef SIGUSR1
{ "SIGUSR1" , SIGUSR1 },
#endif /* SIGUSR1 */
#ifdef SIGSEGV
{ "SIGSEGV" , SIGSEGV },
#endif /* SIGSEGV */
#ifdef SIGUSR2
{ "SIGUSR2" , SIGUSR2 },
#endif /* SIGUSR2 */
#ifdef SIGPIPE
{ "SIGPIPE" , SIGPIPE },
#endif /* SIGPIPE */
#ifdef SIGALRM
{ "SIGALRM" , SIGALRM },
#endif /* SIGALRM */
#ifdef SIGTERM
{ "SIGTERM" , SIGTERM },
#endif /* SIGTERM */
#ifdef SIGSTKFLT
{ "SIGSTKFLT" , SIGSTKFLT },
#endif /* SIGSTKFLT */
#ifdef SIGCHLD
{ "SIGCHLD" , SIGCHLD },
#endif /* SIGCHLD */
#ifdef SIGCONT
{ "SIGCONT" , SIGCONT },
#endif /* SIGCONT */
#ifdef SIGSTOP
{ "SIGSTOP" , SIGSTOP },
#endif /* SIGSTOP */
#ifdef SIGTSTP
{ "SIGTSTP" , SIGTSTP },
#endif /* SIGTSTP */
#ifdef SIGTTIN
{ "SIGTTIN" , SIGTTIN },
#endif /* SIGTTIN */
#ifdef SIGTTOU
{ "SIGTTOU" , SIGTTOU },
#endif /* SIGTTOU */
#ifdef SIGURG
{ "SIGURG" , SIGURG },
#endif /* SIGURG */
#ifdef SIGXCPU
{ "SIGXCPU" , SIGXCPU },
#endif /* SIGXCPU */
#ifdef SIGXFSZ
{ "SIGXFSZ" , SIGXFSZ },
#endif /* SIGXFSZ */
#ifdef SIGVTALRM
{ "SIGVTALRM" , SIGVTALRM },
#endif /* SIGVTALRM */
#ifdef SIGPROF
{ "SIGPROF" , SIGPROF },
#endif /* SIGPROF */
#ifdef SIGWINCH
{ "SIGWINCH" , SIGWINCH },
#endif /* SIGWINCH */
#ifdef SIGIO
{ "SIGIO" , SIGIO },
#endif /* SIGIO */
#ifdef SIGPOLL
{ "SIGPOLL" , SIGPOLL },
#endif /* SIGPOLL */
#ifdef SIGLOST
{ "SIGLOST" , SIGLOST },
#endif /* SIGLOST */
#ifdef SIGPWR
{ "SIGPWR" , SIGPWR },
#endif /* SIGPWR */
#ifdef SIGSYS
{ "SIGSYS" , SIGSYS },
#endif /* SIGSYS */
{ NULL, -1},
};
/*
* Convert a signal name into a signal number
*/
int find_signal_by_name(const char *signame)
{
int i, offset;
/* we want to be able to match either "SIGHUP" or just plain "HUP" */
if (!strncasecmp(signame, "SIG", 3))
offset = 0;
else
offset = 3;
for (i = 0; signalnames[i].name != NULL; i++)
if (!strcasecmp(signalnames[i].name + offset, signame))
return signalnames[i].num;
return -1;
}
/*
* Convert a signal number into a name
*/
const char *signal_name(int signo)
{
int i;
for (i = 0; signalnames[i].name != NULL; i++)
if (signalnames[i].num == signo)
return signalnames[i].name;
return NULL;
}
See more files for this project here