From aa0ebdafc71e1ceac78e0929b94f3bb117d0c8e9 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 11 Feb 2014 19:57:06 -0800 Subject: [PATCH] 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 --- libc/Android.mk | 132 +++++++++++++++---------------- libc/bionic/strerror_r.cpp | 2 +- libc/bionic/{siglist.c => sys_siglist.c} | 5 +- libc/bionic/{signame.c => sys_signame.c} | 9 ++- libc/include/signal.h | 2 + libc/include/sys/_sigdefs.h | 94 ++++++++-------------- tests/signal_test.cpp | 14 ++++ 7 files changed, 127 insertions(+), 131 deletions(-) rename libc/bionic/{siglist.c => sys_siglist.c} (91%) rename libc/bionic/{signame.c => sys_signame.c} (90%) diff --git a/libc/Android.mk b/libc/Android.mk index 79acce8c9..3aced4e80 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -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 \ diff --git a/libc/bionic/strerror_r.cpp b/libc/bionic/strerror_r.cpp index 81120ecd3..5f2d36214 100644 --- a/libc/bionic/strerror_r.cpp +++ b/libc/bionic/strerror_r.cpp @@ -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 { 0, NULL } }; diff --git a/libc/bionic/siglist.c b/libc/bionic/sys_siglist.c similarity index 91% rename from libc/bionic/siglist.c rename to libc/bionic/sys_siglist.c index f1c337785..3cfddbfc4 100644 --- a/libc/bionic/siglist.c +++ b/libc/bionic/sys_siglist.c @@ -25,9 +25,10 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + #include -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 }; diff --git a/libc/bionic/signame.c b/libc/bionic/sys_signame.c similarity index 90% rename from libc/bionic/signame.c rename to libc/bionic/sys_signame.c index 4611e4448..41d34af83 100644 --- a/libc/bionic/signame.c +++ b/libc/bionic/sys_signame.c @@ -25,9 +25,14 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + #include -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 }; + +#endif diff --git a/libc/include/signal.h b/libc/include/signal.h index c01b33a45..58288a103 100644 --- a/libc/include/signal.h +++ b/libc/include/signal.h @@ -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. */ diff --git a/libc/include/sys/_sigdefs.h b/libc/include/sys/_sigdefs.h index eadf7b987..44d60d973 100644 --- a/libc/include/sys/_sigdefs.h +++ b/libc/include/sys/_sigdefs.h @@ -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 diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp index a7e5b9aff..ea3096a5d 100644 --- a/tests/signal_test.cpp +++ b/tests/signal_test.cpp @@ -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]); +} -- 2.11.0