Clean up sys_signame and sys_siglist a little.

We don't need quite so much duplication because we already have a way
to get the signal number from its name, and that already copes with the
fact that the mips/mips64 numbers are different from everyone else's.

Also remove sys_signame from LP64. glibc doesn't have this BSD-ism.

Change-Id: I6dc411a3d73589383c85d3b07d9d648311492a10
This commit is contained in:
Elliott Hughes 2014-02-11 19:57:06 -08:00
parent 9e572ca416
commit aa0ebdafc7
7 changed files with 127 additions and 131 deletions

View file

@ -37,67 +37,6 @@ endif
# Define the common source files for all the libc instances
# =========================================================
libc_common_src_files := \
unistd/alarm.c \
unistd/exec.c \
unistd/fnmatch.c \
unistd/syslog.c \
unistd/system.c \
unistd/time.c \
stdio/asprintf.c \
stdio/fflush.c \
stdio/fgetc.c \
stdio/findfp.c \
stdio/fprintf.c \
stdio/fputc.c \
stdio/fread.c \
stdio/freopen.c \
stdio/fscanf.c \
stdio/fseek.c \
stdio/ftell.c \
stdio/fvwrite.c \
stdio/gets.c \
stdio/printf.c \
stdio/refill.c \
stdio/rewind.c \
stdio/scanf.c \
stdio/snprintf.c\
stdio/sprintf.c \
stdio/sscanf.c \
stdio/stdio.c \
stdio/ungetc.c \
stdio/vasprintf.c \
stdio/vfprintf.c \
stdio/vfscanf.c \
stdio/vprintf.c \
stdio/vsnprintf.c \
stdio/vsprintf.c \
stdio/vscanf.c \
stdio/vsscanf.c \
stdio/wbuf.c \
stdlib/atexit.c \
stdlib/ctype_.c \
stdlib/getenv.c \
stdlib/putenv.c \
stdlib/setenv.c \
stdlib/strtod.c \
stdlib/strtoimax.c \
stdlib/strtol.c \
stdlib/strtoll.c \
stdlib/strtoul.c \
stdlib/strtoull.c \
stdlib/strtoumax.c \
stdlib/tolower_.c \
stdlib/toupper_.c \
string/strcasecmp.c \
string/strcspn.c \
string/strdup.c \
string/strpbrk.c \
string/strsep.c \
string/strspn.c \
string/strstr.c \
string/strtok.c \
wchar/wcswidth.c \
wchar/wcsxfrm.c \
bionic/arc4random.c \
bionic/atoi.c \
bionic/atol.c \
@ -143,8 +82,6 @@ libc_common_src_files := \
bionic/setpgrp.c \
bionic/sigblock.c \
bionic/siginterrupt.c \
bionic/siglist.c \
bionic/signame.c \
bionic/sigsetmask.c \
bionic/strndup.c \
bionic/strntoimax.c \
@ -159,6 +96,67 @@ libc_common_src_files := \
bionic/unlockpt.c \
bionic/utmp.c \
bionic/wcscoll.c \
stdio/asprintf.c \
stdio/fflush.c \
stdio/fgetc.c \
stdio/findfp.c \
stdio/fprintf.c \
stdio/fputc.c \
stdio/fread.c \
stdio/freopen.c \
stdio/fscanf.c \
stdio/fseek.c \
stdio/ftell.c \
stdio/fvwrite.c \
stdio/gets.c \
stdio/printf.c \
stdio/refill.c \
stdio/rewind.c \
stdio/scanf.c \
stdio/snprintf.c\
stdio/sprintf.c \
stdio/sscanf.c \
stdio/stdio.c \
stdio/ungetc.c \
stdio/vasprintf.c \
stdio/vfprintf.c \
stdio/vfscanf.c \
stdio/vprintf.c \
stdio/vscanf.c \
stdio/vsnprintf.c \
stdio/vsprintf.c \
stdio/vsscanf.c \
stdio/wbuf.c \
stdlib/atexit.c \
stdlib/ctype_.c \
stdlib/getenv.c \
stdlib/putenv.c \
stdlib/setenv.c \
stdlib/strtod.c \
stdlib/strtoimax.c \
stdlib/strtol.c \
stdlib/strtoll.c \
stdlib/strtoul.c \
stdlib/strtoull.c \
stdlib/strtoumax.c \
stdlib/tolower_.c \
stdlib/toupper_.c \
string/strcasecmp.c \
string/strcspn.c \
string/strdup.c \
string/strpbrk.c \
string/strsep.c \
string/strspn.c \
string/strstr.c \
string/strtok.c \
unistd/alarm.c \
unistd/exec.c \
unistd/fnmatch.c \
unistd/syslog.c \
unistd/system.c \
unistd/time.c \
wchar/wcswidth.c \
wchar/wcsxfrm.c \
libc_dns_src_files += \
@ -222,8 +220,8 @@ libc_bionic_src_files := \
bionic/dirent.cpp \
bionic/dup2.cpp \
bionic/epoll_create.cpp \
bionic/epoll_wait.cpp \
bionic/epoll_pwait.cpp \
bionic/epoll_wait.cpp \
bionic/__errno.cpp \
bionic/eventfd_read.cpp \
bionic/eventfd_write.cpp \
@ -280,7 +278,6 @@ libc_bionic_src_files := \
bionic/__set_errno.cpp \
bionic/seteuid.cpp \
bionic/setlocale.cpp \
bionic/signalfd.cpp \
bionic/sigaction.cpp \
bionic/sigaddset.cpp \
bionic/sigdelset.cpp \
@ -288,6 +285,7 @@ libc_bionic_src_files := \
bionic/sigfillset.cpp \
bionic/sigismember.cpp \
bionic/signal.cpp \
bionic/signalfd.cpp \
bionic/sigpending.cpp \
bionic/sigprocmask.cpp \
bionic/sigsuspend.cpp \
@ -300,8 +298,10 @@ libc_bionic_src_files := \
bionic/stubs.cpp \
bionic/symlink.cpp \
bionic/sysconf.cpp \
bionic/thread_atexit.cpp \
bionic/sys_siglist.c \
bionic/sys_signame.c \
bionic/tdestroy.cpp \
bionic/thread_atexit.cpp \
bionic/timer.cpp \
bionic/tmpfile.cpp \
bionic/unlink.cpp \

