From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id C91FC5A0268 for ; Mon, 13 Feb 2023 04:12:05 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PFTsG0MKmz4x84; Mon, 13 Feb 2023 14:12:02 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1676257922; bh=6zjs14fkrJj9sMFyPl4T9T5Tv4eH8GrwUHRAt2wlqWA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=a5o3M6SyileC6T+z1YdUFvppCredbk41tTAInjqzXJdSYbc7ax3db9WD1fs2ouQ0y ojExSBY/R4nzrSl1VUKPTg2J7ys6wyomPwqtEVKB/APpJ0xti1w3kzOylpWfiFHeX7 LRLtZ39YxM7MfLIrZHGzJmOqhqGVfwb/eY/9x9gI= Date: Mon, 13 Feb 2023 13:37:12 +1100 From: David Gibson To: Paul Holzinger Subject: Re: [PATCH v2] pasta: propagate exit code from child command Message-ID: References: <20230209145948.20773-1-pholzing@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="9J8KMmucpzndJuzz" Content-Disposition: inline In-Reply-To: <20230209145948.20773-1-pholzing@redhat.com> Message-ID-Hash: IY24HVYQ43RRWL47FIW3WVP54M2D7ILH X-Message-ID-Hash: IY24HVYQ43RRWL47FIW3WVP54M2D7ILH 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 X-Mailman-Version: 3.3.3 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: --9J8KMmucpzndJuzz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Feb 09, 2023 at 03:59:49PM +0100, Paul Holzinger wrote: > Exits codes are very useful for scripts, when the pasta child execvp() > call fails with ENOENT that parent should also exit with > 0. In short > the parent should always exit with the code from the child to make it > useful in scripts. >=20 > It is easy to test with: `pasta -- bash -c "exit 3"; echo $?` >=20 > Signed-off-by: Paul Holzinger Oops, I'm a little embarrassed I didn't think of that before. Reviewed-by: David Gibson > --- > Changes from v1: > - Fixed comments from Stefano. >=20 > pasta.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) >=20 > diff --git a/pasta.c b/pasta.c > index 3f6477c..fe21c5b 100644 > --- a/pasta.c > +++ b/pasta.c > @@ -64,9 +64,17 @@ void pasta_child_handler(int signal) > =20 > if (pasta_child_pid && > !waitid(P_PID, pasta_child_pid, &infop, WEXITED | WNOHANG)) { > - if (infop.si_pid =3D=3D pasta_child_pid) > - exit(EXIT_SUCCESS); > + if (infop.si_pid =3D=3D pasta_child_pid) { > + if (infop.si_code =3D=3D CLD_EXITED) > + exit(infop.si_status); > + > + /* If killed by a signal, si_status is the number. > + * Follow common shell convention of returning it + 128. > + */ > + exit(infop.si_status + 128); > + > /* Nothing to do, detached PID namespace going away */ > + } > } > =20 > waitid(P_ALL, 0, NULL, WEXITED | WNOHANG); --=20 David Gibson | 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 --9J8KMmucpzndJuzz Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmPpolIACgkQzQJF27ox 2GfowA/+LVaGtsmqBugjN4Zgj9L7RTLxrzqSBv4Ink5KCr0IFcVB2VhVNHrdH4/x qfs68V2zqe3iQP4vVfXMFakctAFlwWQ/weq5Ib7pmSnz50TFYZLKYEF5JFbnF4SJ OVFERHZIsxwhGiNZatV7sdixbJi0THlf9dPGfOkf9F53HBJCsgUb8J9DMW3+Mczm 42rUzenN74IpCImlVJAT0xWo4PxrJLveTzLuSmEcaWpVxyNV9oByz5/jNaBsstjp AOc5+76CgOuWISg/H9NYR1lhx9zY4dyH6YlYQ4lJs4IDbMup8BdHejZIvEmGG3/S 1kpNciuINp7EXfF0CgmLAGxkCO7hON1FKWjYINlS0oA16q6UpOF364I96B+pNc28 ux3Nveuv7Poyb0OCV9q/kthP9t2pE70ENlxwXebq/V43VWZnQ6H4JKBODYd7ZbQa SYbwhF/KOwsFRuAvJgZMGzylYMQKpZdkknSoeKBWE7iSbIQ32Bg+pRFQfiXWsnNZ DxzNbwo6V9M2raJ9A6M3vZbnjUUFLT5jZpVDbX9RiRXSQ2f8/DnKXip4J1jqxk7u xDWBVc2u8GYlY5FtIQxeBjaO4oT8XYWCVH1IWE4hIbOO/k1DEbZHvNLlfeitOxDm f+GQw86pHn/x1fzj0mcAcDvjzrJDbbMhDF1KwanZwPtXVj6bveM= =kAUE -----END PGP SIGNATURE----- --9J8KMmucpzndJuzz--