Re: persistant psql feature suggestion - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: persistant psql feature suggestion
Date
Msg-id 004f01c33e6a$6a9f0dd0$6401a8c0@DUNSLANE
Whole thread Raw
In response to persistant psql feature suggestion  (James Pye <jwp@rhid.com>)
Responses Re: persistant psql feature suggestion
List 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@eigenvision.com>
To: "Andrew Dunstan" <andrew@dunslane.net>
Cc: <pgsql-hackers@postgresql.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@postgresql.org so that your
>       message can get through to the mailing list cleanly



pgsql-hackers by date:

Previous
From: Andreas Pflug
Date:
Subject: Re: Problem when running initdb with latest cvs code
Next
From: "Francisco Figueiredo Jr."
Date:
Subject: Re: Problem when running initdb with latest cvs code