Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: ZSH history not saved anymore



Put this in a file named /tmp/z:

TRAPHUP() {
    print exiting on HUP >> /tmp/x
    exit
}
TRAPTERM() {
    print exiting on TERM >> /tmp/x
    exit
}
TRAPKILL() {
    print exiting on KILL >> /tmp/x
    exit
}
TRAPEXIT() {
    print exiting on EXIT >> /tmp/x
    exit
}

rm /tmp/x
print I am pid $$ with these traps in place:
trap

print Run one of these commands in a different shell:
print kill -HUP $$
print kill -TERM $$
print kill -KILL $$

Then start a new shell and source it:

zsh
. /tmp/z

In a different window execute one of the printed kill commands then

cat /tmp/x

Notice that your traps for SIGHUP and SIGTERM are honored but the trap for
SIGKILL is not. That's because the OS kernel ignores any handler for
SIGKILL. So if your terminal emulator is sending SIGKILL there is nothing
zsh can do. If that is happening you should switch to a saner terminal
emulator.

If you're running on a Linux based OS you should be able to trace the
shells interaction with the OS using the strace command. Similarly you
should be able to trace the terminal emulator to see what operating system
calls it is making. One or both of those outputs should make it clear how
the shell is being terminated. You may also find that it's being terminated
with SIGHUP or SIGTERM but the attempt to write the history is failing
(look for failed open() or write() calls).

On Fri, Sep 26, 2014 at 1:15 AM, Tassilo Horn <tsdh@xxxxxxx> wrote:

> Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> writes:
>
> Hi Bart,
>
> > } > If you do
> > } >
> > } > TRAPHUP() {
> > } >   print "Exiting on signal" >~/zsh_exited
> > } >   exit
> > } > }
> > } >
> > } > do you see the message being written to the file ~/zsh_exited?
> > }
> > } Nope, there's no such file after terminating the terminal emulator, so
> a
> > } missing SIGHUP is probably the problem.  Sending it to the ZSH process
> > } using kill -SIGHUP works.  Thanks for your help in clearing that up.
> >
> > That still seems a little strange.  If zsh doesn't get HUP, then it
> > should get EOF and write the history at that point.  Something may
> > be killing it off (with a signal stronger than HUP) before it has a
> > chance to finish writing.
>
> I've tried defining trap functions for HUP, TERM, EXIT, KILL, and ABRT,
> none of which seem to be executed when closing the terminal emulator.
>
> Any idea how to debug that further?
>
> Bye,
> Tassilo
>
>


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank


Messages sorted by: Reverse Date, Date, Thread, Author