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

SIGPIPE (Re: ZSH history not saved anymore)



On Sep 27, 10:05am, Tassilo Horn wrote:
} Subject: Re: ZSH history not saved anymore
}
} > 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.

I'm a bit hesitant to change this after all these years, but perhaps an
interactive shell should exit on SIGPIPE if the terminal is not still open?

I'm probably missing something having to do with subshells receiving the
PIPE signal.  There are regrettably many code paths covering all the ways
an interactive shell might fork.

diff --git a/Src/init.c b/Src/init.c
index 40f46a8..6d005dc 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -1134,6 +1134,7 @@ init_signals(void)
     winch_block();	/* See utils.c:preprompt() */
 #endif
     if (interact) {
+	install_handler(SIGPIPE);
 	install_handler(SIGALRM);
 	signal_ignore(SIGTERM);
     }
diff --git a/Src/signals.c b/Src/signals.c
index cb2b581..094b4b0 100644
--- a/Src/signals.c
+++ b/Src/signals.c
@@ -594,6 +594,17 @@ zhandler(int sig)
 	wait_for_processes();
         break;
  
+    case SIGPIPE:
+	if (!handletrap(SIGPIPE)) {
+	    if (!interact)
+		_exit(SIGPIPE);
+	    else if (!isatty(SHTTY)) {
+		stopmsg = 1;
+		zexit(SIGPIPE, 1);
+	    }
+	}
+	break;
+
     case SIGHUP:
         if (!handletrap(SIGHUP)) {
             stopmsg = 1;



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