Thread: Handle SIGTERM in fe_utils/cancel.c

Handle SIGTERM in fe_utils/cancel.c

From
"Tristan Partin"
Date:
Hello,

This is a way that would solve bug #17698[1]. It just reuses the same
handler as SIGINT (with a function rename).

This patch works best if it is combined with my previous submission[2].
I can rebase that submission if and when this patch is pulled in.

[1]: https://www.postgresql.org/message-id/17698-58a6ab8caec496b0%40postgresql.org
[2]: https://www.postgresql.org/message-id/CSSWBAX56CVY.291H6ZNNHK7EO%40c3po

--
Tristan Partin
Neon (https://neon.tech)

Attachment

Re: Handle SIGTERM in fe_utils/cancel.c

From
Michael Paquier
Date:
On Mon, May 22, 2023 at 12:26:34PM -0500, Tristan Partin wrote:
> This is a way that would solve bug #17698[1]. It just reuses the same
> handler as SIGINT (with a function rename).
>
> This patch works best if it is combined with my previous submission[2].
> I can rebase that submission if and when this patch is pulled in.

Not sure that this is a good idea long-term.  Currently, the code
paths calling setup_cancel_handler() from cancel.c don't have a custom
handling for SIGTERM, but that may not be the case forever.
--
Michael

Attachment

Re: Handle SIGTERM in fe_utils/cancel.c

From
"Tristan Partin"
Date:
On Tue May 23, 2023 at 7:51 PM CDT, Michael Paquier wrote:
> On Mon, May 22, 2023 at 12:26:34PM -0500, Tristan Partin wrote:
> > This is a way that would solve bug #17698[1]. It just reuses the same
> > handler as SIGINT (with a function rename).
> >
> > This patch works best if it is combined with my previous submission[2].
> > I can rebase that submission if and when this patch is pulled in.
>
> Not sure that this is a good idea long-term.  Currently, the code
> paths calling setup_cancel_handler() from cancel.c don't have a custom
> handling for SIGTERM, but that may not be the case forever.

I am more than happy to essentially just copy & paste some code that
will be specific to pgbench if that is preferrable for the purposes of
merging this patch. Another idea would be to change the signature of
setup_cancel_handler() to something like:

void
setup_cancel_handler(cb pre, cb post, int signal, ...); (null-terminate)

Then a client could state exactly what signals it wants to register with
this generic cancel handler.

--
Tristan Partin
Neon (https://neon.tech)