Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oKSUn-0002IP-Po for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Aug 2022 22:42:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oKSUl-0006A4-Uo for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Aug 2022 22:42:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oKSUl-00069v-L9 for pgsql-hackers@lists.postgresql.org; Sat, 06 Aug 2022 22:42:11 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oKSUj-0000ne-CA for pgsql-hackers@postgresql.org; Sat, 06 Aug 2022 22:42:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 276Mg3OL146577; Sat, 6 Aug 2022 18:42:03 -0400 From: Tom Lane To: Thomas Munro cc: Robert Haas , Andrew Dunstan , Andres Freund , pgsql-hackers Subject: Re: Cleaning up historical portability baggage In-reply-to: References: <20220712173352.trdeq66asbv6vf2q@awork3.anarazel.de> <1662559.1657648462@sss.pgh.pa.us> <1249825.1658622186@sss.pgh.pa.us> <3920417.1659710931@sss.pgh.pa.us> Comments: In-reply-to Thomas Munro message dated "Sun, 07 Aug 2022 10:23:17 +1200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <146575.1659825723.1@sss.pgh.pa.us> Date: Sat, 06 Aug 2022 18:42:03 -0400 Message-ID: <146576.1659825723@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thomas Munro writes: > Did I understand correctly that the places that do kill(-pid) followed > by kill(pid) really only need the kill(-pid)? Uh ... did you read the comment right above signal_child? * There is a race condition for recently-forked children: they might not * have executed setsid() yet. So we signal the child directly as well as * the group. We assume such a child will handle the signal before trying * to spawn any grandchild processes. We also assume that signaling the * child twice will not cause any problems. It might be that this is wrong and signaling -pid will work even if the child hasn't yet done setsid(), but I doubt it: the kill(2) man page is pretty clear that it'll fail if "the process group doesn't exist". Perhaps we could finesse that by signaling -pid first, and then signaling pid if that fails, but offhand it seems like that has the described race condition w.r.t. grandchild processes. regards, tom lane