zsh-users
 help / color / mirror / code / Atom feed
* ZSH history not saved anymore
@ 2014-09-23 21:03 Tassilo Horn
  2014-09-24 19:07 ` Peter Stephenson
  0 siblings, 1 reply; 9+ messages in thread
From: Tassilo Horn @ 2014-09-23 21:03 UTC (permalink / raw)
  To: zsh-users

Hi all,

I've just started using enlightenment 19 coming from Gnome.  Now my
terminal emulator is terminology instead of gnome-terminal.

Today, I've noticed that since then my ZSH history file doesn't get
updated anymore.  That is, when terminating the terminal emulator, it
seems that ZSH has no chance to save the histfile anymore.  As a
workaround I can just quit ZSH before terminating terminology using the
"exit" command.

I've written a bug report for terminology here:

  https://phab.enlightenment.org/T1685

However, I'm not completely sure that terminology is doing something
wrong.  When using BASH inside a terminology terminal emulator and
closing the latter, the bash history *is* saved.

So is it really a terminology problem or is ZSH (5.0.6) doing something
wrong?

Bye,
Tassilo


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ZSH history not saved anymore
  2014-09-23 21:03 ZSH history not saved anymore Tassilo Horn
@ 2014-09-24 19:07 ` Peter Stephenson
  2014-09-25  7:10   ` Tassilo Horn
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Stephenson @ 2014-09-24 19:07 UTC (permalink / raw)
  To: zsh-users

On Tue, 23 Sep 2014 23:03:19 +0200
Tassilo Horn <tsdh@gnu.org> wrote:
> I've just started using enlightenment 19 coming from Gnome.  Now my
> terminal emulator is terminology instead of gnome-terminal.
> 
> Today, I've noticed that since then my ZSH history file doesn't get
> updated anymore.  That is, when terminating the terminal emulator, it
> seems that ZSH has no chance to save the histfile anymore.  As a
> workaround I can just quit ZSH before terminating terminology using the
> "exit" command.

The terminal should send SIGHUP to the shell and give it a chance to
handle it.

If you do

TRAPHUP() {
  print "Exiting on signal" >~/zsh_exited
  exit
}

do you see the message being written to the file ~/zsh_exited?

pws


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ZSH history not saved anymore
  2014-09-24 19:07 ` Peter Stephenson
@ 2014-09-25  7:10   ` Tassilo Horn
  2014-09-26  7:04     ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Tassilo Horn @ 2014-09-25  7:10 UTC (permalink / raw)
  To: zsh-users

Peter Stephenson <p.w.stephenson@ntlworld.com> writes:

Hi Peter,

>> I've just started using enlightenment 19 coming from Gnome.  Now my
>> terminal emulator is terminology instead of gnome-terminal.
>> 
>> Today, I've noticed that since then my ZSH history file doesn't get
>> updated anymore.  That is, when terminating the terminal emulator, it
>> seems that ZSH has no chance to save the histfile anymore.  As a
>> workaround I can just quit ZSH before terminating terminology using
>> the "exit" command.
>
> The terminal should send SIGHUP to the shell and give it a chance to
> handle it.
>
> 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.

Bye,
Tassilo


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ZSH history not saved anymore
  2014-09-25  7:10   ` Tassilo Horn
@ 2014-09-26  7:04     ` Bart Schaefer
  2014-09-26  8:15       ` Tassilo Horn
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2014-09-26  7:04 UTC (permalink / raw)
  To: zsh-users

On Sep 25,  9:10am, Tassilo Horn wrote:
}
} > 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.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ZSH history not saved anymore
  2014-09-26  7:04     ` Bart Schaefer
@ 2014-09-26  8:15       ` Tassilo Horn
  2014-09-26 14:58         ` Kurtis Rader
  0 siblings, 1 reply; 9+ messages in thread
From: Tassilo Horn @ 2014-09-26  8:15 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer <schaefer@brasslantern.com> 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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ZSH history not saved anymore
  2014-09-26  8:15       ` Tassilo Horn
@ 2014-09-26 14:58         ` Kurtis Rader
  2014-09-26 20:04           ` Tassilo Horn
  0 siblings, 1 reply; 9+ messages in thread
