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.129.124]) by passt.top (Postfix) with ESMTP id B008A5A005E for ; Thu, 9 Feb 2023 16:00:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675954819; 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; bh=QG4YY+TVx5bDChgaMCdi2/NQjh1OOdSlrMbiqjkLPVM=; b=FUhITxPIkWKPFZPvJ5tU6/kUtu3o0mQNT3fMwxH0VS0+sQ5XQ2MpjByuucEocHZrmdxHTl k61KWLFuVo7/drij/WnbCrIXmjmxr9J2VmcBI7S2vJeFrFwXMziS5mEBpbdZZi8nNrmI8+ RWo5eQmBzFwTxu0PbK3Sj91Hd0CUS+c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-673-nf0r9V6TPwqjJaxA6H8-Gg-1; Thu, 09 Feb 2023 10:00:18 -0500 X-MC-Unique: nf0r9V6TPwqjJaxA6H8-Gg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BB4E7181E3F7 for ; Thu, 9 Feb 2023 15:00:17 +0000 (UTC) Received: from pholzing-fedora.redhat.com (unknown [10.39.194.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0920C492C3F; Thu, 9 Feb 2023 15:00:16 +0000 (UTC) From: Paul Holzinger To: passt-dev@passt.top Subject: [PATCH v2] pasta: propagate exit code from child command Date: Thu, 9 Feb 2023 15:59:49 +0100 Message-Id: <20230209145948.20773-1-pholzing@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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: 7LDXLWTBEO7BSW27MGNI5W3XVO527MTW X-Message-ID-Hash: 7LDXLWTBEO7BSW27MGNI5W3XVO527MTW X-Mailman-Approved-At: Thu, 09 Feb 2023 17:19:51 +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 --- Changes from v1: - Fixed comments from Stefano. pasta.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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) if (pasta_child_pid && !waitid(P_PID, pasta_child_pid, &infop, WEXITED | WNOHANG)) { - if (infop.si_pid == pasta_child_pid) - exit(EXIT_SUCCESS); + if (infop.si_pid == pasta_child_pid) { + if (infop.si_code == 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 */ + } } waitid(P_ALL, 0, NULL, WEXITED | WNOHANG); -- 2.39.1