zsh-users
 help / color / mirror / code / Atom feed
From: Kurtis Rader <krader@skepticism.us>
To: Tassilo Horn <tsdh@gnu.org>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: ZSH history not saved anymore
Date: Fri, 26 Sep 2014 13:34:37 -0700	[thread overview]
Message-ID: <CABx2=D-chwqBDZLTk8OqeUDqxvnYUQFFKWbiw7h3ZgUGtSb_CQ@mail.gmail.com> (raw)
In-Reply-To: <87y4t66td0.fsf@thinkpad-t440p.tsdh.org>

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

  reply	other threads:[~2014-09-26 20:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-23 21:03 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 [this message]
2014-09-27  8:05               ` Tassilo Horn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABx2=D-chwqBDZLTk8OqeUDqxvnYUQFFKWbiw7h3ZgUGtSb_CQ@mail.gmail.com' \
    --to=krader@skepticism.us \
    --cc=tsdh@gnu.org \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).