Date: Wed, 22 Sep 2021 20:25:41 GMT From: Piotr Pawel Stefaniak <pstef@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 1f82fb383410 - main - sh: try to avoid overwriting HISTFILE produced by other shells Message-ID: <202109222025.18MKPfLc098616@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by pstef: URL: https://cgit.FreeBSD.org/src/commit/?id=1f82fb3834105fd8f1186b1c6d719d8a24738180 commit 1f82fb3834105fd8f1186b1c6d719d8a24738180 Author: Piotr Pawel Stefaniak <pstef@FreeBSD.org> AuthorDate: 2021-09-22 16:42:41 +0000 Commit: Piotr Pawel Stefaniak <pstef@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; } /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202109222025.18MKPfLc098616>