From: Kurtis Rader @ 2014-09-26 14:58 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 2470 bytes --]

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@gnu.org> wrote:

> Bart Schaefer <schaefer@brasslantern.com> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ZSH history not saved anymore
  2014-09-26 14:58         ` Kurtis Rader
@ 2014-09-26 20:04           ` Tassilo Horn
  2014-09-26 20:34             ` Kurtis Rader
  0 siblings, 1 reply; 9+ messages in thread
From: Tassilo Horn @ 2014-09-26 20:04 UTC (permalink / raw)
  To: Kurtis Rader; +Cc: Zsh Users

Kurtis Rader <krader@skepticism.us> writes:

Hi Kurtis,

> In a different window execute one of the printed kill commands then
>
> cat /tmp/x

Ok, I didn't rm /tmp/x in /tmp/z, so after executing the three printed
commands one after the other, the file contains:

  exiting on HUP
  exiting on TERM

> Notice that your traps for SIGHUP and SIGTERM are honored but the trap
> for SIGKILL is not.

Indeed.

> 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.

I've written a bug report, so if they really send a SIGKILL that'll
hopefully change anytime soon.

> 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).

The last lines when closing the terminal emulator are:

--8<---------------cut here---------------start------------->8---
close(7)                                = 0
munmap(0x7f9e899e6000, 2105616)         = 0
select(6, [5], NULL, NULL, {0, 105000}) = 0 (Timeout)
epoll_ctl(3, EPOLL_CTL_DEL, 5, 7fff4eb6e6b0) = 0
close(5)                                = 0
close(6)                                = 0
rt_sigaction(SIGPIPE, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f9e96e7e200}, NULL, 8) = 0
rt_sigaction(SIGALRM, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f9e96e7e200}, NULL, 8) = 0
rt_sigaction(SIGCHLD, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f9e96e7e200}, NULL, 8) = 0
rt_sigaction(SIGUSR1, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f9e96e7e200}, NULL, 8) = 0
rt_sigaction(SIGUSR2, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f9e96e7e200}, NULL, 8) = 0
rt_sigaction(SIGHUP, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f9e96e7e200}, NULL, 8) = 0
rt_sigaction(SIGQUIT, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f9e96e7e200}, NULL, 8) = 0
rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f9e96e7e200}, NULL, 8) = 0
rt_sigaction(SIGTERM, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f9e96e7e200}, NULL, 8) = 0
close(4)                                = 0
close(3)                                = 0
munmap(0x7f9e97d54000, 16384)           = 0
munmap(0x7f9e97d44000, 65536)           = 0
exit_group(0)                           = ?
+++ exited with 0 +++
--8<---------------cut here---------------end--------------->8---

And when I do "strace -p<pid-of-zsh-inside-other-term>" and then close
the other term, those are the last lines.

--8<---------------cut here---------------start------------->8---
getuid()                                = 1000
geteuid()                               = 1000
capget({_LINUX_CAPABILITY_VERSION_3, 0}, NULL) = 0
capget({_LINUX_CAPABILITY_VERSION_3, 0}, {0, 0, 0}) = 0
ioctl(10, FIONREAD, [0])                = 0
ioctl(10, SNDRV_TIMER_IOCTL_SELECT or TIOCSPGRP, [4641]) = 0
ioctl(10, SNDCTL_TMR_STOP or SNDRV_TIMER_IOCTL_GINFO or TCSETSW, {B38400 opost isig -icanon -echo ...}) = 0
write(10, "\r\33[0m\33[27m\33[24m\33[J\33[34m\33[1m[\33[0m"..., 267) = 267
write(10, "\33[K", 3)                   = 3
rt_sigprocmask(SIG_UNBLOCK, [WINCH], [WINCH], 8) = 0
read(10, 0x7fff7944683f, 1)             = -1 EIO (Input/output error)
--- SIGHUP {si_signo=SIGHUP, si_code=SI_KERNEL} ---
--- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=4637, si_uid=1000} ---
+++ killed by SIGPIPE +++
--8<---------------cut here---------------end--------------->8---

Hm, so it seems ZSH does receive a SIGHUP and then a SIGPIPE which I
think is the EOF Bart talked about.

Bye,
Tassilo


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ZSH history not saved anymore
  2014-09-26 20:04           ` Tassilo Horn
