From 479a079e6d0ec3f25e4ca0b6ae12eb95dbe63950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberts=20Muktup=C4=81vels?= Date: Thu, 8 Dec 2016 18:45:02 +0200 Subject: Retry read call in session.c if it fails with EINTR. --- src/session.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/session.c b/src/session.c index 15598425..2c05114f 100644 --- a/src/session.c +++ b/src/session.c @@ -404,9 +404,14 @@ static ssize_t read_from_child (Session *session, void *buf, size_t count) { ssize_t n_read; - n_read = read (session->priv->from_child_output, buf, count); - if (n_read < 0) - l_warning (session, "Error reading from session: %s", strerror (errno)); + while ((n_read = read (session->priv->from_child_output, buf, count)) < 0) + { + if (errno != EINTR) + { + l_warning (session, "Error reading from session: %s", strerror (errno)); + return n_read; + } + } return n_read; } -- cgit v1.2.1 From 3b58d1493efd98f11ab578d9b8a7e650d800806e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberts=20Muktup=C4=81vels?= Date: Thu, 8 Dec 2016 23:32:24 +0200 Subject: Use SA_RESTART flag. --- src/process.c | 2 +- src/session.c | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/process.c b/src/process.c index 75357db6..6f07e4e5 100644 --- a/src/process.c +++ b/src/process.c @@ -458,7 +458,7 @@ process_class_init (ProcessClass *klass) g_io_add_watch (g_io_channel_unix_new (signal_pipe[0]), G_IO_IN, handle_signal, NULL); action.sa_sigaction = signal_cb; sigemptyset (&action.sa_mask); - action.sa_flags = SA_SIGINFO; + action.sa_flags = SA_SIGINFO | SA_RESTART; sigaction (SIGTERM, &action, NULL); sigaction (SIGINT, &action, NULL); sigaction (SIGHUP, &action, NULL); diff --git a/src/session.c b/src/session.c index 2c05114f..15598425 100644 --- a/src/session.c +++ b/src/session.c @@ -404,14 +404,9 @@ static ssize_t read_from_child (Session *session, void *buf, size_t count) { ssize_t n_read; - while ((n_read = read (session->priv->from_child_output, buf, count)) < 0) - { - if (errno != EINTR) - { - l_warning (session, "Error reading from session: %s", strerror (errno)); - return n_read; - } - } + n_read = read (session->priv->from_child_output, buf, count); + if (n_read < 0) + l_warning (session, "Error reading from session: %s", strerror (errno)); return n_read; } -- cgit v1.2.1