From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id B8D705A004E for ; Sat, 03 Aug 2024 06:02:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1722657725; bh=gJMmmk/kYt3Va3SK/TUxy0eehmG/gl/uPq/STkOZz6U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hvyd3rrqkNFMrV6TobD564JUsrA9Ju7qSeS8E9MRxg8u6eKt6fWtURQoAj0+JTFEe jZPuVZ1oJLrVmPSaEUDHKzUr5f5VDlb/LGD2OEIwGIYD9U5vz9H+MTj6fdWg00dz03 eBSkqKmqVdpRBqkwKDewD9Q7+xbNTP7FflJWvWD+Ex+mRCuXM/LhsggKedyXtGCwZh FA+OR5HAb0zQsyuaapCnI66p5wig5BgtWAFcIbKoD5fAPbQh9FdC/xvQqNokbfO2hU /Xev5ShR9IyIxmNGNxDmH9aPvTfAr8jIb3wOQIhScrHuDliAE6wqSaW1ELDaoifO0O 9d5lojGJN9kSA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WbTY90M0Wz4wcl; Sat, 3 Aug 2024 14:02:05 +1000 (AEST) Date: Sat, 3 Aug 2024 13:59:55 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] pasta: Save errno on signal handler entry, restore on return when needed Message-ID: References: <20240802133448.3778368-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="evVb17LVGCRnu4y3" Content-Disposition: inline In-Reply-To: <20240802133448.3778368-1-sbrivio@redhat.com> Message-ID-Hash: DWAWPZTDHQIM7XDNMJA7MLEMPX2J2RO4 X-Message-ID-Hash: DWAWPZTDHQIM7XDNMJA7MLEMPX2J2RO4 X-MailFrom: dgibson@gandalf.ozlabs.org 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: passt-dev@passt.top, 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: --evVb17LVGCRnu4y3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 02, 2024 at 03:34:48PM +0200, Stefano Brivio wrote: > Ed reported this: >=20 > # Error: pasta failed with exit code 1: > # Couldn't drop cap 3 from bounding set > # : No child processes >=20 > 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()? >=20 > 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: >=20 > 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. >=20 > Eventually, we'll probably need to switch to signalfd(2) the day we > want to implement multithreading, but this will do for the moment. >=20 > Reported-by: Ed Santiago > Link: https://github.com/containers/podman/issues/23478 > Signed-off-by: Stefano Brivio Ouch. errno, another of those awful APIs we're stuck with :/ Reviewed-by: David Gibson > --- > pasta.c | 3 +++ > 1 file changed, 3 insertions(+) >=20 > 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 =3D errno; > siginfo_t infop; > =20 > (void)signal; > @@ -85,6 +86,8 @@ void pasta_child_handler(int signal) > =20 > waitid(P_ALL, 0, NULL, WEXITED | WNOHANG); > waitid(P_ALL, 0, NULL, WEXITED | WNOHANG); > + > + errno =3D errno_save; > } > =20 > /** --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --evVb17LVGCRnu4y3 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmatqyoACgkQzQJF27ox 2GdgYhAAkgeNhlmVHP2sma/0HlUl4AVFxXFzos40kdvNfbPp7fRMX+nAU61hh6t2 JsDEB8hdVj0qv4kpS47Ecfm+wuItORhxD21gPtTOg/Ij4dO7rSfhYtaZV8dZNM/r Wt6E1z6tfxaCE3RtDYyAOg3hvyogH+TGGNp241VynhasG1nB5eLBQh6WU2D6quCi lv/XbGFzPl6kFsJexOPZNP1lp27O7ZWd25HHnla/OCkdFZw8YONQUqqloXOqaJV5 EXj0Kx3Sr55O8rQmEHj4+/M1fKAR+/cbnb79KTKMOFewtMjgQx7dUjToo0oTTcLS x/MB5KFzSk6bLAP03CD8ftvkEtghAYkoAJAJEU7L4NWrXvrZkzKAhTUhR5Tv7bq1 JxN8Sc0aAu2OFx9YiIwSS06SMY7FAPuYWYAxYyGY60WITtiOLghO/E1xN/u9pOXd M5AGK8jN44NU5vTC5e1Y/GA9qUDbGWZBrgcExvpdDNNHNgKRkfMGzXWdjNGu0ous 7dDDqaOcK9cyNz8QGOtnCdt6Qxojt9z6xVOZ7ShMDs0geZ5yHPlxX2vK4Ps9ukOp J0UJ+XMnED0EzOQf/bi/M0THuMNoCaHqi76FnTK/IdWbR3ztD4cTXFuCyZPO+4fs 0u52w7oWnzDlgRLSkaDoT/rfdkmcfbQgUvDRY77fO7QWUve9a2M= =61Bu -----END PGP SIGNATURE----- --evVb17LVGCRnu4y3--