View file

@ -34,7 +34,7 @@ extern "C" __LIBC_HIDDEN__ const char* __strerror_lookup(int error_number) {
}
static const Pair _sys_signal_strings[] = {
#define __BIONIC_SIGDEF(x,y,z) { y, z },
#define __BIONIC_SIGDEF(signal_number, signal_description) { signal_number, signal_description },
#include <sys/_sigdefs.h>
{ 0, NULL }
};

View file

@ -25,9 +25,10 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <signal.h>
const char * const sys_siglist[NSIG] = {
#define __BIONIC_SIGDEF(x,y,z) [ SIG##x ] = z,
const char* const sys_siglist[NSIG] = {
#define __BIONIC_SIGDEF(signal_number, signal_description) [ signal_number ] = signal_description,
#include <sys/_sigdefs.h>
};

View file

@ -25,9 +25,14 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <signal.h>
const char * const sys_signame[NSIG] = {
#define __BIONIC_SIGDEF(x,y,z) [ SIG##x ] = #x,
#if !defined(__LP64__)
const char* const sys_signame[NSIG] = {
#define __BIONIC_SIGDEF(signal_number, unused) [ signal_number ] = #signal_number + 3,
#include <sys/_sigdefs.h>
};
#endif

View file

@ -61,7 +61,9 @@ typedef int sig_atomic_t;
#define NSIG _NSIG
extern const char* const sys_siglist[];
#if !defined(__LP64__)
extern const char* const sys_signame[];
#endif
typedef __sighandler_t sig_t; /* BSD compatibility. */
typedef __sighandler_t sighandler_t; /* glibc compatibility. */

View file

@ -35,67 +35,41 @@
#error __BIONIC_SIGDEF not defined
#endif
__BIONIC_SIGDEF(HUP,1,"Hangup")
__BIONIC_SIGDEF(INT,2,"Interrupt")
__BIONIC_SIGDEF(QUIT,3,"Quit")
__BIONIC_SIGDEF(ILL,4,"Illegal instruction")
__BIONIC_SIGDEF(TRAP,5,"Trap")
__BIONIC_SIGDEF(ABRT,6,"Aborted")
#ifdef __mips__
__BIONIC_SIGDEF(EMT,7,"EMT")
#else
__BIONIC_SIGDEF(BUS,7,"Bus error")
__BIONIC_SIGDEF(SIGHUP, "Hangup")
__BIONIC_SIGDEF(SIGINT, "Interrupt")
__BIONIC_SIGDEF(SIGQUIT, "Quit")
__BIONIC_SIGDEF(SIGILL, "Illegal instruction")
__BIONIC_SIGDEF(SIGTRAP, "Trap")
__BIONIC_SIGDEF(SIGABRT, "Aborted")
#ifdef SIGEMT
__BIONIC_SIGDEF(SIGEMT, "EMT")
#endif
__BIONIC_SIGDEF(FPE,8,"Floating point exception")
__BIONIC_SIGDEF(KILL,9,"Killed")
#ifdef __mips__
__BIONIC_SIGDEF(BUS,10,"Bus error")
#else
__BIONIC_SIGDEF(USR1,10,"User signal 1")
#endif
__BIONIC_SIGDEF(SEGV,11,"Segmentation fault")
#ifdef __mips__
__BIONIC_SIGDEF(SYS,12,"Bad system call")
#else
__BIONIC_SIGDEF(USR2,12,"User signal 2")
#endif
__BIONIC_SIGDEF(PIPE,13,"Broken pipe")
__BIONIC_SIGDEF(ALRM,14,"Alarm clock")
__BIONIC_SIGDEF(TERM,15,"Terminated")
#ifdef __mips__
__BIONIC_SIGDEF(USR1,16,"User signal 1")
__BIONIC_SIGDEF(USR2,17,"User signal 2")
__BIONIC_SIGDEF(CHLD,18,"Child exited")
__BIONIC_SIGDEF(PWR,19,"Power failure")
__BIONIC_SIGDEF(WINCH,20,"Window size changed")
__BIONIC_SIGDEF(URG,21,"Urgent I/O condition")
__BIONIC_SIGDEF(IO,22,"I/O possible")
__BIONIC_SIGDEF(STOP,23,"Stopped (signal)")
__BIONIC_SIGDEF(TSTP,24,"Stopped")
__BIONIC_SIGDEF(CONT,25,"Continue")
__BIONIC_SIGDEF(TTIN,26,"Stopped (tty input)")
__BIONIC_SIGDEF(TTOU,27,"Stopped (tty output)")
__BIONIC_SIGDEF(VTALRM,28,"Virtual timer expired")
__BIONIC_SIGDEF(PROF,29,"Profiling timer expired")
__BIONIC_SIGDEF(XCPU,30,"CPU time limit exceeded")
__BIONIC_SIGDEF(XFSZ,31,"File size limit exceeded")
#else
__BIONIC_SIGDEF(STKFLT,16,"Stack fault")
__BIONIC_SIGDEF(CHLD,17,"Child exited")
__BIONIC_SIGDEF(CONT,18,"Continue")
__BIONIC_SIGDEF(STOP,19,"Stopped (signal)")
__BIONIC_SIGDEF(TSTP,20,"Stopped")
__BIONIC_SIGDEF(TTIN,21,"Stopped (tty input)")
__BIONIC_SIGDEF(TTOU,22,"Stopped (tty output)")
__BIONIC_SIGDEF(URG,23,"Urgent I/O condition")
__BIONIC_SIGDEF(XCPU,24,"CPU time limit exceeded")
__BIONIC_SIGDEF(XFSZ,25,"File size limit exceeded")
__BIONIC_SIGDEF(VTALRM,26,"Virtual timer expired")
__BIONIC_SIGDEF(PROF,27,"Profiling timer expired")
__BIONIC_SIGDEF(WINCH,28,"Window size changed")
__BIONIC_SIGDEF(IO,29,"I/O possible")
__BIONIC_SIGDEF(PWR,30,"Power failure")
__BIONIC_SIGDEF(SYS,31,"Bad system call")
__BIONIC_SIGDEF(SIGFPE, "Floating point exception")
__BIONIC_SIGDEF(SIGKILL, "Killed")
__BIONIC_SIGDEF(SIGBUS, "Bus error")
__BIONIC_SIGDEF(SIGSEGV, "Segmentation fault")
__BIONIC_SIGDEF(SIGPIPE, "Broken pipe")
__BIONIC_SIGDEF(SIGALRM, "Alarm clock")
__BIONIC_SIGDEF(SIGTERM, "Terminated")
__BIONIC_SIGDEF(SIGUSR1, "User signal 1")
__BIONIC_SIGDEF(SIGUSR2, "User signal 2")
__BIONIC_SIGDEF(SIGCHLD, "Child exited")
__BIONIC_SIGDEF(SIGPWR, "Power failure")
__BIONIC_SIGDEF(SIGWINCH, "Window size changed")
__BIONIC_SIGDEF(SIGURG, "Urgent I/O condition")
__BIONIC_SIGDEF(SIGIO, "I/O possible")
__BIONIC_SIGDEF(SIGSTOP, "Stopped (signal)")
__BIONIC_SIGDEF(SIGTSTP, "Stopped")
__BIONIC_SIGDEF(SIGCONT, "Continue")
__BIONIC_SIGDEF(SIGTTIN, "Stopped (tty input)")
__BIONIC_SIGDEF(SIGTTOU, "Stopped (tty output)")
__BIONIC_SIGDEF(SIGVTALRM, "Virtual timer expired")
__BIONIC_SIGDEF(SIGPROF, "Profiling timer expired")
__BIONIC_SIGDEF(SIGXCPU, "CPU time limit exceeded")
__BIONIC_SIGDEF(SIGXFSZ, "File size limit exceeded")
#if defined(SIGSTKFLT)
__BIONIC_SIGDEF(SIGSTKFLT, "Stack fault")
#endif
__BIONIC_SIGDEF(SIGSYS, "Bad system call")
#undef __BIONIC_SIGDEF

View file

@ -238,3 +238,17 @@ TEST(signal, sigaction) {
// Put everything back how it was.
ASSERT_EQ(0, sigaction(SIGALRM, &original_sa, NULL));
}
TEST(signal, sys_signame) {
#if defined(__BIONIC__) && !defined(__LP64__)
ASSERT_TRUE(sys_signame[0] == NULL);
ASSERT_STREQ("HUP", sys_signame[SIGHUP]);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
TEST(signal, sys_siglist) {
ASSERT_TRUE(sys_siglist[0] == NULL);
ASSERT_STREQ("Hangup", sys_siglist[SIGHUP]);
}