summaryrefslogtreecommitdiff
path: root/bin/ksh
diff options
context:
space:
mode:
authorMartijn van Duren <martijn@cvs.openbsd.org>2018-11-20 07:02:24 +0000
committerMartijn van Duren <martijn@cvs.openbsd.org>2018-11-20 07:02:24 +0000
commit9f85ec400abe1602dd63986300373adf12092bd0 (patch)
tree7413d92b1c60be333730c1649bff43015637a349 /bin/ksh
parent285951b2a7b540f7a11af4695ddbfe1c93aa44ab (diff)
Fix the case where the recursion detection isn't reset when the command is
interrupted. Lots of back and forth with anton@ OK jca@, tb@, anton@
Diffstat (limited to 'bin/ksh')
-rw-r--r--bin/ksh/history.c24
-rw-r--r--bin/ksh/main.c3
-rw-r--r--bin/ksh/sh.h3
3 files changed, 21 insertions, 9 deletions
diff --git a/bin/ksh/history.c b/bin/ksh/history.c
index 67735c90964..1448f8abc58 100644
--- a/bin/ksh/history.c
+++ b/bin/ksh/history.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: history.c,v 1.80 2018/01/15 22:30:38 jca Exp $ */
+/* $OpenBSD: history.c,v 1.81 2018/11/20 07:02:23 martijn Exp $ */
/*
* command history
@@ -48,6 +48,8 @@ static uint32_t line_co;
static struct stat last_sb;
+static volatile sig_atomic_t c_fc_depth;
+
int
c_fc(char **wp)
{
@@ -58,9 +60,8 @@ c_fc(char **wp)
int optc, ret;
char *first = NULL, *last = NULL;
char **hfirst, **hlast, **hp;
- static int depth;
- if (depth != 0) {
+ if (c_fc_depth != 0) {
bi_errorf("history function called recursively");
return 1;
}
@@ -146,9 +147,9 @@ c_fc(char **wp)
hist_get_newest(false);
if (!hp)
return 1;
- depth++;
+ c_fc_depth++;
ret = hist_replace(hp, pat, rep, gflag);
- depth--;
+ c_fc_reset();
return ret;
}
@@ -268,13 +269,22 @@ c_fc(char **wp)
shf_close(shf);
*xp = '\0';
strip_nuls(Xstring(xs, xp), Xlength(xs, xp));
- depth++;
+ c_fc_depth++;
ret = hist_execute(Xstring(xs, xp));
- depth--;
+ c_fc_reset();
return ret;
}
}
+/* Reset the c_fc depth counter.
+ * Made available for when an fc call is interrupted.
+ */
+void
+c_fc_reset(void)
+{
+ c_fc_depth = 0;
+}
+
/* Save cmd in history, execute cmd (cmd gets trashed) */
static int
hist_execute(char *cmd)
diff --git a/bin/ksh/main.c b/bin/ksh/main.c
index 63508d4dc84..e74c12f3a37 100644
--- a/bin/ksh/main.c
+++ b/bin/ksh/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.95 2018/11/17 18:14:58 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.96 2018/11/20 07:02:23 martijn Exp $ */
/*
* startup, main loop, environments and error handling
@@ -557,6 +557,7 @@ shell(Source *volatile s, volatile int toplevel)
case LERROR:
case LSHELL:
if (interactive) {
+ c_fc_reset();
if (i == LINTR)
shellf("\n");
/* Reset any eof that was read as part of a
diff --git a/bin/ksh/sh.h b/bin/ksh/sh.h
index cf2c6c3a595..2efa875bb80 100644
--- a/bin/ksh/sh.h
+++ b/bin/ksh/sh.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sh.h,v 1.73 2018/05/18 13:25:20 benno Exp $ */
+/* $OpenBSD: sh.h,v 1.74 2018/11/20 07:02:23 martijn Exp $ */
/*
* Public Domain Bourne/Korn shell
@@ -449,6 +449,7 @@ void hist_init(Source *);
void hist_finish(void);
void histsave(int, const char *, int);
int c_fc(char **);
+void c_fc_reset(void);
void sethistcontrol(const char *);
void sethistsize(int);
void sethistfile(const char *);