apply diff from manuel giraud via oksh to keep track of LINENO in a trap

This commit is contained in:
tg
2010-05-22 12:49:16 +00:00
parent 2a72f0e2f0
commit 747b27a846
4 changed files with 31 additions and 15 deletions

18
check.t
View File

@@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.377 2010/05/16 19:17:41 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.378 2010/05/22 12:49:13 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@@ -25,7 +25,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh # http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R39 2010/05/16 @(#)MIRBSD KSH R39 2010/05/22
description: description:
Check version of shell. Check version of shell.
stdin: stdin:
@@ -3321,6 +3321,20 @@ expected-stdout:
dot B 3 dot B 3
C 3 C 3
--- ---
name: lineno-trap
description:
Check if LINENO is tracked in traps
stdin:
fail() {
echo "line <$1>"
exit 1
}
trap 'fail $LINENO' INT ERR
false
expected-stdout:
line <6>
expected-exit: 1
---
name: read-IFS-1 name: read-IFS-1
description: description:
Simple test, default IFS Simple test, default IFS

View File

@@ -1,5 +1,5 @@
/* $OpenBSD: history.c,v 1.38 2010/05/01 21:09:23 guenther Exp $ */ /* $OpenBSD: history.c,v 1.39 2010/05/19 17:36:08 jasper Exp $ */
/* $OpenBSD: trap.c,v 1.22 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: trap.c,v 1.23 2010/05/19 17:36:08 jasper Exp $ */
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
@@ -26,7 +26,7 @@
#include <sys/file.h> #include <sys/file.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.93 2010/05/13 18:44:09 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.94 2010/05/22 12:49:14 tg Exp $");
/*- /*-
* MirOS: This is the default mapping type, and need not be specified. * MirOS: This is the default mapping type, and need not be specified.
@@ -250,7 +250,7 @@ c_fc(const char **wp)
Source *sold = source; Source *sold = source;
int ret; int ret;
ret = command(editor ? editor : "${FCEDIT:-/bin/ed} $_"); ret = command(editor ? editor : "${FCEDIT:-/bin/ed} $_", 0);
source = sold; source = sold;
if (ret) if (ret)
return (ret); return (ret);
@@ -318,7 +318,7 @@ hist_execute(char *cmd)
*/ */
/* XXX: source should not get trashed by this.. */ /* XXX: source should not get trashed by this.. */
sold = source; sold = source;
ret = command(cmd); ret = command(cmd, 0);
source = sold; source = sold;
return (ret); return (ret);
} }
@@ -1286,7 +1286,7 @@ runtrap(Trap *p)
/* Note: trapstr is fully parsed before anything is executed, thus /* Note: trapstr is fully parsed before anything is executed, thus
* no problem with afree(p->trap) in settrap() while still in use. * no problem with afree(p->trap) in settrap() while still in use.
*/ */
command(trapstr); command(trapstr, current_lineno);
exstat = oexstat; exstat = oexstat;
if (i == SIGEXIT_ || i == SIGERR_) { if (i == SIGEXIT_ || i == SIGERR_) {
if (p->flags & TF_CHANGED) if (p->flags & TF_CHANGED)

8
main.c
View File

@@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.45 2009/01/29 23:27:26 jaredy Exp $ */ /* $OpenBSD: main.c,v 1.46 2010/05/19 17:36:08 jasper Exp $ */
/* $OpenBSD: tty.c,v 1.9 2006/03/14 22:08:01 deraadt Exp $ */ /* $OpenBSD: tty.c,v 1.9 2006/03/14 22:08:01 deraadt Exp $ */
/* $OpenBSD: io.c,v 1.22 2006/03/17 16:30:13 millert Exp $ */ /* $OpenBSD: io.c,v 1.22 2006/03/17 16:30:13 millert Exp $ */
/* $OpenBSD: table.c,v 1.13 2009/01/17 22:06:44 millert Exp $ */ /* $OpenBSD: table.c,v 1.13 2009/01/17 22:06:44 millert Exp $ */
@@ -33,7 +33,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.164 2010/04/20 17:28:20 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.165 2010/05/22 12:49:15 tg Exp $");
extern char **environ; extern char **environ;
@@ -540,13 +540,15 @@ include(const char *name, int argc, const char **argv, int intr_ok)
return (i & 0xff); /* & 0xff to ensure value not -1 */ return (i & 0xff); /* & 0xff to ensure value not -1 */
} }
/* spawn a command into a shell optionally keeping track of the line number */
int int
command(const char *comm) command(const char *comm, int line)
{ {
Source *s; Source *s;
s = pushs(SSTRING, ATEMP); s = pushs(SSTRING, ATEMP);
s->start = s->str = comm; s->start = s->str = comm;
s->line = line;
return (shell(s, false)); return (shell(s, false));
} }

8
sh.h
View File

@@ -4,7 +4,7 @@
/* $OpenBSD: tree.h,v 1.10 2005/03/28 21:28:22 deraadt Exp $ */ /* $OpenBSD: tree.h,v 1.10 2005/03/28 21:28:22 deraadt Exp $ */
/* $OpenBSD: expand.h,v 1.6 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: expand.h,v 1.6 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: lex.h,v 1.11 2006/05/29 18:22:24 otto Exp $ */ /* $OpenBSD: lex.h,v 1.11 2006/05/29 18:22:24 otto Exp $ */
/* $OpenBSD: proto.h,v 1.32 2009/01/29 23:27:26 jaredy Exp $ */ /* $OpenBSD: proto.h,v 1.33 2010/05/19 17:36:08 jasper Exp $ */
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
@@ -150,9 +150,9 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.391 2010/05/16 19:04:42 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.392 2010/05/22 12:49:16 tg Exp $");
#endif #endif
#define MKSH_VERSION "R39 2010/05/16" #define MKSH_VERSION "R39 2010/05/22"
#ifndef MKSH_INCLUDES_ONLY #ifndef MKSH_INCLUDES_ONLY
@@ -1496,7 +1496,7 @@ void pprompt(const char *, int);
int promptlen(const char *); int promptlen(const char *);
/* main.c */ /* main.c */
int include(const char *, int, const char **, int); int include(const char *, int, const char **, int);
int command(const char *); int command(const char *, int);
int shell(Source *volatile, int volatile); int shell(Source *volatile, int volatile);
void unwind(int) MKSH_A_NORETURN; void unwind(int) MKSH_A_NORETURN;
void newenv(int); void newenv(int);