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.
This commit is contained in:
parent
c866d0c798
commit
1f82fb3834
@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
@ -70,6 +71,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
History *hist; /* history cookie */
|
History *hist; /* history cookie */
|
||||||
EditLine *el; /* editline cookie */
|
EditLine *el; /* editline cookie */
|
||||||
int displayhist;
|
int displayhist;
|
||||||
|
static int savehist;
|
||||||
static FILE *el_in, *el_out;
|
static FILE *el_in, *el_out;
|
||||||
|
|
||||||
static char *fc_replace(const char *, char *, char *);
|
static char *fc_replace(const char *, char *, char *);
|
||||||
@ -103,7 +105,7 @@ histsave(void)
|
|||||||
int fd;
|
int fd;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if ((histfile = get_histfile()) == NULL)
|
if (!savehist || (histfile = get_histfile()) == NULL)
|
||||||
return;
|
return;
|
||||||
INTOFF;
|
INTOFF;
|
||||||
asprintf(&histtmpname, "%s.XXXXXXXXXX", histfile);
|
asprintf(&histtmpname, "%s.XXXXXXXXXX", histfile);
|
||||||
@ -134,7 +136,9 @@ histload(void)
|
|||||||
|
|
||||||
if ((histfile = get_histfile()) == NULL)
|
if ((histfile = get_histfile()) == NULL)
|
||||||
return;
|
return;
|
||||||
history(hist, &he, H_LOAD, histfile);
|
errno = 0;
|
||||||
|
if (history(hist, &he, H_LOAD, histfile) != -1 || errno == ENOENT)
|
||||||
|
savehist = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user