Re: persistant psql feature suggestion

From: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
To: "PeterKorman" <calvin-pgsql-ml(at)eigenvision(dot)com>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: persistant psql feature suggestion
Date: 2003-06-29 18:15:26
Message-ID: 004f01c33e6a$6a9f0dd0$6401a8c0@DUNSLANE
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

We don't need to read and write on the same fd.

The real right way is to detect when the psql client exits - possible when
the perl program spawns it, like shown below.

As always, TIMTOWTDI

andrew

--------------------------

use strict;
use IO::Handle;
use POSIX ":sys_wait_h";

my $curpos;
my $fifofile = shift || usage();
my $database = shift || usage();

open(FILE,$fifofile) || die $!;
my $psqlpid = open(OUTPIPE,"|-");
unless (defined($psqlpid)) { die $!; }
if ($psqlpid == 0)
{
exec("psql -a $database") || die $!;
}

# must be parent here
sub REAPER
{
my $waitedpid;
while (($waitedpid = waitpid(-1,WNOHANG)) > 0)
{
if ($waitedpid == $psqlpid) { exit 0; }
}
$SIG{CHLD} = \&REAPER; # loathe sysV
}

$SIG{CHLD} = \&REAPER;

OUTPIPE->autoflush();

for (;;)
{
for ($curpos = tell(FILE); $_ = <FILE>; $curpos = tell(FILE))
{
print OUTPIPE $_;
}
sleep(1);
seek(FILE, $curpos, 0);
}

sub usage
{
print STDERR "usage: ",$0," fifofile database\n";
exit 1;
}

----- Original Message -----
From: "PeterKorman" <calvin-pgsql-ml(at)eigenvision(dot)com>
To: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Sent: Sunday, June 29, 2003 11:40 AM
Subject: Re: [HACKERS] persistant psql feature suggestion

> On Sun, Jun 29, 2003 at 10:22:49AM -0400, Andrew Dunstan wrote:
> > OK, worked out the wrinkle. psql is behaving perfectly well, but the
shim
> > doesn't get a SIGPIPE until it tries to write to it after psql has
exited.
> >
> > A slightly hackish fix for this would be to put this line after the
"print
> > $_" line:
> >
> > if ($_ eq "\\q\n") { sleep 1; print " "; } # get SIGPIPE if client
gone
> >
> > cheers
> >
> > andrew
>
> NAME
> IPC::Open2, open2 - open a process for both reading and writing
>
> http://www.perl.com/doc/manual/html/lib/IPC/Open2.html
>
> Would this help?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Francisco Figueiredo Jr. 2003-06-29 18:50:21 Re: Problem when running initdb with latest cvs code
Previous Message Andreas Pflug 2003-06-29 17:23:44 Re: Problem when running initdb with latest cvs code