From patchwork Fri Feb 16 14:56:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 85884 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BAC4B3857C41 for ; Fri, 16 Feb 2024 14:57:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 35C5C385829E for ; Fri, 16 Feb 2024 14:56:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35C5C385829E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 35C5C385829E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708095409; cv=none; b=oVyhsxQ9dK/4G/DLLh14UCnpiI67gCSczJg7ntpHwFzJHIn13Oo0H/TPuhOMCGiZmsnUUYu0kdMhwaxv/L+eSykzYd7amBVYmVF8AwbIUpr5LliEX+9d6KLW/uIEThMYtcxVoxd0YWBUJRgenHw2gUHOZE2VYsP6D/lFw2znMOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708095409; c=relaxed/simple; bh=iHVQAzzzfTaTgzOXCLFz1g/OQfWxLf37ORqpX3X1H8Q=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=vGCn7OpF0rBHVy/V0albnBPISCJwHCaQfHYHh+rOT7ApO+GfdXbMD87ysZIToRbjD6ffCfNyPaGcZ0HGTKOrO1GObp8Qf5VimW7TkbJMsIXB5OPFhpdmqCIJaHN7lR23bDZL+V/glC5hw5168wD7EtCIr131yvuFtx1/qydkfNQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2d1094b5568so28482901fa.1 for ; Fri, 16 Feb 2024 06:56:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708095405; x=1708700205; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=OBHxDe62oF6tG5aygEwlgznKdr1QKGqOUik0bTT9V5k=; b=hsBOXhtIdXKbjiOI41grWD0uRBAxXBWV0WYtamtlsuNm0LWjmHIGJ3LtWd0uHiqFee O2YwgFuKPCRzuU3IGN4mT6Mk6pfvZQoysraiujoM1/KgLE3dwjdXYq5mvkF60d6H6Nk6 V6oj4ZF5m9ss2/QV1L+dWAQ8s126mQS56aH27cTGfj0y6fVLPA0bjEZH/lekBYr3EUke Z0U+uRouE6N2gmYrdmHz48GInxe1z1bah5LvdvjwgFpS5emLA+V+doJCHDPd5eCSD6BY q3T1Kso0oRc0dzOdQ8tyNyJ52C0EtJa+YRieo5xzLAiiO0mG1ZIkIcjWhpSBPfS2QZ2+ do/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708095405; x=1708700205; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OBHxDe62oF6tG5aygEwlgznKdr1QKGqOUik0bTT9V5k=; b=CaO7LLhZvNBsYzmxS73z8rI8z6SXXweM1PdjkHR/AGmB5Ppee3GfIrOVPRZnZbS663 REhp0pV9oNM2t9+NaQV9Ev+CvSAcPShmNZz8zJKe/w2mSO/nWGbeblDBwwf/kVmSILrT rYp3cTu2tLkbUei8vHioY0yfaiwBClCUVdh97L0Mi/azN2vJKOOWfU9Y6Nry57L8QMjD wqFse0aL9gjT9ObYwUD7s0EDr9OAfM2UIcrxHAQq45Iu8IbxzhLOgu5uEAqoBPhYG+1+ FghgHB9WvcCH0ud3VGqQiYef5Uni1D7uS5RZ61aMQ07RvfHRupEuVF2c05IcGOWrAgYx IR+Q== X-Gm-Message-State: AOJu0YxWYh+DECPrJbRUjE0EYwuqet5VVrDccKVvym3/LaoZBfIkNZTb Oy2xIBHaVwEo8jUa2V3YlEA7pZ0UDuHZlqXKZ+tSX9WPA57JWOur56LDOrSc X-Google-Smtp-Source: AGHT+IHqmBpl8RkBDsiUmj7PCtuXoujdbn4fsUNwRDeGeVJZADmW3sOWRqeu6Bxnafce9Yg1HjdIag== X-Received: by 2002:a2e:9dd4:0:b0:2d0:4c41:695 with SMTP id x20-20020a2e9dd4000000b002d04c410695mr3887147ljj.37.1708095405137; Fri, 16 Feb 2024 06:56:45 -0800 (PST) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id g17-20020a05600c4ed100b0040ecdd672fasm2669894wmq.13.2024.02.16.06.56.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 16 Feb 2024 06:56:44 -0800 (PST) From: Iain Sandoe X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Cc: ian@airs.com Subject: [PATCH] libiberty: Fix error return value in pex_unix_exec_child [PR113957]. Date: Fri, 16 Feb 2024 14:56:43 +0000 Message-Id: <20240216145643.50448-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: iain@sandoe.co.uk Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org tested on x86_64-darwin, so far. OK for trunk if regression test is successful on Linux too? thanks Iain --- 8< --- r14-5310-g879cf9ff45d940 introduced some new handling for spawning sub processes. The return value from the generic exec_child is examined and needs to be < 0 to signal an error. However, the unix flavour of this routine is returning the PID value set from the posix_spawn{p}. This latter value is undefined per the manual pages for both Darwin and Linux, and it seems Darwin, at least, sets the value to some usually positive number (presumably the PID that would have been used if the fork had succeeded). The fix proposed here is to set the pid = -1 in the relevant error paths. PR other/113957 libiberty/ChangeLog: * pex-unix.c (pex_unix_exec_child): Set pid = -1 in the error paths, since that is used to signal an erroneous outcome for the routine. Signed-off-by: Iain Sandoe --- libiberty/pex-unix.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libiberty/pex-unix.c b/libiberty/pex-unix.c index af98062a94c..f3a1cc95ada 100644 --- a/libiberty/pex-unix.c +++ b/libiberty/pex-unix.c @@ -695,6 +695,7 @@ pex_unix_exec_child (struct pex_obj *obj ATTRIBUTE_UNUSED, { *err = ret; *errmsg = "posix_spawnp"; + pid = -1; /* The value of pid is unspecified on failure. */ goto exit; } } @@ -705,6 +706,7 @@ pex_unix_exec_child (struct pex_obj *obj ATTRIBUTE_UNUSED, { *err = ret; *errmsg = "posix_spawn"; + pid = -1; goto exit; } }