Hi!

----

Attached (as "astksh20130807_sigmax001.diff.txt") is a patch which
fixes some issues related to |shgd->sigmax| handling.
Originally |shgd->sigmax| counted the signals from "|0| -
|shgd->sigmax|" but later this was changed incrementally over months
to "|0| - |shgd->sigmax-1|". The patch unifies&&fixes the logic (and
fixes SIGRTMAX users; but note that "valgrind" uses some realtime
signals for it's own usage... see
http://article.gmane.org/gmane.comp.debugging.valgrind.devel/23869).

* Fixed bugs:
1. The following valgrind hit on SuSE 12.3/AMD64/64bitis fixed:
-- snip --
==44984== Warning: ignored attempt to set SIGRT32 handler in sigaction();
==44984==          the SIGRT32 signal is used internally by Valgrind
==44984== Conditional jump or move depends on uninitialised value(s)
==44984==    at 0x414910: sh_sigtrap (fault.c:318)
==44984==    by 0x48BB46: b_trap (trap.c:170)
==44984==    by 0x468E00: sh_exec (xec.c:1360)
==44984==    by 0x46BEA6: sh_exec (xec.c:2223)
==44984==    by 0x40F502: exfile (main.c:603)
==44984==    by 0x40E74D: sh_main (main.c:375)
==44984==    by 0x40D920: main (pmain.c:45)
-- snip --

2. SIGRTMAX traps now work stable and no longer have weired "works,
works not, works, works not" issues between runs (this is likely
related to signal storms and [3] below)

3. |shp->siginfo| is no longer allocated on demand in the signal
handler, removing a possible race condition (see [2] above) and other
related mess (yes... I know... consumes more memory by default... but
better "safe than sorry" in the case of signals... we can re-optimise
it later again when signals are stable...)

4. The mysterious signal SIG65 (SIGRTMAX+1) on Linux is now gone

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
diff -r -u original/src/cmd/ksh93/bltins/cflow.c 
build_sigmax/src/cmd/ksh93/bltins/cflow.c
--- src/cmd/ksh93/bltins/cflow.c        2012-08-03 20:41:32.000000000 +0200
+++ src/cmd/ksh93/bltins/cflow.c        2013-08-09 18:03:51.538495834 +0200
@@ -65,7 +65,7 @@
        pp->mode = (**argv=='e'?SH_JMPEXIT:SH_JMPFUN);
        argv += opt_info.index;
        n = (((arg= *argv)?(int)strtol(arg, (char**)0, 10):shp->oldexit));
-       if(n<0 || n==256 || n > SH_EXITMASK+shp->gd->sigmax+1)
+       if(n<0 || n==256 || n > (SH_EXITMASK+shp->gd->sigmax))
                        n &= ((unsigned int)n)&SH_EXITMASK;
        /* return outside of function, dotscript and profile is exit */
        if(shp->fn_depth==0 && shp->dot_depth==0 && !sh_isstate(shp,SH_PROFILE))
diff -r -u original/src/cmd/ksh93/bltins/trap.c 
build_sigmax/src/cmd/ksh93/bltins/trap.c
--- src/cmd/ksh93/bltins/trap.c 2013-08-02 20:50:23.000000000 +0200
+++ src/cmd/ksh93/bltins/trap.c 2013-08-09 18:06:25.956814669 +0200
@@ -144,7 +144,7 @@
                                        free(arg);
                                continue;
                        }
