From: Martin Mares Date: Wed, 18 Jul 2012 09:12:12 +0000 (+0200) Subject: Signals: Added a module with a list of signals X-Git-Tag: v5.99~151 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=923365eb001011e77a79447fbc84b513f6bf4e95;p=libucw.git Signals: Added a module with a list of signals --- diff --git a/ucw/Makefile b/ucw/Makefile index f6cab5f1..75b9c463 100644 --- a/ucw/Makefile +++ b/ucw/Makefile @@ -34,7 +34,8 @@ LIBUCW_MODS= \ getopt \ strtonum \ resource trans res-fd res-mem res-subpool res-mempool res-eltpool \ - daemon daemon-ctrl + daemon daemon-ctrl \ + signames LIBUCW_MAIN_INCLUDES= \ lib.h log.h threads.h time.h \ @@ -61,7 +62,8 @@ LIBUCW_MAIN_INCLUDES= \ partmap.h \ strtonum.h \ resource.h trans.h \ - daemon.h + daemon.h \ + signames.h ifdef CONFIG_UCW_THREADS # Some modules require threading diff --git a/ucw/signames.c b/ucw/signames.c new file mode 100644 index 00000000..84276fd6 --- /dev/null +++ b/ucw/signames.c @@ -0,0 +1,170 @@ +/* + * A List of Signal Names + * + * (c) 2012 Martin Mares + */ + +#include +#include + +#include +#include +#include + +struct sig_name { + const char name[11]; + byte number; +}; + +#define S(sig) { #sig, sig } + +static const struct sig_name sig_names[] = { +#ifdef SIGABRT + S(SIGABRT), +#endif +#ifdef SIGALRM + S(SIGALRM), +#endif +#ifdef SIGBUS + S(SIGBUS), +#endif +#ifdef SIGCHLD + S(SIGCHLD), +#endif +#ifdef SIGCONT + S(SIGCONT), +#endif +#ifdef SIGFPE + S(SIGFPE), +#endif +#ifdef SIGHUP + S(SIGHUP), +#endif +#ifdef SIGILL + S(SIGILL), +#endif +#ifdef SIGINT + S(SIGINT), +#endif +#ifdef SIGIO + S(SIGIO), +#endif +#ifdef SIGIOT + S(SIGIOT), +#endif +#ifdef SIGKILL + S(SIGKILL), +#endif +#ifdef SIGPIPE + S(SIGPIPE), +#endif +#ifdef SIGPOLL + S(SIGPOLL), +#endif +#ifdef SIGPROF + S(SIGPROF), +#endif +#ifdef SIGPWR + S(SIGPWR), +#endif +#ifdef SIGQUIT + S(SIGQUIT), +#endif +#ifdef SIGSEGV + S(SIGSEGV), +#endif +#ifdef SIGSTKFLT + S(SIGSTKFLT), +#endif +#ifdef SIGSTOP + S(SIGSTOP), +#endif +#ifdef SIGSYS + S(SIGSYS), +#endif +#ifdef SIGTERM + S(SIGTERM), +#endif +#ifdef SIGTRAP + S(SIGTRAP), +#endif +#ifdef SIGTSTP + S(SIGTSTP), +#endif +#ifdef SIGTTIN + S(SIGTTIN), +#endif +#ifdef SIGTTOU + S(SIGTTOU), +#endif +#ifdef SIGURG + S(SIGURG), +#endif +#ifdef SIGUSR1 + S(SIGUSR1), +#endif +#ifdef SIGUSR2 + S(SIGUSR2), +#endif +#ifdef SIGVTALRM + S(SIGVTALRM), +#endif +#ifdef SIGWINCH + S(SIGWINCH), +#endif +#ifdef SIGXCPU + S(SIGXCPU), +#endif +#ifdef SIGXFSZ + S(SIGXFSZ), +#endif +}; + +int +sig_name_to_number(const char *name) +{ + for (uns i=0; i < ARRAY_SIZE(sig_names); i++) + if (!strcmp(sig_names[i].name, name)) + return sig_names[i].number; + return -1; +} + +const char * +sig_number_to_name(int number) +{ + for (uns i=0; i < ARRAY_SIZE(sig_names); i++) + if (sig_names[i].number == number) + return sig_names[i].name; + return NULL; +} + +#ifdef TEST + +#include + +int main(void) +{ + char c[256]; + while (fgets(c, sizeof(c), stdin)) + { + char *e = strchr(c, '\n'); + if (e) + *e = 0; + if (c[0] == '#') + { + const char *name = sig_number_to_name(atoi(c+1)); + puts(name ? : "?"); + } + else + { + int num = sig_name_to_number(c); + if (num < 0) + puts("?"); + else + printf("%d\n", num); + } + } + return 0; +} + +#endif diff --git a/ucw/signames.h b/ucw/signames.h new file mode 100644 index 00000000..d7b9cac7 --- /dev/null +++ b/ucw/signames.h @@ -0,0 +1,14 @@ +/* + * A List of Signal Names + * + * (c) 2012 Martin Mares + */ + +#ifndef _UCW_SIGNAMES_H +#define _UCW_SIGNAMES_H + +int sig_name_to_number(const char *name); + +const char *sig_number_to_name(int number); + +#endif