sh: Don't trust that signal descriptions fit within 49 bytes.

This commit is contained in:
jilles 2016-03-02 21:24:46 +00:00
parent b05c8d148a
commit 3583401113

View File

@ -322,8 +322,8 @@ static void
showjob(struct job *jp, int mode) showjob(struct job *jp, int mode)
{ {
char s[64]; char s[64];
char statestr[64]; char statebuf[16];
const char *sigstr; const char *statestr, *coredump;
struct procstat *ps; struct procstat *ps;
struct job *j; struct job *j;
int col, curr, i, jobno, prev, procno; int col, curr, i, jobno, prev, procno;
@ -339,9 +339,10 @@ showjob(struct job *jp, int mode)
prev = j - jobtab + 1; prev = j - jobtab + 1;
} }
#endif #endif
coredump = "";
ps = jp->ps + jp->nprocs - 1; ps = jp->ps + jp->nprocs - 1;
if (jp->state == 0) { if (jp->state == 0) {
strcpy(statestr, "Running"); statestr = "Running";
#if JOBS #if JOBS
} else if (jp->state == JOBSTOPPED) { } else if (jp->state == JOBSTOPPED) {
while (!WIFSTOPPED(ps->status) && ps > jp->ps) while (!WIFSTOPPED(ps->status) && ps > jp->ps)
@ -350,27 +351,25 @@ showjob(struct job *jp, int mode)
i = WSTOPSIG(ps->status); i = WSTOPSIG(ps->status);
else else
i = -1; i = -1;
sigstr = strsignal(i); statestr = strsignal(i);
if (sigstr != NULL) if (statestr == NULL)
strcpy(statestr, sigstr); statestr = "Suspended";
else
strcpy(statestr, "Suspended");
#endif #endif
} else if (WIFEXITED(ps->status)) { } else if (WIFEXITED(ps->status)) {
if (WEXITSTATUS(ps->status) == 0) if (WEXITSTATUS(ps->status) == 0)
strcpy(statestr, "Done"); statestr = "Done";
else else {
fmtstr(statestr, 64, "Done(%d)", fmtstr(statebuf, sizeof(statebuf), "Done(%d)",
WEXITSTATUS(ps->status)); WEXITSTATUS(ps->status));
statestr = statebuf;
}
} else { } else {
i = WTERMSIG(ps->status); i = WTERMSIG(ps->status);
sigstr = strsignal(i); statestr = strsignal(i);
if (sigstr != NULL) if (statestr == NULL)
strcpy(statestr, sigstr); statestr = "Unknown signal";
else
strcpy(statestr, "Unknown signal");
if (WCOREDUMP(ps->status)) if (WCOREDUMP(ps->status))
strcat(statestr, " (core dumped)"); coredump = " (core dumped)";
} }
for (ps = jp->ps ; procno > 0 ; ps++, procno--) { /* for each process */ for (ps = jp->ps ; procno > 0 ; ps++, procno--) { /* for each process */
@ -399,7 +398,8 @@ showjob(struct job *jp, int mode)
} }
if (ps == jp->ps) { if (ps == jp->ps) {
out1str(statestr); out1str(statestr);
col += strlen(statestr); out1str(coredump);
col += strlen(statestr) + strlen(coredump);
} }
do { do {
out1c(' '); out1c(' ');