-                       if(sig>shp->gd->sigmax)
+                       if(sig>=shp->gd->sigmax)
                        {
                                errormsg(SH_DICT,2,e_trap,arg);
                                return(1);
@@ -261,7 +261,7 @@
        }
        if(flag&S_FLAG)
        {
-               if((sig=sig_number(shp,signame)) < 0 || sig > shp->gd->sigmax)
+               if(((sig=sig_number(shp,signame)) < 0) || (sig >= 
shp->gd->sigmax))
                {
                        shp->exitval = 2;
                        errormsg(SH_DICT,ERROR_exit(1),e_nosignal,signame);
diff -r -u original/src/cmd/ksh93/sh/fault.c 
build_sigmax/src/cmd/ksh93/sh/fault.c
--- src/cmd/ksh93/sh/fault.c    2013-08-02 19:21:24.000000000 +0200
+++ src/cmd/ksh93/sh/fault.c    2013-08-09 18:18:13.520584040 +0200
@@ -182,7 +182,7 @@
                        }
                        /* mark signal and continue */
                        shp->trapnote |= SH_SIGSET;
-                       if(sig <= shp->gd->sigmax)
+                       if(sig < shp->gd->sigmax)
                                shp->sigflag[sig] |= SH_SIGSET;
 #if  defined(VMFL) && (VMALLOC_VERSION>=20031205L)
                        if(abortsig(sig))
@@ -238,7 +238,7 @@
        if(flag&(SH_SIGSET|SH_SIGTRAP))
                astserial(AST_SERIAL_RESTART, AST_SERIAL_except);
 #endif
-       if(sig <= shp->gd->sigmax)
+       if(sig < shp->gd->sigmax)
                shp->sigflag[sig] |= flag;
        if(pp->mode==SH_JMPCMD && sh_isstate(shp,SH_STOPOK))
        {
@@ -283,10 +283,12 @@
        shp->st.trapcom = (char**)calloc(n,sizeof(char*));
        shp->sigflag = (unsigned char*)calloc(n,sizeof(char));
        shp->gd->sigmsg = (char**)calloc(n,sizeof(char*));
+       shp->siginfo = (void**)calloc(sizeof(void*),shp->gd->sigmax);
+
        for(tp=shtab_signals; sig=tp->sh_number; tp++)
        {
                n = (sig>>SH_SIGBITS);
-               if((sig &= ((1<<SH_SIGBITS)-1)) > (shp->gd->sigmax+1))
+               if((sig &= ((1<<SH_SIGBITS)-1)) >= shp->gd->sigmax)
                        continue;
                sig--;
                if(n&SH_SIGRUNTIME)
@@ -320,8 +322,6 @@
                }
                else
                {
-                       if(!shp->siginfo)
-                               shp->siginfo = 
(void**)calloc(sizeof(void*),shp->gd->sigmax);
                        flag |= SH_SIGFAULT;
                        if(sig==SIGALRM && fun!=SIG_DFL && 
fun!=(sh_sigfun_t)sh_fault)
                                signal(sig,fun);
@@ -336,9 +336,10 @@
  */
 void   sh_sigdone(Shell_t *shp)
 {
-       register int    flag, sig = shgd->sigmax;
+       unsigned char   flag;
+       int             sig;
        shp->sigflag[0] |= SH_SIGFAULT;
-       for(sig=shgd->sigmax; sig>0; sig--)
+       for(sig=shgd->sigmax-1 ; sig>=0 ; sig--)
        {
                flag = shp->sigflag[sig];
                if((flag&(SH_SIGDONE|SH_SIGIGNORE|SH_SIGINTERACTIVE)) && 
!(flag&(SH_SIGFAULT|SH_SIGOFF)))
@@ -758,7 +759,7 @@
        if(flag<=0)
        {
                /* not all signals may be defined, so initialize */
-               for(sig=shp->gd->sigmax; sig>=0; sig--)
+               for(sig=shp->gd->sigmax-1; sig>=0; sig--)
                        names[sig] = 0;
                for(sig=SH_DEBUGTRAP; sig>=0; sig--)
                        traps[sig] = 0;
@@ -791,7 +792,7 @@
                {
                        if(!(trap=trapcom[sig]))
                                continue;
-                       if(sig > shp->gd->sigmax || !(sname=(char*)names[sig]))
+                       if(sig >= shp->gd->sigmax || !(sname=(char*)names[sig]))
                                sname = sig_name(shp,sig,name,1);
                        sfprintf(iop,trapfmt,sh_fmtq(trap),sname);
                }
@@ -805,7 +806,7 @@
        else
        {
                /* print all the signal names */
-               for(sig=1; sig <= shp->gd->sigmax; sig++)
+               for(sig=1; sig < shp->gd->sigmax; sig++)
                {
                        if(!(sname=(char*)names[sig]))
                        {
diff -r -u original/src/cmd/ksh93/sh/jobs.c build_sigmax/src/cmd/ksh93/sh/jobs.c
--- src/cmd/ksh93/sh/jobs.c     2013-07-17 18:22:06.000000000 +0200
+++ src/cmd/ksh93/sh/jobs.c     2013-08-09 18:04:27.976348098 +0200
@@ -1996,7 +1996,7 @@
 static char *job_sigmsg(Shell_t *shp,int sig)
 {
        static char signo[40];
-       if(sig<=shgd->sigmax && shgd->sigmsg[sig])
+       if(sig<shgd->sigmax && shgd->sigmsg[sig])
                return(shgd->sigmsg[sig]);
 #if defined(SIGRTMIN) && defined(SIGRTMAX)
        if(sig>=shp->gd->sigruntime[SH_SIGRTMIN] && 
sig<=shp->gd->sigruntime[SH_SIGRTMAX])
diff -r -u original/src/cmd/ksh93/sh/timers.c 
build_sigmax/src/cmd/ksh93/sh/timers.c
--- src/cmd/ksh93/sh/timers.c   2012-08-08 18:57:52.000000000 +0200
+++ src/cmd/ksh93/sh/timers.c   2013-08-09 18:04:51.724857872 +0200
@@ -97,8 +97,6 @@
        Shell_t *shp = sh_getinterp();
        if(shp->st.trapcom[SIGALRM] && *shp->st.trapcom[SIGALRM])
        {
-               if(!shp->siginfo)
-                       shp->siginfo = 
(void**)calloc(sizeof(void*),shp->gd->sigmax);
                shp->siginfo[SIGALRM] = malloc(sizeof(siginfo_t));
                memcpy(shp->siginfo[SIGALRM],context,sizeof(siginfo_t));
        }
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers

Reply via email to