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 1pW0Dk-0008Ao-Il for pgsql-hackers@arkaria.postgresql.org; Sat, 25 Feb 2023 19:28:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pW0Dj-00084c-2o for pgsql-hackers@arkaria.postgresql.org; Sat, 25 Feb 2023 19:28:35 +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 1pW0Di-00084S-Ne for pgsql-hackers@lists.postgresql.org; Sat, 25 Feb 2023 19:28:34 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pW0Df-0001rK-Fw for pgsql-hackers@lists.postgresql.org; Sat, 25 Feb 2023 19:28:34 +0000 Received: by mail-pl1-x62f.google.com with SMTP id l15so2889821pls.1 for ; Sat, 25 Feb 2023 11:28:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=m7SnDSjhYDamqJPDwuWC1g7pvhvJIfxJwkMWnzFzWEM=; b=PxEXYP2XoAIH2eiNE5xBY+3Vzh7nZfNhN6HI5CZNFLQXcwSavuVQN0KZtLo4YdW0UQ Nrg9E6AMEAwX6wWvMIcFAkCprqkCri7n5+DAx8zqiyTE1eOoPqCiXJj2AiLB7rnyNTOZ gjS07L1L9GEMIbtVHxzwOJdric3dGto9koL/NsAHDm5L6+Nwj1LPsSMqxoig/cyC0SAf secorCIxiUcmHhWUSccClrT9/7P7BSSHbZrvWr7tNBaR55z0uVhTTpJnVT+WYS48BOBx 13H5vv1FvqZ5MM0GaN7blWB/1tkW7nPXyEJULA/3nVbnfWvPQTHCZWTiaJedRjyvYhac hExw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=m7SnDSjhYDamqJPDwuWC1g7pvhvJIfxJwkMWnzFzWEM=; b=5QvtpGPjUqI8Hnu4ediAdtY/N6NRiEtQaniFX0oYgbGXkZhaK8H6bTINW+O46dK4K8 iARMtkgkrT+LQ0Z+/anuLZ9e5/S4CZTt7A7FZWCDWreUczME0ZASJCYQMyzysTel3pMJ IjwpPXWpN0iHv/V26MTYP7yxEBGAbe8sSUWUtluiYZmT9hCQzEqlwjWnlTBKFiDClhFI eErY51KcfzQVspSv7itoqEV75XHCpZfxh3Bu0mp2olFuGLGK0p2WizVg/gFdjn1F+yYx R3jTpRI24WLFGmKIjIXwx1nnhKihckR1bxA0ijTMvilFqEX0RIHrgEbBuEHn+pUxLfUT XONw== X-Gm-Message-State: AO0yUKWLYBU5P2pwzswd33DQ8/3djLHlJCzORKThggnEfPnJtUqzuljK EuWHIrlO9rf9asJCkcOMZSo= X-Google-Smtp-Source: AK7set9a2128uEocznM1iYOnUWcnE/iXqm1LUuRoTAfLSinSABy77o5Sph3GTEwNi8t1UbF4V8i51Q== X-Received: by 2002:a05:6a20:4298:b0:bf:8866:f46d with SMTP id o24-20020a056a20429800b000bf8866f46dmr24449909pzj.34.1677353309119; Sat, 25 Feb 2023 11:28:29 -0800 (PST) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id q21-20020a62e115000000b005a90f2cce30sm1524146pfh.49.2023.02.25.11.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 11:28:28 -0800 (PST) Date: Sat, 25 Feb 2023 11:28:25 -0800 From: Nathan Bossart To: Andres Freund Cc: Thomas Munro , Michael Paquier , Robert Haas , Tom Lane , Fujii Masao , Postgres hackers Subject: Re: stopgap fix for signal handling during restore_command Message-ID: <20230225192825.GA868928@nathanxps13> References: <20230223231503.GA743455@nathanxps13> <20230224043323.GA821522@nathanxps13> <20230225190742.lfopue3nkrvxxoie@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230225190742.lfopue3nkrvxxoie@awork3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Feb 25, 2023 at 11:07:42AM -0800, Andres Freund wrote: > On 2023-02-23 20:33:23 -0800, Nathan Bossart wrote:> >> if (in_restore_command) >> - proc_exit(1); >> + { >> + /* >> + * If we are in a child process (e.g., forked by system() in >> + * RestoreArchivedFile()), we don't want to call any exit callbacks. >> + * The parent will take care of that. >> + */ >> + if (MyProcPid == (int) getpid()) >> + proc_exit(1); >> + else >> + { >> + const char msg[] = "StartupProcShutdownHandler() called in child process\n"; >> + int rc pg_attribute_unused(); >> + >> + rc = write(STDERR_FILENO, msg, sizeof(msg)); >> + _exit(1); >> + } >> + } > > Why do we need that rc variable? Don't we normally get away with (void) > write(...)? My compiler complains about that. :/ ../postgresql/src/backend/postmaster/startup.c: In function ‘StartupProcShutdownHandler’: ../postgresql/src/backend/postmaster/startup.c:139:11: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result] 139 | (void) write(STDERR_FILENO, msg, sizeof(msg)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors >> diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c >> index 22b4278610..e3da0622d7 100644 >> --- a/src/backend/storage/lmgr/proc.c >> +++ b/src/backend/storage/lmgr/proc.c >> @@ -805,6 +805,7 @@ ProcKill(int code, Datum arg) >> dlist_head *procgloballist; >> >> Assert(MyProc != NULL); >> + Assert(MyProcPid == (int) getpid()); /* not safe if forked by system(), etc. */ >> >> /* Make sure we're out of the sync rep lists */ >> SyncRepCleanupAtProcExit(); >> @@ -925,6 +926,7 @@ AuxiliaryProcKill(int code, Datum arg) >> PGPROC *proc; >> >> Assert(proctype >= 0 && proctype < NUM_AUXILIARY_PROCS); >> + Assert(MyProcPid == (int) getpid()); /* not safe if forked by system(), etc. */ >> >> auxproc = &AuxiliaryProcs[proctype]; >> >> -- >> 2.25.1 > > I think the much more interesting assertion here would be to check that > MyProc->pid equals the current pid. I don't mind changing this, but why is this a more interesting assertion? -- Nathan Bossart Amazon Web Services: https://aws.amazon.com