Module Name: src Committed By: kre Date: Thu May 11 14:57:14 UTC 2017
Modified Files: src/bin/sh: jobs.c Log Message: Avoid truncating the command string saved with background jobs if one of the words happens to contain ${#var}. (This is the command string shown by the "jobs" command, and when a background job completes) While here, undo the LINENO hack when building that string. And one ot two other foibles... To generate a diff of this commit: cvs rdiff -u -r1.83 -r1.84 src/bin/sh/jobs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/sh/jobs.c diff -u src/bin/sh/jobs.c:1.83 src/bin/sh/jobs.c:1.84 --- src/bin/sh/jobs.c:1.83 Tue May 9 05:14:03 2017 +++ src/bin/sh/jobs.c Thu May 11 14:57:14 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.c,v 1.83 2017/05/09 05:14:03 kre Exp $ */ +/* $NetBSD: jobs.c,v 1.84 2017/05/11 14:57:14 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: jobs.c,v 1.83 2017/05/09 05:14:03 kre Exp $"); +__RCSID("$NetBSD: jobs.c,v 1.84 2017/05/11 14:57:14 kre Exp $"); #endif #endif /* not lint */ @@ -1423,7 +1423,7 @@ cmdputs(const char *s) int subtype = 0; int quoted = 0; static char vstype[16][4] = { "", "}", "-", "+", "?", "=", - "#", "##", "%", "%%" }; + "#", "##", "%", "%%", "}" }; p = s; nextc = cmdnextc; @@ -1435,22 +1435,28 @@ cmdputs(const char *s) break; case CTLVAR: subtype = *p++; - if ((subtype & VSTYPE) == VSLENGTH) + if (subtype & VSLINENO) { + if ((subtype & VSTYPE) == VSLENGTH) + str = "${#LINENO"; + else + str = "${LINENO"; + while (is_digit(*p)) + p++; + } else if ((subtype & VSTYPE) == VSLENGTH) str = "${#"; else str = "${"; if (!(subtype & VSQUOTE) != !(quoted & 1)) { quoted ^= 1; c = '"'; - } else + } else { c = *str++; + } break; case CTLENDVAR: - if (quoted & 1) { - c = '"'; - str = "}"; - } else - c = '}'; + c = '}'; + if (quoted & 1) + str = "\""; quoted >>= 1; subtype = 0; break; @@ -1474,6 +1480,10 @@ cmdputs(const char *s) quoted ^= 1; c = '"'; break; + case CTLQUOTEEND: + quoted >>= 1; + c = '"'; + break; case '=': if (subtype == 0) break; @@ -1484,6 +1494,9 @@ cmdputs(const char *s) c = *str++; if (c != '}') quoted <<= 1; + else if (*p == CTLENDVAR) + c = *str++; + subtype = 0; break; case '\'': case '\\': @@ -1497,7 +1510,7 @@ cmdputs(const char *s) default: break; } - do { + if (c != '\0') do { /* c == 0 implies nothing in str */ *nextc++ = c; } while (--nleft > 0 && str && (c = *str++)); str = 0;