@ 2014-09-26 20:34             ` Kurtis Rader
  2014-09-27  8:05               ` Tassilo Horn
  0 siblings, 1 reply; 9+ messages in thread
From: Kurtis Rader @ 2014-09-26 20:34 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 4946 bytes --]

The problem is the SIGPIPE. It's terminating the shell before it has a
chance to handle the SIGHUP. Notice that the SIGPIPE was sent by the user
process with pid 4637 running as uid 1000. I'll bet that you'll find that
user ID is yours and the pid is the terminal emulator. If you look earlier
in the strace output for the terminal emulator you should be able to find
the kill syscall that sent the SIGPIPE. I have no idea why the emulator
feels the need to send SIGPIPE -- that's a very peculiar thing to do.
Obviously you can work around the problem by telling zsh to trap that
signal:

TRAPPIPE() {
    exit
}


On Fri, Sep 26, 2014 at 1:04 PM, Tassilo Horn <tsdh@gnu.org> wrote:

> Kurtis Rader <krader@skepticism.us> writes:
>
> Hi Kurtis,
>
> > In a different window execute one of the printed kill commands then
> >
> > cat /tmp/x
>
> Ok, I didn't rm /tmp/x in /tmp/z, so after executing the three printed
> commands one after the other, the file contains:
>
>   exiting on HUP
>   exiting on TERM
>
> > Notice that your traps for SIGHUP and SIGTERM are honored but the trap
> > for SIGKILL is not.
>
> Indeed.
>
> > 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.
>
> I've written a bug report, so if they really send a SIGKILL that'll
> hopefully change anytime soon.
>
> > 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).
>
> The last lines when closing the terminal emulator are:
>
> --8<---------------cut here---------------start------------->8---
> close(7)                                = 0
> munmap(0x7f9e899e6000, 2105616)         = 0
> select(6, [5], NULL, NULL, {0, 105000}) = 0 (Timeout)
> epoll_ctl(3, EPOLL_CTL_DEL, 5, 7fff4eb6e6b0) = 0
> close(5)                                = 0
> close(6)                                = 0
> rt_sigaction(SIGPIPE, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO,
> 0x7f9e96e7e200}, NULL, 8) = 0
> rt_sigaction(SIGALRM, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO,
> 0x7f9e96e7e200}, NULL, 8) = 0
> rt_sigaction(SIGCHLD, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO,
> 0x7f9e96e7e200}, NULL, 8) = 0
> rt_sigaction(SIGUSR1, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO,
> 0x7f9e96e7e200}, NULL, 8) = 0
> rt_sigaction(SIGUSR2, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO,
> 0x7f9e96e7e200}, NULL, 8) = 0
> rt_sigaction(SIGHUP, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO,
> 0x7f9e96e7e200}, NULL, 8) = 0
> rt_sigaction(SIGQUIT, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO,
> 0x7f9e96e7e200}, NULL, 8) = 0
> rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO,
> 0x7f9e96e7e200}, NULL, 8) = 0
> rt_sigaction(SIGTERM, {SIG_DFL, [], SA_RESTORER|SA_RESTART|SA_SIGINFO,
> 0x7f9e96e7e200}, NULL, 8) = 0
> close(4)                                = 0
> close(3)                                = 0
> munmap(0x7f9e97d54000, 16384)           = 0
> munmap(0x7f9e97d44000, 65536)           = 0
> exit_group(0)                           = ?
> +++ exited with 0 +++
> --8<---------------cut here---------------end--------------->8---
>
> And when I do "strace -p<pid-of-zsh-inside-other-term>" and then close
> the other term, those are the last lines.
>
> --8<---------------cut here---------------start------------->8---
> getuid()                                = 1000
> geteuid()                               = 1000
> capget({_LINUX_CAPABILITY_VERSION_3, 0}, NULL) = 0
> capget({_LINUX_CAPABILITY_VERSION_3, 0}, {0, 0, 0}) = 0
> ioctl(10, FIONREAD, [0])                = 0
> ioctl(10, SNDRV_TIMER_IOCTL_SELECT or TIOCSPGRP, [4641]) = 0
> ioctl(10, SNDCTL_TMR_STOP or SNDRV_TIMER_IOCTL_GINFO or TCSETSW, {B38400
> opost isig -icanon -echo ...}) = 0
> write(10, "\r\33[0m\33[27m\33[24m\33[J\33[34m\33[1m[\33[0m"..., 267) = 267
> write(10, "\33[K", 3)                   = 3
> rt_sigprocmask(SIG_UNBLOCK, [WINCH], [WINCH], 8) = 0
> read(10, 0x7fff7944683f, 1)             = -1 EIO (Input/output error)
> --- SIGHUP {si_signo=SIGHUP, si_code=SI_KERNEL} ---
> --- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=4637, si_uid=1000}
> ---
> +++ killed by SIGPIPE +++
> --8<---------------cut here---------------end--------------->8---
>
> Hm, so it seems ZSH does receive a SIGHUP and then a SIGPIPE which I
> think is the EOF Bart talked about.
>
> Bye,
> Tassilo
>



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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ZSH history not saved anymore
  2014-09-26 20:34             ` Kurtis Rader
@ 2014-09-27  8:05               ` Tassilo Horn
  0 siblings, 0 replies; 9+ messages in thread
