Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

run-time sanity check for bogus signames.h?



This patch prevents hang-ups when signames.h wasn't properly produced.

Poor guys who have their SIGxxx definitions in unusual places shouldn't
be left with a shell which hangs silently when the first signal is
encountered. Like me, under Linux 1.3.x. Of course we are encouraged to
examine configure's output. But this isn't bullet-proof. 
 
The overhead involved for run-time out-of-bounds checks should be
negligible. The alternative compile-time check doesn't seem feasible,
since it wouldn't be easy to detect partly generated signames arrays.
Can NSIG be relied upon?

Astonishingly, all the code dealing with short signames (sigs[])
looks pretty sensible of this problem.


*** jobs.c.orig	Sat Jul  1 00:06:22 1995
--- jobs.c	Sat Jul 15 06:42:50 1995
***************
*** 218,224 ****
  	if (pn->status != SP_RUNNING)
  	    if (WIFSIGNALED(pn->status)) {
  		sig = WTERMSIG(pn->status);
! 		llen = strlen(sigmsg[sig]);
  		if (WCOREDUMP(pn->status))
  		    llen += 14;
  		if (llen > len)
--- 218,224 ----
  	if (pn->status != SP_RUNNING)
  	    if (WIFSIGNALED(pn->status)) {
  		sig = WTERMSIG(pn->status);
! 		llen = sig < SIGCOUNT+2 ? strlen(sigmsg[sig]) : 0;
  		if (WCOREDUMP(pn->status))
  		    llen += 14;
  		if (llen > len)
***************
*** 231,237 ****
  		    doputnl = 1;
  	    } else if (WIFSTOPPED(pn->status)) {
  		sig = WSTOPSIG(pn->status);
! 		if ((int)strlen(sigmsg[sig]) > len)
  		    len = strlen(sigmsg[sig]);
  		if (job == thisjob && sig == SIGTSTP)
  		    doputnl = 1;
--- 231,237 ----
  		    doputnl = 1;
  	    } else if (WIFSTOPPED(pn->status)) {
  		sig = WSTOPSIG(pn->status);
! 		if(sig < SIGCOUNT+2 && strlen(sigmsg[sig]) > len)
  		    len = strlen(sigmsg[sig]);
  		if (job == thisjob && sig == SIGTSTP)
  		    doputnl = 1;
***************
*** 297,310 ****
  			    len - 9 + 2, "");
  		else
  		    fprintf(stderr, "done%*s", len - 4 + 2, "");
! 	    else if (WIFSTOPPED(pn->status))
! 		fprintf(stderr, "%-*s", len + 2, sigmsg[WSTOPSIG(pn->status)]);
! 	    else if (WCOREDUMP(pn->status))
! 		fprintf(stderr, "%s (core dumped)%*s",
! 			sigmsg[WTERMSIG(pn->status)],
! 			(int)(len - 14 + 2 - strlen(sigmsg[WTERMSIG(pn->status)])), "");
! 	    else
! 		fprintf(stderr, "%-*s", len + 2, sigmsg[WTERMSIG(pn->status)]);
  	    for (; pn != qn; pn = pn->next)
  		fprintf(stderr, (pn->next) ? "%s | " : "%s", pn->text);
  	    putc('\n', stderr);
--- 297,317 ----
  			    len - 9 + 2, "");
  		else
  		    fprintf(stderr, "done%*s", len - 4 + 2, "");
! 	    else {
! 		char * signame = "";
! 
! 		if((sig = WIFSTOPPED(pn->status) ? WSTOPSIG(pn->status) :
! 		    WTERMSIG(pn->status)) < SIGCOUNT+2)
! 		    signame = sigmsg[sig];
! 
! 		if (WIFSTOPPED(pn->status))
! 		    fprintf(stderr, "%-*s", len + 2, signame);
! 		else if (WCOREDUMP(pn->status))
! 		    fprintf(stderr, "%s (core dumped)%*s", signame,
! 			    (int)(len - 14 + 2 - strlen(signame)), "");
! 		else
! 		    fprintf(stderr, "%-*s", len + 2, signame);
! 	    }
  	    for (; pn != qn; pn = pn->next)
  		fprintf(stderr, (pn->next) ? "%s | " : "%s", pn->text);
  	    putc('\n', stderr);
-- 
Thorsten Meinecke
<kaefer@xxxxxxxxxxxxxxx>



Messages sorted by: Reverse Date, Date, Thread, Author