From f0ee8be8049b1a8d1ee0e307b4e7771cb0d9211c Mon Sep 17 00:00:00 2001
From: Marius Vlad <marius.vlad@collabora.com>
Date: Fri, 21 Feb 2025 14:50:41 +0200
Subject: [PATCH] terminal: Restore SIGPIPE signal handler to oldact (SIG_DFL)

Prior to executing a new command restore the parent process to the
default SIG_DLF handler as we normally use SIG_IGN it to avoid
crashing on pasted input.

As we seem to be hitting a Broken Pipe message when running
certain scripts, it seem we need to restore back the
default handler.

This is similar to what other folks have been doing in
https://github.com/labwc/labwc/issues/1209.

Fixes: #994

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
---
 clients/terminal.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clients/terminal.c b/clients/terminal.c
index 871391acf5..beeea4bc13 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -58,6 +58,7 @@ static char *option_term;
 static char *option_shell;
 
 static struct wl_list terminal_list;
+struct sigaction oldact;
 
 static struct terminal *
 terminal_create(struct display *display);
@@ -3100,6 +3101,9 @@ terminal_run(struct terminal *terminal, const char *path)
 		close(pipes[0]);
 		setenv("TERM", option_term, 1);
 		setenv("COLORTERM", option_term, 1);
+
+		sigaction(SIGPIPE, &oldact, NULL);
+
 		if (execl(path, path, NULL)) {
 			printf("exec failed: %s\n", strerror(errno));
 			exit(EXIT_FAILURE);
@@ -3177,8 +3181,10 @@ int main(int argc, char *argv[])
 	 * socket whose reading end has been closed */
 	sigpipe.sa_handler = SIG_IGN;
 	sigemptyset(&sigpipe.sa_mask);
+	sigemptyset(&oldact.sa_mask);
+
 	sigpipe.sa_flags = 0;
-	sigaction(SIGPIPE, &sigpipe, NULL);
+	sigaction(SIGPIPE, &sigpipe, &oldact);
 
 	d = display_create(&argc, argv);
 	if (d == NULL) {
-- 
GitLab