From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gatech.edu (gatech.edu [130.207.244.244]) by werple.mira.net.au (8.6.12/8.6.9) with SMTP id QAA05009 for ; Sat, 15 Jul 1995 16:26:39 +1000 Received: from math (math.skiles.gatech.edu) by gatech.edu with SMTP id AA08484 (5.65c/Gatech-10.0-IDA for ); Sat, 15 Jul 1995 02:27:09 -0400 Received: by math (5.x/SMI-SVR4) id AA15868; Sat, 15 Jul 1995 02:23:33 -0400 Resent-Date: Sat, 15 Jul 1995 08:19:49 +0200 (MET DST) Old-Return-Path: Message-Id: Subject: run-time sanity check for bogus signames.h? To: zsh-workers@math.gatech.edu Date: Sat, 15 Jul 1995 08:19:49 +0200 (MET DST) From: Thorsten Meinecke Organization: none. Location: Berlin, Germany X-Mailer: ELM [version 2.4 PL23] Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Resent-Message-Id: <"0KZiH.0.st3.axr1m"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/210 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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