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.94.2) (envelope-from ) id 1tXMvf-005tpv-J2 for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Jan 2025 16:04:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tXMve-00BB8d-1M for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Jan 2025 16:04:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tXMvd-00BB8U-FQ for pgsql-hackers@lists.postgresql.org; Mon, 13 Jan 2025 16:04:38 +0000 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tXMvc-000CS9-0K for pgsql-hackers@lists.postgresql.org; Mon, 13 Jan 2025 16:04:36 +0000 Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-3ab29214f45so14334985ab.0 for ; Mon, 13 Jan 2025 08:04:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736784275; x=1737389075; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=X/0rNAK/FeBtbYbB8p+5xxoHYnc/2VeRngjfPmAEyy8=; b=fZUTqPPIe1N3cV0QBRQG8T/j7ExX7qsyBhEEsILWzlo7le5RCMOona1IDGnKArRpZJ 0yxZJ8tHzxr3DS2tYJ5CpUdL8uDSMiAfoTzCNbDlwB7b+2SXaxiuAb+ESLUEYt+0j5Gh +swCwFsivjJ1sz/LNZaDNcerLYDEL9WQJtrTat9JuMlE9ADkFT6+JtE7xVD9Zh6x5ULT e33VtOeB/t+21/fghDkOxeLkZ/RJvqE1oYc6TtAfIjp1AttrsL8Kx2o/Flh4IO5yD0DJ aBxMdLedqkDni2IfankTXu8/NSGPdtm2xJdkLF2TmbLrKQFyYqTSiZ7F0EG8eKv6EYA2 WZyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736784275; x=1737389075; h=in-reply-to: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=X/0rNAK/FeBtbYbB8p+5xxoHYnc/2VeRngjfPmAEyy8=; b=jvE4I1IbCXOparkXpz0ITFMjJ+3L+yFS/p/sTaJIo+7/wB81MFJO6Oo9Wo0jgxG/kp 0aZ+iXxBS7SL3PQDMSfpEoFZ/o2Ot0alUT7/keMyL69Ards8m6gDQGRqMC4/krwkyw8W Vle0ASxUMuS/T+jdoIcCtDVdsa7oRPBV445Applc5rd4bWiuG5HvznPmaZ9LUHqaamqF /9StBZS+oO5L71sYOU9fr3ZrI9Tno3Nehp7pAKW6YFmCJIk4o5swMgV+eAQnZP04mMLI m5VNn5ru/0GkngF9F3oveLyCCWhTD7gYzNO844dzoashkMJ9dq2ZVCJzAyTOj1vlEIlB sWcg== X-Forwarded-Encrypted: i=1; AJvYcCUVn1Uvq6941N9X5prRudt6WZczWt4sl5BSfGxUoCMN7Oc1yeygSELnpcUOtRK73t5FJ/yFvEldQMIfAo85@lists.postgresql.org X-Gm-Message-State: AOJu0YwrzJl/oxjOp/PW2wPhpu8KEfuGh0op1cY7QnM/gEwrnxDRF1jp wc0j+ivMuBMM2q1T3ahmjvhvd1AgsCxB1K99b2OdQ7DIPWjeY0Gd X-Gm-Gg: ASbGncvQcCJJq3huBq9bVvCAi8u/PCT51SNw/dk/a3BzZkfyoMjYDl25wKEdQjUgxaO wj+/6zTgWBzey+Zd59lVoJ3R+Iz2oTLebsB5W2j2t38aQkGCa30WSzXQo0Jco7G8dr+XGohmTfh 1/lPdhqZRj/Re5YKXtn0SvOtYVkCsveJyxHa44NHsXUrARHRI9m/cnoPjlrtPsNeRPspo5T2QXw DjgYxXWAggAdqfKUOnJtT2BA4BZTgJ2tshI8Nb6YPo3boWBEEtEEbBQBD4L6PhQbz2cv/zsQ9rj l5APP79PnzubB6gVAkTOt7oL8/NHoO+9CjQb9lIxzO7u3RM= X-Google-Smtp-Source: AGHT+IG4LlB9yclabT6S+DI/WHM2zd0HO3N9c2VIR6mqdVxpV7IGtFMvkKdt3RUnx2E0Vqk2n1tTZw== X-Received: by 2002:a05:6e02:1c2a:b0:3a7:86ab:bebe with SMTP id e9e14a558f8ab-3ce3aa5adc0mr144415735ab.16.1736784274616; Mon, 13 Jan 2025 08:04:34 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3ce4adb3aaasm27639885ab.24.2025.01.13.08.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 08:04:33 -0800 (PST) Date: Mon, 13 Jan 2025 10:04:31 -0600 From: Nathan Bossart To: Tom Lane Cc: Fujii Masao , Andy Fan , pgsql-hackers@lists.postgresql.org Subject: Re: pgbench error: (setshell) of script 0; execution of meta-command failed Message-ID: References: <87msfz5qv2.fsf@163.com> <87ikqn5em7.fsf@163.com> <2422778.1736521065@sss.pgh.pa.us> <2425050.1736522451@sss.pgh.pa.us> <127979.1736622253@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="1NgM7R4OkTY29DBX" Content-Disposition: inline In-Reply-To: <127979.1736622253@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --1NgM7R4OkTY29DBX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Jan 11, 2025 at 02:04:13PM -0500, Tom Lane wrote: > After studying this more, I think what we should do in HEAD is > even more aggressive: let's make the real name of port/pqsignal.c's > function be either pqsignal_fe in frontend, or pqsignal_be in backend. > This positively ensures that there's no collision with libpq's > export, and it seems like a good idea for the additional reason that > the frontend and backend versions are not really interchangeable. That would be nice. > However, we can't get away with that in released branches because > it'd be an ABI break for any outside code that calls pqsignal. > What I propose doing in the released branches is what's shown in > the attached patch for v17: rename port/pqsignal.c's function to > pqsignal_fe in frontend, but leave it as pqsignal in the backend. > Leaving it as pqsignal in the backend preserves ABI for extension > modules, at the cost that it's not entirely clear which pqsignal > an extension that's also linked with libpq will get. But that > hazard affects none of our code, and it existed already for any > third-party extensions that call pqsignal. In principle using > "pqsignal_fe" in frontend creates an ABI hazard for outside users of > libpgport.a. But I think it's not really a problem, because we don't > support that as a shared library. As long as people build with > headers and .a files from the same minor release, they'll be OK. I don't have any concrete reasons to think you are wrong about this, but it does feel somewhat risky to me. It might be worth testing it with a couple of third-party projects that use the frontend version of pqsignal(). codesearch.debian.net shows a couple that may be doing so [0] [1] [2]. > BTW, this decouples legacy-pqsignal.c from pqsignal.c enough > that we could now do what's contemplated in the comments from > 3b00fdba9: simplify that version by making it return void, > or perhaps better just a true/false success report. > I've not touched that point here, though. I think it should just return void since AFAICT nobody checks the return value. But it would probably be a good idea to add some sort of error checking within the function. I've attached a draft patch that adds some new assertions. I originally tried to use elog() where it was available, but besides making the code even more unreadable, I think it's unnecessary (since AFAICT any problems are likely coding errors). [0] https://github.com/gleu/pgstats [1] https://github.com/hapostgres/pg_auto_failover [2] https://github.com/credativ/pg_checksums -- nathan --1NgM7R4OkTY29DBX Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v1-0001-modify-pqsignal.patch" From 93ea04b912a90e6a166941c575b4da128e3b7533 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 13 Jan 2025 09:27:28 -0600 Subject: [PATCH v1 1/1] modify pqsignal --- src/include/port.h | 2 +- src/port/pqsignal.c | 32 ++++++-------------------------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/include/port.h b/src/include/port.h index f0e28ce5c53..4e9e5657872 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -520,7 +520,7 @@ extern int pg_mkdir_p(char *path, int omode); #define pqsignal pqsignal_be #endif typedef void (*pqsigfunc) (SIGNAL_ARGS); -extern pqsigfunc pqsignal(int signo, pqsigfunc func); +extern void pqsignal(int signo, pqsigfunc func); /* port/quotes.c */ extern char *escape_single_quotes_ascii(const char *src); diff --git a/src/port/pqsignal.c b/src/port/pqsignal.c index f707b1c54e1..076e3dfe340 100644 --- a/src/port/pqsignal.c +++ b/src/port/pqsignal.c @@ -114,29 +114,15 @@ wrapper_handler(SIGNAL_ARGS) * * Returns the previous handler. * - * NB: If called within a signal handler, race conditions may lead to bogus - * return values. You should either avoid calling this within signal handlers - * or ignore the return value. - * - * XXX: Since no in-tree callers use the return value, and there is little - * reason to do so, it would be nice if we could convert this to a void - * function instead of providing potentially-bogus return values. - * Unfortunately, that requires modifying the pqsignal() in legacy-pqsignal.c, - * which in turn requires an SONAME bump, which is probably not worth it. - * * Note: the actual name of this function is either pqsignal_fe when * compiled with -DFRONTEND, or pqsignal_be when compiled without. * This is to avoid a name collision with libpq's legacy-pqsignal.c. */ -pqsigfunc +void pqsignal(int signo, pqsigfunc func) { - pqsigfunc orig_func = pqsignal_handlers[signo]; /* assumed atomic */ #if !(defined(WIN32) && defined(FRONTEND)) - struct sigaction act, - oact; -#else - pqsigfunc ret; + struct sigaction act; #endif Assert(signo < PG_NSIG); @@ -155,17 +141,11 @@ pqsignal(int signo, pqsigfunc func) if (signo == SIGCHLD) act.sa_flags |= SA_NOCLDSTOP; #endif - if (sigaction(signo, &act, &oact) < 0) - return SIG_ERR; - else if (oact.sa_handler == wrapper_handler) - return orig_func; - else - return oact.sa_handler; + if (sigaction(signo, &act, NULL) < 0) + Assert(false); /* probably indicates coding error */ #else /* Forward to Windows native signal system. */ - if ((ret = signal(signo, func)) == wrapper_handler) - return orig_func; - else - return ret; + if (signal(signo, func) == SIG_ERR) + Assert(false); /* probably indicates coding error */ #endif } -- 2.39.5 (Apple Git-154) --1NgM7R4OkTY29DBX--