[PATCH 5/5] unshare: handle EINTR in waitpid loop

Kiran Rangoon <[email protected]> Thu, 8 Jan 2026 13:31:34 -0500
Newsgroups org.kernel.vger.util-linux
Message-ID <[email protected]>
Modify waitpid() to retry on EINTR. When the signal handler forwards
a signal to the child, waitpid() can be interrupted. We need to retry
in this case instead of failing.

Signed-off-by: Kiran Rangoon <[email protected]>
---
 sys-utils/unshare.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c
index 8bc805e05..2ced8b7a8 100644
--- a/sys-utils/unshare.c
+++ b/sys-utils/unshare.c
@@ -1172,7 +1172,14 @@ int main(int argc, char *argv[])
 	}
 
 	if (pid) {
-		if (waitpid(pid, &status, 0) == -1)
+		int rc;
+
+		/* Wait for child, handling EINTR from signal forwarding */
+		do {
+			rc = waitpid(pid, &status, 0);
+		} while (rc == -1 && errno == EINTR);
+
+		if (rc == -1)
 			err(EXIT_FAILURE, _("waitpid failed"));
 
 		if (WIFEXITED(status))
-- 
2.47.3