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 92FCA5A0268 for ; Wed, 8 Feb 2023 16:55:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675871703; 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=0s1JGdvORVLr+Cm+U9SB2V/QNGZNeS9Y1ouZhJFqZXI=; b=ItCKepphUdqlqAdCzwpLQ+nak5gT3PBQOU/QSFma8OVZSwha9AOnDp0x7ntib5dMNC604w ka9pUW+Qq30Smj6ukgJuvBW3at5ngz0pTiyowKslhKNNj/F8lYGv8KY1lNB68SwDduSLjK 6pPJQpi/K6sl0dvwP5BwDZmhlehw8Us= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-394-1-xg_kWOPla0wG0uCVo9Wg-1; Wed, 08 Feb 2023 10:55:02 -0500 X-MC-Unique: 1-xg_kWOPla0wG0uCVo9Wg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EF96829AB400 for ; Wed, 8 Feb 2023 15:55:01 +0000 (UTC) Received: from pholzing-fedora.redhat.com (unknown [10.39.193.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A4FD492C3E; Wed, 8 Feb 2023 15:55:01 +0000 (UTC) From: Paul Holzinger To: passt-dev@passt.top Subject: [PATCH 2/2] pasta: propagate exit code from child command Date: Wed, 8 Feb 2023 16:54:41 +0100 Message-Id: <20230208155441.64306-2-pholzing@redhat.com> In-Reply-To: <20230208155441.64306-1-pholzing@redhat.com> References: <20230208155441.64306-1-pholzing@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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: 7DASLV6AOBDG2GGGXI6C6HXGL3EQAVBL X-Message-ID-Hash: 7DASLV6AOBDG2GGGXI6C6HXGL3EQAVBL X-Mailman-Approved-At: Wed, 08 Feb 2023 17:27:13 +0100 CC: Paul Holzinger 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: 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 */ + exit(infop.si_status + 128); + } + /* Nothing to do, detached PID namespace going away */ } waitid(P_ALL, 0, NULL, WEXITED | WNOHANG); -- 2.39.1