From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id 01CC35A026E; Thu, 13 Apr 2023 19:45:57 +0200 (CEST) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH] passt: Fix error check for signal(), improve error messages Date: Thu, 13 Apr 2023 19:45:57 +0200 Message-Id: <20230413174557.1482799-1-sbrivio@redhat.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: EI6WK66RYRGTCUYBIT5NREYTWVVSDGGE X-Message-ID-Hash: EI6WK66RYRGTCUYBIT5NREYTWVVSDGGE X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Valtteri Vuorikoski , David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 Fixes: 8534be076c73 ("Catch failures when installing signal handlers") Signed-off-by: Stefano Brivio --- 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"; -- 2.39.2