Re: In MacOS, psql reacts on SIGINT in a strange fashion (Linux is fine) - Mailing list pgsql-hackers

From Dmitry Koterov
Subject Re: In MacOS, psql reacts on SIGINT in a strange fashion (Linux is fine)
Date
Msg-id CA+CZih7g+Vkc8=iSUsJQEg96oo8Oqi-pLiwdwPcZvZ7M_G3pzw@mail.gmail.com
Whole thread Raw
In response to Re: In MacOS, psql reacts on SIGINT in a strange fashion (Linux is fine)  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: In MacOS, psql reacts on SIGINT in a strange fashion (Linux is fine)
Re: In MacOS, psql reacts on SIGINT in a strange fashion (Linux is fine)
List pgsql-hackers
On Sat, Apr 13, 2024 at 7:53 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Let me guess ... you're using zsh not bash?

I wish it was zsh... I tested it with zsh, but with bash (and with low-level kill syscall), I observed the same effect unfortunately. 

So it's still a puzzle.

1. Even more, when I send a kill() low-level syscall using e.g. Perl - perl -e 'kill("INT", 16107)' - it is the same.
2. If any other program but psql is used (e.g. vim or my custom Perl script which ignores SIGINT), the effect is not reproducible.

Can it be e.g. readline? Or something related to tty or session settings which psql could modify (I did not find any in the source code though).

=========================

chsh -s /bin/bash
# then kill all terminals

$ PGHOST=127.0.0.1 PGPORT=15432 PGUSER=postgres PGPASSWORD=postgres PGDATABASE=postgres /tmp/my1.pl
...
postgres=#

$ ps | grep zsh | grep -v grep
<empty>

$ watch -n0.5 'pstree | grep -E "yarn|psql|vim|sleep|lldb|my.pl|perl|debugserver|-bash| login" | grep -v grep'
 |   |-+= 13721 root login -fp dmitry
 |   | \-+= 13722 dmitry -bash
 |   |-+= 13700 root login -fp dmitry
 |   | \-+= 13701 dmitry -bash
 |   |   \-+= 16105 dmitry /usr/bin/perl -w /tmp/my1.pl
 |   |     \-+- 16106 dmitry /usr/bin/perl -w /tmp/my2.pl
 |   |       \--- 16107 dmitry psql
 |   \-+= 13796 root login -fp dmitry
 |     \--= 13797 dmitry -bash

$ perl -e 'kill("INT", 16107)'

I observe as previously:

int in my2
int in my1
postgres=# 

=========================


When I use a custom SIGINT-trapping script instead of psql, it all works as expected in MacOS, only that script receives the SIGINT and not its parents:

=========================

$ cat /tmp/ignore.pl
#!/usr/bin/perl -w
$SIG{INT} = sub { print("int ignored\n") };
while (1) { sleep(1); }

$ cat /tmp/my2.pl
#!/usr/bin/perl -w
if (fork()) {
  $SIG{INT} = sub { print("int in my2\n") };
  while (1) { wait() and exit(1); }
} else {
  exec("/tmp/ignore.pl");
}


=========================


CleanShot 2024-04-13 at 16.07.08@2x.png
Attachment

pgsql-hackers by date:

Previous
From: "Dima Rybakov (Tlt)"
Date:
Subject: Why should I use fileno(stderr) instead of STDERR_FILENO
Next
From: "David G. Johnston"
Date:
Subject: Re: In MacOS, psql reacts on SIGINT in a strange fashion (Linux is fine)