From: | Dmitry Koterov <dmitry(dot)koterov(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: In MacOS, psql reacts on SIGINT in a strange fashion (Linux is fine) |
Date: | 2024-04-13 23:17:42 |
Message-ID: | CA+CZih7g+Vkc8=iSUsJQEg96oo8Oqi-pLiwdwPcZvZ7M_G3pzw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Sat, Apr 13, 2024 at 7:53 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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");
}
=========================
[image: CleanShot 2024-04-13 at 16(dot)07(dot)08(at)2x(dot)png]
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2024-04-13 23:27:41 | Re: In MacOS, psql reacts on SIGINT in a strange fashion (Linux is fine) |
Previous Message | Dima Rybakov (Tlt) | 2024-04-13 22:58:21 | Why should I use fileno(stderr) instead of STDERR_FILENO |