git: 1f82fb383410 - main - sh: try to avoid overwriting HISTFILE produced by other shells
Piotr Pawel Stefaniak
pstef at FreeBSD.org
Wed Sep 22 20:25:41 UTC 2021
The branch main has been updated by pstef:
URL: https://cgit.FreeBSD.org/src/commit/?id=1f82fb3834105fd8f1186b1c6d719d8a24738180
commit 1f82fb3834105fd8f1186b1c6d719d8a24738180
Author: Piotr Pawel Stefaniak <pstef at FreeBSD.org>
AuthorDate: 2021-09-22 16:42:41 +0000
Commit: Piotr Pawel Stefaniak <pstef at FreeBSD.org>
CommitDate: 2021-09-22 20:23:32 +0000
sh: try to avoid overwriting HISTFILE produced by other shells
If an attempt to load history from an existing history file was
unsuccessful, do not try to save command history to that file on exit.
---
bin/sh/histedit.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c
index 4e82f7497850..96511b87b451 100644
--- a/bin/sh/histedit.c
+++ b/bin/sh/histedit.c
@@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/stat.h>
#include <dirent.h>
+#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <paths.h>
@@ -70,6 +71,7 @@ __FBSDID("$FreeBSD$");
History *hist; /* history cookie */
EditLine *el; /* editline cookie */
int displayhist;
+static int savehist;
static FILE *el_in, *el_out;
static char *fc_replace(const char *, char *, char *);
@@ -103,7 +105,7 @@ histsave(void)
int fd;
FILE *f;
- if ((histfile = get_histfile()) == NULL)
+ if (!savehist || (histfile = get_histfile()) == NULL)
return;
INTOFF;
asprintf(&histtmpname, "%s.XXXXXXXXXX", histfile);
@@ -134,7 +136,9 @@ histload(void)
if ((histfile = get_histfile()) == NULL)
return;
- history(hist, &he, H_LOAD, histfile);
+ errno = 0;
+ if (history(hist, &he, H_LOAD, histfile) != -1 || errno == ENOENT)
+ savehist = 1;
}
/*
More information about the dev-commits-src-all
mailing list