From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Cc: Valtteri Vuorikoski <vuori@notcom.org>,
David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH] passt: Fix error check for signal(), improve error messages
Date: Thu, 13 Apr 2023 19:45:57 +0200 [thread overview]
Message-ID: <20230413174557.1482799-1-sbrivio@redhat.com> (raw)
Valtteri reports that if SIGPIPE already has a disposition set by the
parent process, such as systemd with the default setting of
IgnoreSIGPIPE=yes, signal() will return the previous value, not zero,
and this is not an error: check for SIG_ERR instead.
While at it, split messages for failures of sigaction() and signal(),
and report the actual error.
Reported-by: Valtteri Vuorikoski <vuori@notcom.org>
Fixes: 8534be076c73 ("Catch failures when installing signal handlers")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
passt.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/passt.c b/passt.c
index 7fa1170..3b9b36b 100644
--- a/passt.c
+++ b/passt.c
@@ -204,8 +204,15 @@ int main(int argc, char **argv)
name = basename(argv0);
if (strstr(name, "pasta")) {
sa.sa_handler = pasta_child_handler;
- if (sigaction(SIGCHLD, &sa, NULL) || signal(SIGPIPE, SIG_IGN))
- die("Couldn't install signal handlers");
+ if (sigaction(SIGCHLD, &sa, NULL)) {
+ die("Couldn't install signal handlers: %s",
+ strerror(errno));
+ }
+
+ if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
+ die("Couldn't set disposition for SIGPIPE: %s",
+ strerror(errno));
+ }
c.mode = MODE_PASTA;
log_name = "pasta";
--
@@ -204,8 +204,15 @@ int main(int argc, char **argv)
name = basename(argv0);
if (strstr(name, "pasta")) {
sa.sa_handler = pasta_child_handler;
- if (sigaction(SIGCHLD, &sa, NULL) || signal(SIGPIPE, SIG_IGN))
- die("Couldn't install signal handlers");
+ if (sigaction(SIGCHLD, &sa, NULL)) {
+ die("Couldn't install signal handlers: %s",
+ strerror(errno));
+ }
+
+ if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
+ die("Couldn't set disposition for SIGPIPE: %s",
+ strerror(errno));
+ }
c.mode = MODE_PASTA;
log_name = "pasta";
--
2.39.2
reply other threads:[~2023-04-13 17:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230413174557.1482799-1-sbrivio@redhat.com \
--to=sbrivio@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=vuori@notcom.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).