From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id 58C495A0319; Fri, 02 Aug 2024 15:34:48 +0200 (CEST) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH] pasta: Save errno on signal handler entry, restore on return when needed Date: Fri, 2 Aug 2024 15:34:48 +0200 Message-ID: <20240802133448.3778368-1-sbrivio@redhat.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: ODO2ONVT737A65PSWPJC4XCZGQZ5CZQO X-Message-ID-Hash: ODO2ONVT737A65PSWPJC4XCZGQZ5CZQO 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: Ed Santiago , Paul Holzinger 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: Ed reported this: # Error: pasta failed with exit code 1: # Couldn't drop cap 3 from bounding set # : No child processes in a Podman CI run with tests being run in parallel. The error message itself, by the way, is fixed by commit 1cd773081f12 ("log: Drop newlines in the middle of the perror()-like messages"), but how can we possibly get ECHILD as failure code for prctl()? Well, we don't, but if we exit early enough, pasta_child_handler() might run before we're even done with isolation steps, and it calls waitid(), which sets errno. We need to restore it before returning from the signal handler (if we return after calling functions that might set it), as signal-safety(7) also implies: Fetching and setting the value of errno is async-signal-safe provided that the signal handler saves errno on entry and restores its value before returning. Eventually, we'll probably need to switch to signalfd(2) the day we want to implement multithreading, but this will do for the moment. Reported-by: Ed Santiago Link: https://github.com/containers/podman/issues/23478 Signed-off-by: Stefano Brivio --- pasta.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pasta.c b/pasta.c index 572048d..b4a3d99 100644 --- a/pasta.c +++ b/pasta.c @@ -61,6 +61,7 @@ int pasta_child_pid; */ void pasta_child_handler(int signal) { + int errno_save = errno; siginfo_t infop; (void)signal; @@ -85,6 +86,8 @@ void pasta_child_handler(int signal) waitid(P_ALL, 0, NULL, WEXITED | WNOHANG); waitid(P_ALL, 0, NULL, WEXITED | WNOHANG); + + errno = errno_save; } /** -- 2.43.0