From a4e28213c2b6e04514f61c1a1220c9e8aa9d9648 Mon Sep 17 00:00:00 2001 From: Vijay Dhanraj Date: Tue, 28 May 2019 17:52:49 -0700 Subject: [PATCH] DM: handle SIGPIPE signal Ignore SIGPIPE signal and handle the error directly when write() function fails. this will help us to catch the write failure rather than crashing the UOS. PS: Observed that when acrnctl stop command was issued from kata-runtime, UOS was crashing with SIGPIPE signal. Tracked-On: #3190 Signed-off-by: Vijay Dhanraj Acked-by: Yu Wang --- devicemodel/core/main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index 2423e21cb..bd9532f2a 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -785,6 +785,13 @@ main(int argc, char *argv[]) fprintf(stderr, "cannot register handler for SIGHUP\n"); if (signal(SIGINT, sig_handler_term) == SIG_ERR) fprintf(stderr, "cannot register handler for SIGINT\n"); + /* + * Ignore SIGPIPE signal and handle the error directly when write() + * function fails. this will help us to catch the write failure rather + * than crashing the UOS. + */ + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) + fprintf(stderr, "cannot register handler for SIGPIPE\n"); while ((c = getopt_long(argc, argv, optstr, long_options, &option_idx)) != -1) {