Roland Mainz
2013-07-31 14:04:54 UTC
Hi!
----
Attached (as "astksh20130727_shsig_name001.diff.txt") is a patch which
tries to improve the handling of .sh.sig.code.
* Changes:
- .sh.sig.code now supports all |CLD_*| |si_code| names (|CLD_TRAPPED|
was missing)
- .sh.sig.code now supports the generic SI_* names for |si_code|
defined in http://pubs.opengroup.org/onlinepubs/009696699/basedefs/signal.h.html
and the extensions defined by { Solaris, Linux, FreeBSD }. For
example:
-- snip --
$ ksh -c 'trap "printf \"%s;%s\n\" \"\${.sh.sig.name}\"
\"\${.sh.sig.code}\"" USR1 CHLD ; kill -USR1 $$ ; kill -q4 -USR1 $$ ;
true & wait ; true'
USR1;user
USR1;queue
CHLD;exited
-- snip --
(that becomes a bit more usefull with the extensions on Linux&&Solaris
etc. since it allows to distinguish between kernel-generated signals
and signals coming from an user. Another usage may be to distinguish
between signals created by dtrace, resource control facilities etc.)
- .sh.sig.code falls back to be a number if no string match has been found
- .sh.sig.code strings now come from a static table which can be
extended on demand (e.g. for SIGPOLL)
Comments/feedback/rants etc. welcome...
----
Bye,
Roland
P.S.: I didn't implement
http://lists.research.att.com/pipermail/ast-developers/2013q3/002953.html
yet since this needs to be discussed with David first...
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
-------------- next part --------------
diff -r -u original/src/cmd/ksh93/data/signals.c build_sigfixes/src/cmd/ksh93/data/signals.c
--- src/cmd/ksh93/data/signals.c 2012-04-23 20:20:54.000000000 +0200
+++ src/cmd/ksh93/data/signals.c 2013-07-31 02:48:17.238002402 +0200
@@ -245,3 +245,71 @@
#endif /* SIGRES */
"", 0, 0
};
+
+
+#ifdef _lib_sigaction
+const
+struct shtab_sigcodes shtab_siginfo_codes[] =
+{
+ { SIGCHLD, CLD_EXITED, "exited" },
+ { SIGCHLD, CLD_DUMPED, "dumped" },
+ { SIGCHLD, CLD_KILLED, "killed" },
+#ifdef CLD_STOPPED
+ { SIGCHLD, CLD_STOPPED, "stopped" },
+#endif
+#ifdef CLD_CONTINUED
+ { SIGCHLD, CLD_CONTINUED, "continued" },
+#endif
+#ifdef CLD_TRAPPED
+ { SIGCHLD, CLD_TRAPPED, "trapped" },
+#endif
+
+ /*
+ * entries with sig==0 must be at the end of the list
+ * to prevent possible clashes with signal-specific
+ * codes
+ */
+
+#ifdef SI_USER
+ { 0, SI_USER, "user" },
+#endif
+#ifdef SI_QUEUE
+ { 0, SI_QUEUE, "queue" },
+#endif
+#ifdef SI_TIMER
+ { 0, SI_TIMER, "timer" },
+#endif
+#ifdef SI_ASYNCIO
+ { 0, SI_ASYNCIO, "asyncio" },
+#endif
+#ifdef SI_MESGQ
+ { 0, SI_MESGQ, "mesgq" },
+#endif
+#ifdef SI_NOINFO
+ { 0, SI_NOINFO, "noinfo" },
+#endif
+#ifdef SI_DTRACE
+ { 0, SI_DTRACE, "dtrace" },
+#endif
+#ifdef SI_RCTL
+ { 0, SI_RCTL, "rctl" },
+#endif
+#ifdef SI_LWP
+ { 0, SI_LWP, "lwp" },
+#endif
+#ifdef SI_KERNEL
+ { 0, SI_KERNEL, "kernel" },
+#endif
+#ifdef SI_SIGIO
+ { 0, SI_SIGIO, "sigio" },
+#endif
+#ifdef SI_TKILL
+ { 0, SI_TKILL, "tkill" },
+#endif
+#ifdef SI_ASYNCNL
+ { 0, SI_ASYNCNL, "asyncnl" },
+#endif
+ { 0, 0, NULL },
+};
+#endif /* _lib_sigaction */
+
diff -r -u original/src/cmd/ksh93/include/shtable.h build_sigfixes/src/cmd/ksh93/include/shtable.h
--- src/cmd/ksh93/include/shtable.h 2012-01-10 20:03:22.000000000 +0100
+++ src/cmd/ksh93/include/shtable.h 2013-07-31 01:41:43.802566429 +0200
@@ -50,6 +50,15 @@
int (*sh_value)(int, char*[], Shbltin_t*);
};
+#ifdef _lib_sigaction
+struct shtab_sigcodes
+{
+ const int sig;
+ const int si_code;
+ const char *str;
+};
+#endif
+
#define sh_lookup(name,value) (sh_locate(name,(Shtable_t*)(value),sizeof(*(value)))->sh_number)
extern const Shtable_t shtab_testops[];
extern const Shtable_t shtab_options[];
@@ -59,6 +68,10 @@
extern const struct shtable2 shtab_signals[];
extern const struct shtable3 shtab_builtins[];
extern const Shtable_t shtab_reserved[];
+#ifdef _lib_sigaction
+extern const struct shtab_sigcodes shtab_siginfo_codes[];
+#endif
+
extern const Shtable_t *sh_locate(const char*, const Shtable_t*, int);
extern int sh_lookopt(const char*, int*);
diff -r -u original/src/cmd/ksh93/sh/init.c build_sigfixes/src/cmd/ksh93/sh/init.c
--- src/cmd/ksh93/sh/init.c 2013-07-22 16:43:07.000000000 +0200
+++ src/cmd/ksh93/sh/init.c 2013-07-31 02:07:16.064595489 +0200
@@ -2058,11 +2058,26 @@
svar_init(shp,SH_SIG,shtab_siginfo);
}
+
+static const char *siginfocode2str(int sig, int si_code)
+{
+ const struct shtab_sigcodes *sc;
+
+ for(sc = shtab_siginfo_codes ; sc->str != NULL ; sc++)
+ {
+ if(((sc->sig == sig) || (sc->sig == 0)) &&
+ (sc->si_code == si_code))
+ return(sc->str);
+ }
+ return(NULL);
+}
+
void sh_setsiginfo(siginfo_t *sip)
{
Namval_t *np;
Namfun_t *fp = SH_SIG->nvfun;
struct Svars *sp;
+ const char *sistr;
while(fp->disc->createf!=create_svar)
fp = fp->next;
if(!fp)
@@ -2080,19 +2095,10 @@
np = create_svar(SH_SIG,"uid",0, fp);
np->nvalue.idp = &sip->si_uid;
np = create_svar(SH_SIG,"code",0, fp);
- if(sip->si_signo==SIGCHLD)
+ if(sistr = siginfocode2str(sip->si_signo, sip->si_code))
{
nv_offattr(np,NV_INTEGER);
- if(sip->si_code==CLD_EXITED)
- np->nvalue.cp = "exited";
- else if(sip->si_code==CLD_DUMPED)
- np->nvalue.cp = "dumped";
- else if(sip->si_code==CLD_KILLED)
- np->nvalue.cp = "killed";
- else if(sip->si_code==CLD_STOPPED)
- np->nvalue.cp = "stopped";
- else
- np->nvalue.cp = "continued";
+ np->nvalue.cp = sistr;
nv_onattr(np,NV_NOFREE);
}
else
@@ -2108,7 +2114,7 @@
np = create_svar(SH_SIG,"value",0,fp);
np = create_svar(SH_SIG,"value.int",0,fp);
nv_setsize(np,10);
- np->nvalue.ip = (Sflong_t*)&(sip->si_value.sival_int);
+ np->nvalue.ip = &(sip->si_value.sival_int);
np = create_svar(SH_SIG,"value.ptr",0,fp);
nv_setsize(np,16);
np->nvalue.llp = (Sflong_t*)&(sip->si_value.sival_ptr);
----
Attached (as "astksh20130727_shsig_name001.diff.txt") is a patch which
tries to improve the handling of .sh.sig.code.
* Changes:
- .sh.sig.code now supports all |CLD_*| |si_code| names (|CLD_TRAPPED|
was missing)
- .sh.sig.code now supports the generic SI_* names for |si_code|
defined in http://pubs.opengroup.org/onlinepubs/009696699/basedefs/signal.h.html
and the extensions defined by { Solaris, Linux, FreeBSD }. For
example:
-- snip --
$ ksh -c 'trap "printf \"%s;%s\n\" \"\${.sh.sig.name}\"
\"\${.sh.sig.code}\"" USR1 CHLD ; kill -USR1 $$ ; kill -q4 -USR1 $$ ;
true & wait ; true'
USR1;user
USR1;queue
CHLD;exited
-- snip --
(that becomes a bit more usefull with the extensions on Linux&&Solaris
etc. since it allows to distinguish between kernel-generated signals
and signals coming from an user. Another usage may be to distinguish
between signals created by dtrace, resource control facilities etc.)
- .sh.sig.code falls back to be a number if no string match has been found
- .sh.sig.code strings now come from a static table which can be
extended on demand (e.g. for SIGPOLL)
Comments/feedback/rants etc. welcome...
----
Bye,
Roland
P.S.: I didn't implement
http://lists.research.att.com/pipermail/ast-developers/2013q3/002953.html
yet since this needs to be discussed with David first...
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
-------------- next part --------------
diff -r -u original/src/cmd/ksh93/data/signals.c build_sigfixes/src/cmd/ksh93/data/signals.c
--- src/cmd/ksh93/data/signals.c 2012-04-23 20:20:54.000000000 +0200
+++ src/cmd/ksh93/data/signals.c 2013-07-31 02:48:17.238002402 +0200
@@ -245,3 +245,71 @@
#endif /* SIGRES */
"", 0, 0
};
+
+
+#ifdef _lib_sigaction
+const
+struct shtab_sigcodes shtab_siginfo_codes[] =
+{
+ { SIGCHLD, CLD_EXITED, "exited" },
+ { SIGCHLD, CLD_DUMPED, "dumped" },
+ { SIGCHLD, CLD_KILLED, "killed" },
+#ifdef CLD_STOPPED
+ { SIGCHLD, CLD_STOPPED, "stopped" },
+#endif
+#ifdef CLD_CONTINUED
+ { SIGCHLD, CLD_CONTINUED, "continued" },
+#endif
+#ifdef CLD_TRAPPED
+ { SIGCHLD, CLD_TRAPPED, "trapped" },
+#endif
+
+ /*
+ * entries with sig==0 must be at the end of the list
+ * to prevent possible clashes with signal-specific
+ * codes
+ */
+
+#ifdef SI_USER
+ { 0, SI_USER, "user" },
+#endif
+#ifdef SI_QUEUE
+ { 0, SI_QUEUE, "queue" },
+#endif
+#ifdef SI_TIMER
+ { 0, SI_TIMER, "timer" },
+#endif
+#ifdef SI_ASYNCIO
+ { 0, SI_ASYNCIO, "asyncio" },
+#endif
+#ifdef SI_MESGQ
+ { 0, SI_MESGQ, "mesgq" },
+#endif
+#ifdef SI_NOINFO
+ { 0, SI_NOINFO, "noinfo" },
+#endif
+#ifdef SI_DTRACE
+ { 0, SI_DTRACE, "dtrace" },
+#endif
+#ifdef SI_RCTL
+ { 0, SI_RCTL, "rctl" },
+#endif
+#ifdef SI_LWP
+ { 0, SI_LWP, "lwp" },
+#endif
+#ifdef SI_KERNEL
+ { 0, SI_KERNEL, "kernel" },
+#endif
+#ifdef SI_SIGIO
+ { 0, SI_SIGIO, "sigio" },
+#endif
+#ifdef SI_TKILL
+ { 0, SI_TKILL, "tkill" },
+#endif
+#ifdef SI_ASYNCNL
+ { 0, SI_ASYNCNL, "asyncnl" },
+#endif
+ { 0, 0, NULL },
+};
+#endif /* _lib_sigaction */
+
diff -r -u original/src/cmd/ksh93/include/shtable.h build_sigfixes/src/cmd/ksh93/include/shtable.h
--- src/cmd/ksh93/include/shtable.h 2012-01-10 20:03:22.000000000 +0100
+++ src/cmd/ksh93/include/shtable.h 2013-07-31 01:41:43.802566429 +0200
@@ -50,6 +50,15 @@
int (*sh_value)(int, char*[], Shbltin_t*);
};
+#ifdef _lib_sigaction
+struct shtab_sigcodes
+{
+ const int sig;
+ const int si_code;
+ const char *str;
+};
+#endif
+
#define sh_lookup(name,value) (sh_locate(name,(Shtable_t*)(value),sizeof(*(value)))->sh_number)
extern const Shtable_t shtab_testops[];
extern const Shtable_t shtab_options[];
@@ -59,6 +68,10 @@
extern const struct shtable2 shtab_signals[];
extern const struct shtable3 shtab_builtins[];
extern const Shtable_t shtab_reserved[];
+#ifdef _lib_sigaction
+extern const struct shtab_sigcodes shtab_siginfo_codes[];
+#endif
+
extern const Shtable_t *sh_locate(const char*, const Shtable_t*, int);
extern int sh_lookopt(const char*, int*);
diff -r -u original/src/cmd/ksh93/sh/init.c build_sigfixes/src/cmd/ksh93/sh/init.c
--- src/cmd/ksh93/sh/init.c 2013-07-22 16:43:07.000000000 +0200
+++ src/cmd/ksh93/sh/init.c 2013-07-31 02:07:16.064595489 +0200
@@ -2058,11 +2058,26 @@
svar_init(shp,SH_SIG,shtab_siginfo);
}
+
+static const char *siginfocode2str(int sig, int si_code)
+{
+ const struct shtab_sigcodes *sc;
+
+ for(sc = shtab_siginfo_codes ; sc->str != NULL ; sc++)
+ {
+ if(((sc->sig == sig) || (sc->sig == 0)) &&
+ (sc->si_code == si_code))
+ return(sc->str);
+ }
+ return(NULL);
+}
+
void sh_setsiginfo(siginfo_t *sip)
{
Namval_t *np;
Namfun_t *fp = SH_SIG->nvfun;
struct Svars *sp;
+ const char *sistr;
while(fp->disc->createf!=create_svar)
fp = fp->next;
if(!fp)
@@ -2080,19 +2095,10 @@
np = create_svar(SH_SIG,"uid",0, fp);
np->nvalue.idp = &sip->si_uid;
np = create_svar(SH_SIG,"code",0, fp);
- if(sip->si_signo==SIGCHLD)
+ if(sistr = siginfocode2str(sip->si_signo, sip->si_code))
{
nv_offattr(np,NV_INTEGER);
- if(sip->si_code==CLD_EXITED)
- np->nvalue.cp = "exited";
- else if(sip->si_code==CLD_DUMPED)
- np->nvalue.cp = "dumped";
- else if(sip->si_code==CLD_KILLED)
- np->nvalue.cp = "killed";
- else if(sip->si_code==CLD_STOPPED)
- np->nvalue.cp = "stopped";
- else
- np->nvalue.cp = "continued";
+ np->nvalue.cp = sistr;
nv_onattr(np,NV_NOFREE);
}
else
@@ -2108,7 +2114,7 @@
np = create_svar(SH_SIG,"value",0,fp);
np = create_svar(SH_SIG,"value.int",0,fp);
nv_setsize(np,10);
- np->nvalue.ip = (Sflong_t*)&(sip->si_value.sival_int);
+ np->nvalue.ip = &(sip->si_value.sival_int);
np = create_svar(SH_SIG,"value.ptr",0,fp);
nv_setsize(np,16);
np->nvalue.llp = (Sflong_t*)&(sip->si_value.sival_ptr);