CVS commit: [netbsd-6] src/bin/sh
Module Name:src Committed By: snj Date: Wed Nov 16 17:53:57 UTC 2016 Modified Files: src/bin/sh [netbsd-6]: exec.c var.c Log Message: Pull up following revision(s) (requested by dholland in ticket #1412): bin/sh/exec.c: revision 1.45 bin/sh/var.c: revision 1.43 PR/48312: Dieter Roelants: According to TOG, unset should not return an error for functions are variables that were not previously set: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html To generate a diff of this commit: cvs rdiff -u -r1.42 -r1.42.20.1 src/bin/sh/exec.c cvs rdiff -u -r1.40 -r1.40.4.1 src/bin/sh/var.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/exec.c diff -u src/bin/sh/exec.c:1.42 src/bin/sh/exec.c:1.42.20.1 --- src/bin/sh/exec.c:1.42 Thu Oct 16 15:31:05 2008 +++ src/bin/sh/exec.c Wed Nov 16 17:53:57 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: exec.c,v 1.42 2008/10/16 15:31:05 dholland Exp $ */ +/* $NetBSD: exec.c,v 1.42.20.1 2016/11/16 17:53:57 snj Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: exec.c,v 1.42 2008/10/16 15:31:05 dholland Exp $"); +__RCSID("$NetBSD: exec.c,v 1.42.20.1 2016/11/16 17:53:57 snj Exp $"); #endif #endif /* not lint */ @@ -944,9 +944,8 @@ unsetfunc(char *name) cmdp->cmdtype == CMDFUNCTION) { freefunc(cmdp->param.func); delete_cmd_entry(); - return (0); } - return (1); + return 0; } /* Index: src/bin/sh/var.c diff -u src/bin/sh/var.c:1.40 src/bin/sh/var.c:1.40.4.1 --- src/bin/sh/var.c:1.40 Sat Jun 18 21:18:46 2011 +++ src/bin/sh/var.c Wed Nov 16 17:53:57 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.40 2011/06/18 21:18:46 christos Exp $ */ +/* $NetBSD: var.c,v 1.40.4.1 2016/11/16 17:53:57 snj Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: var.c,v 1.40 2011/06/18 21:18:46 christos Exp $"); +__RCSID("$NetBSD: var.c,v 1.40.4.1 2016/11/16 17:53:57 snj Exp $"); #endif #endif /* not lint */ @@ -753,10 +753,10 @@ unsetvar(const char *s, int unexport) vp = find_var(s, , NULL); if (vp == NULL) - return 1; + return 0; if (vp->flags & VREADONLY) - return (1); + return 1; INTOFF; if (unexport) {
CVS commit: [netbsd-6] src/bin/sh
Module Name:src Committed By: bouyer Date: Sat Aug 27 14:46:36 UTC 2016 Modified Files: src/bin/sh [netbsd-6]: parser.c Log Message: Pull up following revision(s) (requested by kre in ticket #1397): bin/sh/parser.c: revision 1.114 via patch PR bin/51027 - fix the parsing of references to shell parameters when given without braces (ie: $2 etc). Only the first 9 shell parameters ($1 .. $9) and the special parameter ($0) can be referenced this way, $10 is ${1}0 not ${10}. Make it so. This bug brought to notice by Sven Mascheck's web pages which discuss (among other things) the history of this (and other ash based) shells .. see http://www.in-ulm.de/~mascheck/ (from kre@) To generate a diff of this commit: cvs rdiff -u -r1.80 -r1.80.4.1 src/bin/sh/parser.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/parser.c diff -u src/bin/sh/parser.c:1.80 src/bin/sh/parser.c:1.80.4.1 --- src/bin/sh/parser.c:1.80 Wed Aug 31 16:24:55 2011 +++ src/bin/sh/parser.c Sat Aug 27 14:46:36 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: parser.c,v 1.80 2011/08/31 16:24:55 plunky Exp $ */ +/* $NetBSD: parser.c,v 1.80.4.1 2016/08/27 14:46:36 bouyer Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95"; #else -__RCSID("$NetBSD: parser.c,v 1.80 2011/08/31 16:24:55 plunky Exp $"); +__RCSID("$NetBSD: parser.c,v 1.80.4.1 2016/08/27 14:46:36 bouyer Exp $"); #endif #endif /* not lint */ @@ -1294,7 +1294,7 @@ parsesub: { do { USTPUTC(c, out); c = pgetc(); - } while (is_digit(c)); + } while (subtype != VSNORMAL && is_digit(c)); } else if (is_special(c)) { USTPUTC(c, out);
CVS commit: [netbsd-6] src/bin/sh
Module Name:src Committed By: bouyer Date: Sun Nov 15 17:41:26 UTC 2015 Modified Files: src/bin/sh [netbsd-6]: jobs.c trap.c trap.h Log Message: Pull up following revision(s) (requested by christos in ticket #1323): bin/sh/jobs.c: revision 1.74 bin/sh/jobs.c: revision 1.75 bin/sh/trap.c: revision 1.36 bin/sh/trap.c: revision 1.37 bin/sh/trap.h: revision 1.21 bin/sh/trap.h: revision 1.22 Process pending signals while waiting for a job: $ cat << EOF > hup.sh #!/bin/sh trap 'echo SIGHUP; exit 1' 1 sleep 1 & wait EOF $ chmod +x ./hup.sh $ ./hup.sh & $ kill -HUP %1 report the signal that wait was interrupted by, which is not always SIGINT anymore. To generate a diff of this commit: cvs rdiff -u -r1.69.4.1 -r1.69.4.2 src/bin/sh/jobs.c cvs rdiff -u -r1.35 -r1.35.4.1 src/bin/sh/trap.c cvs rdiff -u -r1.19 -r1.19.4.1 src/bin/sh/trap.h 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.69.4.1 src/bin/sh/jobs.c:1.69.4.2 --- src/bin/sh/jobs.c:1.69.4.1 Sun Dec 7 15:58:27 2014 +++ src/bin/sh/jobs.c Sun Nov 15 17:41:26 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.c,v 1.69.4.1 2014/12/07 15:58:27 martin Exp $ */ +/* $NetBSD: jobs.c,v 1.69.4.2 2015/11/15 17:41:26 bouyer 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.69.4.1 2014/12/07 15:58:27 martin Exp $"); +__RCSID("$NetBSD: jobs.c,v 1.69.4.2 2015/11/15 17:41:26 bouyer Exp $"); #endif #endif /* not lint */ @@ -619,7 +619,7 @@ waitcmd(int argc, char **argv) continue; } if (dowait(WBLOCK, NULL) == -1) - return 128 + SIGINT; + return 128 + lastsig(); jp = jobtab; } } @@ -634,7 +634,7 @@ waitcmd(int argc, char **argv) /* loop until process terminated or stopped */ while (job->state == JOBRUNNING) { if (dowait(WBLOCK|WNOFREE, job) == -1) - return 128 + SIGINT; + return 128 + lastsig(); } status = job->ps[job->nprocs ? job->nprocs - 1 : 0].status; if (WIFEXITED(status)) @@ -1042,13 +1042,12 @@ dowait(int flags, struct job *job) struct job *thisjob; int done; int stopped; - extern volatile char gotsig[]; TRACE(("dowait(%x) called\n", flags)); do { pid = waitproc(flags & WBLOCK, job, ); TRACE(("wait returns pid %d, status %d\n", pid, status)); - } while (pid == -1 && errno == EINTR && gotsig[SIGINT - 1] == 0); + } while (pid == -1 && errno == EINTR && pendingsigs == 0); if (pid <= 0) return pid; INTOFF; Index: src/bin/sh/trap.c diff -u src/bin/sh/trap.c:1.35 src/bin/sh/trap.c:1.35.4.1 --- src/bin/sh/trap.c:1.35 Sat Jun 18 21:18:46 2011 +++ src/bin/sh/trap.c Sun Nov 15 17:41:26 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.35 2011/06/18 21:18:46 christos Exp $ */ +/* $NetBSD: trap.c,v 1.35.4.1 2015/11/15 17:41:26 bouyer Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95"; #else -__RCSID("$NetBSD: trap.c,v 1.35 2011/06/18 21:18:46 christos Exp $"); +__RCSID("$NetBSD: trap.c,v 1.35.4.1 2015/11/15 17:41:26 bouyer Exp $"); #endif #endif /* not lint */ @@ -77,8 +77,8 @@ __RCSID("$NetBSD: trap.c,v 1.35 2011/06/ char *trap[NSIG+1]; /* trap handler commands */ MKINIT char sigmode[NSIG]; /* current value of signal */ -volatile char gotsig[NSIG]; /* indicates specified signal received */ -int pendingsigs; /* indicates some signal received */ +static volatile char gotsig[NSIG];/* indicates specified signal received */ +volatile int pendingsigs; /* indicates some signal received */ static int getsigaction(int, sig_t *); @@ -421,7 +421,16 @@ done: pendingsigs = 0; } +int +lastsig(void) +{ + int i; + for (i = NSIG; i > 0; i--) + if (gotsig[i - 1]) + return i; + return SIGINT; /* XXX */ +} /* * Controls whether the shell is interactive or not. Index: src/bin/sh/trap.h diff -u src/bin/sh/trap.h:1.19 src/bin/sh/trap.h:1.19.4.1 --- src/bin/sh/trap.h:1.19 Sat Jun 18 21:18:46 2011 +++ src/bin/sh/trap.h Sun Nov 15 17:41:26 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.h,v 1.19 2011/06/18 21:18:46 christos Exp $ */ +/* $NetBSD: trap.h,v 1.19.4.1 2015/11/15 17:41:26 bouyer Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -34,7 +34,7 @@ * @(#)trap.h 8.3 (Berkeley) 6/5/95 */ -extern int pendingsigs; +extern volatile int pendingsigs; void clear_traps(int); sig_t setsignal(int, int); @@ -43,3 +43,4 @@ void onsig(int); void dotrap(void); void setinteractive(int); void exitshell(int) __attribute__((__noreturn__)); +int lastsig(void);
CVS commit: [netbsd-6] src/bin/sh
Module Name:src Committed By: martin Date: Sun Dec 7 15:58:27 UTC 2014 Modified Files: src/bin/sh [netbsd-6]: jobs.c Log Message: Pullup the following revisions, requested by spz in #1205: src/bin/sh/jobs.c 1.73 PR/48729: Torbj�rn Granlund: Avoid negative index in array ref. To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.69.4.1 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.69 src/bin/sh/jobs.c:1.69.4.1 --- src/bin/sh/jobs.c:1.69 Sat Jun 18 21:18:46 2011 +++ src/bin/sh/jobs.c Sun Dec 7 15:58:27 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.c,v 1.69 2011/06/18 21:18:46 christos Exp $ */ +/* $NetBSD: jobs.c,v 1.69.4.1 2014/12/07 15:58:27 martin 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.69 2011/06/18 21:18:46 christos Exp $); +__RCSID($NetBSD: jobs.c,v 1.69.4.1 2014/12/07 15:58:27 martin Exp $); #endif #endif /* not lint */ @@ -636,7 +636,7 @@ waitcmd(int argc, char **argv) if (dowait(WBLOCK|WNOFREE, job) == -1) return 128 + SIGINT; } - status = job-ps[job-nprocs - 1].status; + status = job-ps[job-nprocs ? job-nprocs - 1 : 0].status; if (WIFEXITED(status)) retval = WEXITSTATUS(status); #if JOBS
CVS commit: [netbsd-6] src/bin/sh
Module Name:src Committed By: sborrill Date: Sat Feb 2 15:43:27 UTC 2013 Modified Files: src/bin/sh [netbsd-6]: expand.c expand.h Log Message: Pull up the following revisions(s) (requested by dsl in ticket #773): bin/sh/expand.c:revision 1.88 bin/sh/expand.h:revision 1.19 Fix the expansion of $(foo-$bar} so that IFS isn't applied when expanding $bar. Should fix PR bin/47361 To generate a diff of this commit: cvs rdiff -u -r1.86 -r1.86.4.1 src/bin/sh/expand.c cvs rdiff -u -r1.18 -r1.18.4.1 src/bin/sh/expand.h 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/expand.c diff -u src/bin/sh/expand.c:1.86 src/bin/sh/expand.c:1.86.4.1 --- src/bin/sh/expand.c:1.86 Wed Aug 31 16:24:54 2011 +++ src/bin/sh/expand.c Sat Feb 2 15:43:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: expand.c,v 1.86 2011/08/31 16:24:54 plunky Exp $ */ +/* $NetBSD: expand.c,v 1.86.4.1 2013/02/02 15:43:27 sborrill Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = @(#)expand.c 8.5 (Berkeley) 5/15/95; #else -__RCSID($NetBSD: expand.c,v 1.86 2011/08/31 16:24:54 plunky Exp $); +__RCSID($NetBSD: expand.c,v 1.86.4.1 2013/02/02 15:43:27 sborrill Exp $); #endif #endif /* not lint */ @@ -247,7 +247,7 @@ argstr(char *p, int flag) break; default: STPUTC(c, expdest); - if (flag EXP_IFS_SPLIT ifs_split strchr(ifs, c) != NULL) { + if (flag ifs_split strchr(ifs, c) != NULL) { /* We need to get the output split here... */ recordregion(expdest - stackblock() - 1, expdest - stackblock(), 0); @@ -702,8 +702,21 @@ again: /* jump here after setting a vari } - apply_ifs = ((varflags VSQUOTE) == 0 || - (*var == '@' shellparam.nparam != 1)); + if (flag EXP_IN_QUOTES) + apply_ifs = 0; + else if (varflags VSQUOTE) { + if (*var == '@' shellparam.nparam != 1) + apply_ifs = 1; + else { + /* + * Mark so that we don't apply IFS if we recurse through + * here expanding $bar from ${foo-$bar}. + */ + flag |= EXP_IN_QUOTES; + apply_ifs = 0; + } + } else + apply_ifs = 1; switch (subtype) { case VSLENGTH: Index: src/bin/sh/expand.h diff -u src/bin/sh/expand.h:1.18 src/bin/sh/expand.h:1.18.4.1 --- src/bin/sh/expand.h:1.18 Sat Jun 18 21:18:46 2011 +++ src/bin/sh/expand.h Sat Feb 2 15:43:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: expand.h,v 1.18 2011/06/18 21:18:46 christos Exp $ */ +/* $NetBSD: expand.h,v 1.18.4.1 2013/02/02 15:43:27 sborrill Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -56,6 +56,7 @@ struct arglist { #define EXP_REDIR 0x8 /* file glob for a redirection (1 match only) */ #define EXP_CASE 0x10 /* keeps quotes around for CASE pattern */ #define EXP_IFS_SPLIT 0x20 /* need to record arguments for ifs breakup */ +#define EXP_IN_QUOTES 0x40 /* don't set EXP_IFS_SPLIT again */ union node;