From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 030755A005E for ; Thu, 9 Feb 2023 15:23:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675952598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q5jyvQ65IpC3PVUAdcW4hvypZMWLIGQl4ESGTaaa6B4=; b=HlS72aNvJrquWXSzVfs9lnGnG/6gunomUcoH1Fe8OCd3TsIjcNvgXIRhSn9JrcjIITW2lI CP1bWE3cpx3Z1YWxPpqoTAS7BVHf0VwU9evc8HKOcLKQOZvQuyHpHKyY1j4/1Zi9uNZ15X 6K6es/Idz735F8UOJkLyUKbW8BAW0QM= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-262-7aiHVCgRPh61rusKIrkq9w-1; Thu, 09 Feb 2023 09:23:17 -0500 X-MC-Unique: 7aiHVCgRPh61rusKIrkq9w-1 Received: by mail-wr1-f69.google.com with SMTP id a15-20020adfe5cf000000b002c500989222so487096wrn.5 for ; Thu, 09 Feb 2023 06:23:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Q5jyvQ65IpC3PVUAdcW4hvypZMWLIGQl4ESGTaaa6B4=; b=qaEIIswvVjIHk1WU4xjiLuio0P+jaGM9X7A/2SnxZihd2Y26xQoOUxzORz2lTsSk9h WbGJnIgQuzeJYJxenIJI8ibSam7eC8f71qPcx2GTWlZ7KA9gkIiPr2gXASM8Yaz1Ba+0 vUwrQuOvsbZpECuKROqZplDraACdcjgk1npqHTXcK4WtZfQFl65GwMcShETP3eZqvKbE cZHNN8JN+4hZoqluh1MrqCnbJ/4CdW7CX/WQSsvdWF+qmFQnhvJu7GWaK15lw6Dyp6K9 WWuH7VbGFX/5LasA/tSALTtUxGmugcqCvkCa2Bg4JZNMWIEpB6YGR68brlHUQ8EOAFnk YiVA== X-Gm-Message-State: AO0yUKVQNSOeuD5kcbSgaZEFhx3CreccMZdGIytmcPb/3vD4NW1shNt0 RrBy//oHB3QjdJTeZg9IrmUMw0dNgy7+yrAzWXckbrjd4+T0aBt3Ipc9XGtdks7iaegZtC8Ndjn jAbrHG5tBk1KC X-Received: by 2002:a05:600c:19d1:b0:3e0:15b:47b3 with SMTP id u17-20020a05600c19d100b003e0015b47b3mr10354468wmq.32.1675952596373; Thu, 09 Feb 2023 06:23:16 -0800 (PST) X-Google-Smtp-Source: AK7set/8wvuV2sNXWL+QgMpKGnUt9R3Lw2EwrdZMa+wgvnDoJufrvqOx0jEK8+kl+c33B5sqv3uprA== X-Received: by 2002:a05:600c:19d1:b0:3e0:15b:47b3 with SMTP id u17-20020a05600c19d100b003e0015b47b3mr10354456wmq.32.1675952596155; Thu, 09 Feb 2023 06:23:16 -0800 (PST) Received: from [192.168.188.25] ([80.243.52.135]) by smtp.gmail.com with ESMTPSA id s12-20020a05600c45cc00b003dfe5190376sm2180389wmo.35.2023.02.09.06.23.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Feb 2023 06:23:15 -0800 (PST) Message-ID: <3e14a8cd-0814-c9c3-f24d-25e126e31cc2@redhat.com> Date: Thu, 9 Feb 2023 15:23:14 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH 2/2] pasta: propagate exit code from child command To: Stefano Brivio References: <20230208155441.64306-1-pholzing@redhat.com> <20230208155441.64306-2-pholzing@redhat.com> <20230208191425.743197cd@elisabeth> From: Paul Holzinger In-Reply-To: <20230208191425.743197cd@elisabeth> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-MailFrom: pholzing@redhat.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation Message-ID-Hash: H7GBI536EU7IKST3DZF7CCUBHNPOZXO6 X-Message-ID-Hash: H7GBI536EU7IKST3DZF7CCUBHNPOZXO6 X-Mailman-Approved-At: Thu, 09 Feb 2023 17:19:50 +0100 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: Thanks for the feedback, I will send a v2 with the comments fixed. On 08/02/2023 19:14, Stefano Brivio wrote: > On Wed, 8 Feb 2023 16:54:41 +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. >> >> It is easy to test with: `pasta -- bash -c "exit 3"; echo $?` >> >> Signed-off-by: Paul Holzinger >> --- >> pasta.c | 11 ++++++++--- >> 1 file changed, 8 insertions(+), 3 deletions(-) >> >> diff --git a/pasta.c b/pasta.c >> index 3f6477c..4b18d7e 100644 >> --- a/pasta.c >> +++ b/pasta.c >> @@ -64,9 +64,14 @@ void pasta_child_handler(int signal) >> >> if (pasta_child_pid && >> !waitid(P_PID, pasta_child_pid, &infop, WEXITED | WNOHANG)) { >> - if (infop.si_pid == pasta_child_pid) >> - exit(EXIT_SUCCESS); >> - /* Nothing to do, detached PID namespace going away */ >> + if (infop.si_pid == pasta_child_pid) { >> + if (infop.si_code == CLD_EXITED) >> + exit(infop.si_status); >> + >> + /* else killed by signal, si_status == SIGNUM in this case */ > It took me a while to figure out that SIGNUM is not a constant I wasn't > aware of, just the signal number -- I guess you meant 'signum' from > sigaction() or suchlike? > > Maybe you could go with: > > /* If killed by a signal, si_status is its number */ > >> + exit(infop.si_status + 128); > This is a bit arbitrary -- returning n + 128 is what Bash, zsh, and a > few other shells do, and probably a reasonable convention given that > POSIX says we need to return a value greater than 128. Still I would > mention it: > > /* Arbitrary: return signal number + 128 */ > > or: > > /* If killed by a signal, si_status is the number. > * Follow common shell convention of returning it + 128. > */ The second suggestion sounds good to me. >> + } >> + /* Nothing to do, detached PID namespace going away */ > This should be moved back into the conditional block (swapping the two > lines above, or moving this comment at the beginning of the block). Whoops, this was by accident. > > If si_pid is not the child, we need to do other stuff (that is, reap > clones). > >> } >> >> waitid(P_ALL, 0, NULL, WEXITED | WNOHANG);