From 5f592c7855c4a1221facb282adb73156e949ecc0 Mon Sep 17 00:00:00 2001 From: Manuel Stoeckl Date: Mon, 19 Aug 2019 11:53:35 -0400 Subject: [PATCH] weston-terminal: Ignore SIGPIPE This ensures that the default signal action doesn't kill weston-terminal when the terminal tries to paste into a pipe whose read end has already been shut down. (For example, a pipe from a misconfigured program or from one which crashes/exits before the terminal calls write().) Signed-off-by: Manuel Stoeckl --- clients/terminal.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clients/terminal.c b/clients/terminal.c index 38e40207..ec767641 100644 --- a/clients/terminal.c +++ b/clients/terminal.c @@ -23,6 +23,7 @@ #include "config.h" +#include #include #include #include @@ -3127,6 +3128,7 @@ int main(int argc, char *argv[]) struct display *d; struct terminal *terminal; const char *config_file; + struct sigaction sigpipe; struct weston_config *config; struct weston_config_section *s; @@ -3157,6 +3159,14 @@ int main(int argc, char *argv[]) return 1; } + /* Disable SIGPIPE so that paste operations do not crash the program + * when the file descriptor provided to receive data is a pipe or + * socket whose reading end has been closed */ + sigpipe.sa_handler = SIG_IGN; + sigemptyset(&sigpipe.sa_mask); + sigpipe.sa_flags = 0; + sigaction(SIGPIPE, &sigpipe, NULL); + d = display_create(&argc, argv); if (d == NULL) { fprintf(stderr, "failed to create display: %s\n",