From aa0ebdafc71e1ceac78e0929b94f3bb117d0c8e9 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 11 Feb 2014 19:57:06 -0800 Subject: 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/siglist.c | 33 ----------- libc/bionic/signame.c | 33 ----------- libc/bionic/strerror_r.cpp | 2 +- libc/bionic/sys_siglist.c | 34 ++++++++++++ libc/bionic/sys_signame.c | 38 +++++++++++++ libc/include/signal.h | 2 + libc/include/sys/_sigdefs.h | 94 ++++++++++++------------------- tests/signal_test.cpp | 14 +++++ 9 files changed, 189 insertions(+), 193 deletions(-) delete mode 100644 libc/bionic/siglist.c delete mode 100644 libc/bionic/signame.c create mode 100644 libc/bionic/sys_siglist.c create mode 100644 libc/bionic/sys_signame.c diff --git a/libc/Android.mk b/libc/Android.mk index 79acce8..3aced4e 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/siglist.c b/libc/bionic/siglist.c deleted file mode 100644 index f1c3377..0000000 --- a/libc/bionic/siglist.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * 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. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 - * COPYRIGHT OWNER 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. - */ -#include - -const char * const sys_siglist[NSIG] = { -#define __BIONIC_SIGDEF(x,y,z) [ SIG##x ] = z, -#include -}; diff --git a/libc/bionic/signame.c b/libc/bionic/signame.c deleted file mode 100644 index 4611e44..0000000 --- a/libc/bionic/signame.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * 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. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 - * COPYRIGHT OWNER 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. - */ -#include - -const char * const sys_signame[NSIG] = { -#define __BIONIC_SIGDEF(x,y,z) [ SIG##x ] = #x, -#include -}; diff --git a/libc/bionic/strerror_r.cpp b/libc/bionic/strerror_r.cpp index 81120ec..5f2d362 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/sys_siglist.c b/libc/bionic/sys_siglist.c new file mode 100644 index 0000000..3cfddbf --- /dev/null +++ b/libc/bionic/sys_siglist.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * 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. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 + * COPYRIGHT OWNER 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. + */ + +#include + +const char* const sys_siglist[NSIG] = { +#define __BIONIC_SIGDEF(signal_number, signal_description) [ signal_number ] = signal_description, +#include +}; diff --git a/libc/bionic/sys_signame.c b/libc/bionic/sys_signame.c new file mode 100644 index 0000000..41d34af --- /dev/null +++ b/libc/bionic/sys_signame.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * 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. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 + * COPYRIGHT OWNER 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. + */ + +#include + +#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 c01b33a..58288a1 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 eadf7b9..44d60d9 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 a7e5b9a..ea3096a 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]); +} -- cgit v1.1