It will also fail the rename in the chunk:
if(access(hist_old->histname,F_OK) >= 0)
/* The unlink can fail on windows 95 */
char *last, *name=hist_old->histname;
tmpname = (char*)malloc(strlen(name)+14);
if(last = strrchr(name,'/'))
*last = 0;
*last = '/';
if(rename(name,tmpname) < 0)
tmpname = name;
fd = open(tmpname,O_RDONLY);
tmpname = 0;
hist_ptr = 0;
histinit = 1;
histmode = statb.st_mode;
Another condition required is to have a full .sh_history.
This will cause sh_histinit to call hist_trim, that will
again call sh_histinit.
On the backtrace, the condition is verified in the statb
local variable of hist_trim, where the call trace shows that
the unlink and rename syscalls failed.
The unlink call may fail due to a stale file or some filesystem
issue. The rename call will fail if tmpname is on another filesystem;
could be nfs vs local filesystem or local filesystem and a tmpfs /tmp.
The issue only happens if the unlink fails, but still, could use
a smarter or fallback approach to not cause the stack overflow crash.
We just had another case with a slightly different condition for this to happen.
Still an erroneous state. Basically, needs a .sh_history that will cause hist_trim
to be called, and not have write permissions to $HOME.
The other recent cases were stale nfs file and an issue with a local filesystem.