From: Tassilo Horn @ 2014-09-27  8:05 UTC (permalink / raw)
  To: Kurtis Rader; +Cc: Zsh Users

Kurtis Rader <krader@skepticism.us> writes:

Hi Kurtis,

> The problem is the SIGPIPE. It's terminating the shell before it has a
> chance to handle the SIGHUP. Notice that the SIGPIPE was sent by the user
> process with pid 4637 running as uid 1000. I'll bet that you'll find that
> user ID is yours

Yes.

> and the pid is the terminal emulator.

Yes.

> If you look earlier in the strace output for the terminal emulator you
> should be able to find the kill syscall that sent the SIGPIPE. I have
> no idea why the emulator feels the need to send SIGPIPE -- that's a
> very peculiar thing to do.

Indeed.  ZSH has pid 2019 in here:

--8<---------------cut here---------------start------------->8---
munmap(0x7f1291b1c000, 7680000)         = 0
close(23)                               = 0
futex(0x25322d8, FUTEX_WAKE, 1)         = 1
close(22)                               = 0
kill(2029, SIGCONT)                     = 0
kill(2029, SIGPIPE)                     = 0
wait4(2029, 0x7fffb1676de4, WNOHANG, NULL) = 0
nanosleep({0, 1000000}, NULL)           = ? ERESTART_RESTARTBLOCK (Interrupted by signal)
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=2029, si_uid=1000, si_status=SIGPIPE, si_utime=4, si_stime=0} ---
rt_sigreturn()                          = -1 EINTR (Interrupted system call)
wait4(2029, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGPIPE}], WNOHANG, NULL) = 2029
epoll_ctl(3, EPOLL_CTL_DEL, 22, 7fffb1676d80) = -1 EBADF (Bad file descriptor)
[...]
+++ exited with 0 +++
--8<---------------cut here---------------end--------------->8---

> Obviously you can work around the problem by telling zsh to trap that
> signal:
>
> TRAPPIPE() {
>     exit
> }

Yes, that works.  So I'll keep that in my ~/.zshrc for the time being.

Thanks for your help, Kurtis!

Bye,
Tassilo


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-09-27  8:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-23 21:03 ZSH history not saved anymore Tassilo Horn
2014-09-24 19:07 ` Peter Stephenson
2014-09-25  7:10   ` Tassilo Horn
2014-09-26  7:04     ` Bart Schaefer
2014-09-26  8:15       ` Tassilo Horn
2014-09-26 14:58         ` Kurtis Rader
2014-09-26 20:04           ` Tassilo Horn
2014-09-26 20:34             ` Kurtis Rader
2014-09-27  8:05               ` Tassilo Horn

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).