[PATCH 1/2] tests: add signal2name function to libtests

Fei, Jie/费 杰 feij.fnst at cn.fujitsu.com
Mon Jun 13 01:27:41 UTC 2016


Hi all,

This is the v3 patch, how about it?
I would appreciate it if you could give me a bit of advice.

On 05/31/2016 02:13 PM, Fei Jie wrote:
> * tests/tests.h (signal2name): New prototype.
> * tests/signal2name.c: New file.
> * tests/Makefile.am (libtests_a_SOURCES): Add it.
> ---
>   tests/Makefile.am   |   1 +
>   tests/signal2name.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>   tests/tests.h       |   3 ++
>   3 files changed, 129 insertions(+)
>   create mode 100644 tests/signal2name.c
>
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 9eba306..ac527ec 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -51,6 +51,7 @@ libtests_a_SOURCES = \
>   	print_quoted_string.c \
>   	printflags.c \
>   	printxval.c \
> +	signal2name.c \
>   	tail_alloc.c \
>   	tests.h \
>   	tprintf.c \
> diff --git a/tests/signal2name.c b/tests/signal2name.c
> new file mode 100644
> index 0000000..906e821
> --- /dev/null
> +++ b/tests/signal2name.c
> @@ -0,0 +1,125 @@
> +#include "tests.h"
> +#include <signal.h>
> +
> +#define CASE(x) case x: return #x
> +
> +const char *
> +signal2name(int sig)
> +{
> +	switch (sig) {
> +#ifdef SIGALRM
> +	CASE(SIGALRM);
> +#endif
> +#ifdef SIGBUS
> +	CASE(SIGBUS);
> +#endif
> +#ifdef SIGCHLD
> +	CASE(SIGCHLD);
> +#endif
> +#ifdef SIGCONT
> +	CASE(SIGCONT);
> +#endif
> +#ifdef SIGFPE
> +	CASE(SIGFPE);
> +#endif
> +#ifdef SIGHUP
> +	CASE(SIGHUP);
> +#endif
> +#ifdef SIGILL
> +	CASE(SIGILL);
> +#endif
> +#ifdef SIGINT
> +	CASE(SIGINT);
> +#endif
> +#ifdef SIGIO
> +	CASE(SIGIO);
> +#endif
> +#ifdef SIGPIPE
> +	CASE(SIGPIPE);
> +#endif
> +#ifdef SIGPROF
> +	CASE(SIGPROF);
> +#endif
> +#ifdef SIGQUIT
> +	CASE(SIGQUIT);
> +#endif
> +#ifdef SIGSEGV
> +	CASE(SIGSEGV);
> +#endif
> +#ifdef SIGSYS
> +	CASE(SIGSYS);
> +#endif
> +#ifdef SIGTERM
> +	CASE(SIGTERM);
> +#endif
> +#ifdef SIGTRAP
> +	CASE(SIGTRAP);
> +#endif
> +#ifdef SIGTSTP
> +	CASE(SIGTSTP);
> +#endif
> +#ifdef SIGTTIN
> +	CASE(SIGTTIN);
> +#endif
> +#ifdef SIGTTOU
> +	CASE(SIGTTOU);
> +#endif
> +#ifdef SIGURG
> +	CASE(SIGURG);
> +#endif
> +#ifdef SIGUSR1
> +	CASE(SIGUSR1);
> +#endif
> +#ifdef SIGUSR2
> +	CASE(SIGUSR2);
> +#endif
> +#ifdef SIGVTALRM
> +	CASE(SIGVTALRM);
> +#endif
> +#ifdef SIGWINCH
> +	CASE(SIGWINCH);
> +#endif
> +#ifdef SIGXCPU
> +	CASE(SIGXCPU);
> +#endif
> +#ifdef SIGXFSZ
> +	CASE(SIGXFSZ);
> +#endif
> +#if !defined MIPS
> +# ifdef SIGABRT
> +	CASE(SIGABRT);
> +# endif
> +#endif
> +#if defined ALPHA || defined MIPS || defined SPARC
> +# ifdef SIGEMT
> +	CASE(SIGEMT);
> +# endif
> +#endif
> +#ifdef ALPHA
> +# ifdef SIGINFO
> +	CASE(SIGINFO);
> +# endif
> +#endif
> +#ifdef MIPS
> +# ifdef SIGIOT
> +	CASE(SIGIOT);
> +# endif
> +#endif
> +#ifdef SPARC
> +# ifdef SIGLOST
> +	CASE(SIGLOST);
> +# endif
> +#endif
> +#if !defined ALPHA && !defined SPARC
> +# ifdef SIGPWR
> +	CASE(SIGPWR);
> +# endif
> +#endif
> +#if !defined ALPHA && !defined SPARC && !defined MIPS
> +# ifdef SIGSTKFLT
> +	CASE(SIGSTKFLT);
> +# endif
> +#endif
> +	default: perror_msg_and_fail("unknown signal number %d", sig);
> +	}
> +}
> diff --git a/tests/tests.h b/tests/tests.h
> index 0205ea0..c140830 100644
> --- a/tests/tests.h
> +++ b/tests/tests.h
> @@ -93,6 +93,9 @@ void check_overflowgid(const int);
>   /* Translate errno to its name. */
>   const char *errno2name(void);
>   
> +/* Translate signal number to its name. */
> +const char *signal2name(int);
> +
>   struct xlat;
>   
>   /* Print flags in symbolic form according to xlat table. */

-- 
Thanks!
Fei Jie







More information about the Strace-devel mailing list