Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wAfoB-000DHn-32 for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Apr 2026 03:11:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wAfo9-003GKG-12 for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Apr 2026 03:11:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wAfo8-003GK7-2z for pgsql-hackers@lists.postgresql.org; Thu, 09 Apr 2026 03:11:53 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wAfo7-000000006yc-1zoR for pgsql-hackers@lists.postgresql.org; Thu, 09 Apr 2026 03:11:53 +0000 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-c766a95a72dso332872a12.1 for ; Wed, 08 Apr 2026 20:11:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775704309; x=1776309109; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=QB/2eRbUorFwhBBQ72SUkD06Gv0UlwPVQfG4TMsnvFA=; b=UAaQkDtQgKRttYjagAg1zL5oSfGFkrmnWKStvWSeQqDr60YRjL1IZHkzrGC/Hah+j5 fRdR213vDf15LwkS/N9wKt4ZM582JSIlug7zoPs2CydZDlGUnT+P92Tb8JG2sarpLzNy Ji8D1vPZgUEuzwqs5DKwfk3RECDZ3haUQURgyouT2uZvR8aid0lPBChBtF17ho5z+y+t 1tx90xMxqlXYH/gtEbFDHJI8/soj0EXTrpbNmWFWDuDiR3xbWBiapNvBEjUFsZcBxHVv yADETsXBsx24iJDnxA1k3XuEggu4UueS1hhNke5+bX7cjk3JGC3ywshOR36g2oDd800w 7nkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775704309; x=1776309109; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=QB/2eRbUorFwhBBQ72SUkD06Gv0UlwPVQfG4TMsnvFA=; b=pcrZBC+ueT+DtfrHjQvbO21Fcp7v5Olwulb171FAf40LT3RUs1d3wz1Df+Q/zhUhm7 ROoZF5l+x9KjpbfMM8fgObY+hvyHmRxMQFBZaErrnidDg3ECG8taOy+io4FJ2nUJaZ2j j3rhwbCf/PqJfp74/ZZo/grbSQ+nxjhW8niyqhAwTy0YM9qejVoJs2zFYAqLP04C3QjP QymMPX7fI1HVuhgO6ts6DIxrUWXxORYySJCil59JkFj0pUMcN+cik/+Dm2B+oVXOYlX1 p3jrf7V9rNZpc68Db48y+PPiFElDnvC9HDTkjfJaWjLQlQWsd14vCq+veNyD0qIYkpz7 wumQ== X-Forwarded-Encrypted: i=1; AJvYcCWPHBduWSYSr5rRrfZsoRE02BT//Cg2cxvTmV6bQai8A3O4+wMrg6g0WKBjmII1vRj5GnwzvKefvff07q6L@lists.postgresql.org X-Gm-Message-State: AOJu0YyhLwPK86cPdwtedTejs0tJ4dHuRIqro8ZYLmPEPo+aIzUgpKXE DdxM5WUM54IltilNRJ6VGvg8dLHqS5UXFWGkfZczUbgAEw782qaaIPAC X-Gm-Gg: AeBDiesDEdRu0n5jWyCkufrYPpOV3iEIZoE3cQoffmm/I6SrMLka1Cvixme3mjNWcTK vthez8s83Cyr142pFMM0BB2u/w5Zpvr34ruB6Nt/G9dN+a2xKfO/38q+Jq1hg4cfP1oJpjiXSUI c53q2EKwvsRG6UvfjLqGSjn/8MmFVZPDaLonFXJzI1+n4OBglwuD+KfICEE8aYuxyaL1FiU9G5M qvUvA2+f794aO47wyqc4jTfqWK3wiV1Vwd8eP6jKPphkJTfHeIQOPEdQ84hkuszl1njgyuW8e/R SqNXeTREJnd2jaR5NgH5xz0T3uvIrFBlBETbem0JZ9Bi40vwbEP0nZY9iFnuwoQqib8THpOzpa3 f1oE7mmr5aguSNZv/Q7dGNd7GSWz1cmvvfAE5t7N3MFUKFSq1dkXMxe5XJ+niGc4QT5IytYwDMq pGS6ts6v8YAN4LSO6xVPx3wUuprDcI2h0Z8ehODUaEBg== X-Received: by 2002:a05:6a00:10c7:b0:82c:eafa:8863 with SMTP id d2e1a72fcca58-82d0dbbcc99mr24411409b3a.49.1775704308986; Wed, 08 Apr 2026 20:11:48 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82d11cd2ce2sm22808708b3a.6.2026.04.08.20.11.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Apr 2026 20:11:48 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: Add errdetail() with PID and UID about source of termination signal From: Chao Li In-Reply-To: Date: Thu, 9 Apr 2026 11:11:08 +0800 Cc: Jim Jones , Andrew Dunstan , Jakub Wartak , PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: <4D19BF33-3C16-49A3-918E-148369ADBCB2@gmail.com> References: <1ba07c75-cc4e-410c-9af1-076feeeb9594@dunslane.net> <9179378a-42db-4315-9ff6-b849ad5eefaf@dunslane.net> <6cj4oxgdpavltoqdbydw2pgxfdbcejc26x3mitasrnswipxne5@7gkaeoibos4l> <71930E58-82A8-4DDC-BA8C-5E394331E463@gmail.com> <43ab327c-3ec7-4424-88de-22c7906e5529@uni-muenster.de> To: Andres Freund X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Apr 9, 2026, at 01:01, Andres Freund wrote: >=20 > Hi, >=20 > Attached is a very rough first draft for how I think this needs to = look like. >=20 > Basically, SIGNAL_INFO always will pass both the signal number and = extended > information along to the signal handler. The extended information is a > postgres specific struct. If the platform can't provide the extended > information, the values are instead set to some default value = indicating that > the information is not known. >=20 > With that die() (and also StatementCancelHandler, ...) can just set = whatever > globals it wants, without pqsignal.c needing to know about it. >=20 > It also allows us to extend the amount of information in the future. = E.g. I'd > like to log the reason for a segfault (could e.g. be an OOM kill or an = umapped > region) to stderr. >=20 > The annoying thing about it is needing to change nearly all the = existing > references to SIG_IGN/SIG_DFL, to avoid warnings due to mismatched = types. >=20 >=20 > On 2026-04-08 11:13:40 +0200, Jim Jones wrote: >> If I understood this thread correctly, the feature (v6) introduced a >> problematic dual signature for wrapper_handler in pgsignal.c: >=20 >> +#if !defined(FRONTEND) && defined(HAVE_SA_SIGINFO) >> +static void >> +wrapper_handler(int signo, siginfo_t * info, void *context) >> +#else >> static void >> wrapper_handler(SIGNAL_ARGS) >> +#endif >=20 > I think it's not a problem for wrapper_handler to change its = signature, that's > a local implementation detail. The problem is that the way the = arguments were > passed was just wrong. Because signal handlers can be nested and such > nastiness, doing any of that via global variables is a recipe for = disaster. > It's also just ugly. >=20 >=20 >> .. and it should be rather done in the source (c.h) where SIGNAL_ARGS = is >> defined: >>=20 >> #ifndef SIGNAL_ARGS >> #define SIGNAL_ARGS int postgres_signal_arg >> #endif >>=20 >> Something like: >>=20 >> #ifndef SIGNAL_ARGS >> #ifdef HAVE_SA_SIGINFO >> #define SIGNAL_ARGS int postgres_signal_arg, siginfo_t >> *postgres_signal_info, void *postgres_signal_context >> #else >> #define SIGNAL_ARGS int postgres_signal_arg >> #endif >> #endif >>=20 >> But wouldn't it mean that all handlers need to be updated as well, = since >> they'd get new parameters? >=20 > All the signal handlers actually use SIGNAL_ARGS themselves, so that = part is > not a problem. >=20 > However, if we did it like you sketch above, they'd all need ifdefs = etc to be > able to access any extended information, which seems like a terrible > idea. Especially if we want this information on multiple platforms, = where the > struct to be passed would differ. >=20 > Hence in my prototype it's hidden behind a platform indepenedent = struct of our > own. >=20 >=20 >> If this is the case, the change can be quite substantial. >=20 > It's a bit annoying to do all the s/\b(SIG_(IGN|DFL)/PG_$1/, but it's = not that > bad, I think? >=20 > I unfortunately don't see a good other way to deal with it. We could = have a > macro wrapper around pqsignal() that checks for SIG_IGN with a cast to = the > system type, but that seems exceedingly ugly. >=20 > Greetings, >=20 > Andres Freund > I think the core idea here is to add a new parameter so signal handlers = can receive =E2=80=9Cpg_signal_info". Compared to my earlier proposal, = which stored sender info in file-scope variables, I agree this solution = is more flexible. I think my earlier direction was mainly trying to = avoid changing the signal handler interface. So I have no objection to the overall direction. Since the patch is = marked as WIP, I didn't review all the details yet. But one thing I want = to point out is: ``` +typedef struct pg_signal_info +{ + pid_t pid; /* pid of sending = process or 0 if unknown */ + uid_t uid; /* uid of sending = process or 0 if unknown */ +} pg_signal_info; ``` For uid, 0 is usually a valid value for root. So using 0 as the = =E2=80=9Cunknown=E2=80=9D value seems a bit awkward. Maybe we should = instead document something like "uid is only meaningful when pid is not = 0". Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/