Re: persistant psql feature suggestion

Поиск
Список
Период
Сортировка
От Andrew Dunstan
Тема Re: persistant psql feature suggestion
Дата
Msg-id 004f01c33e6a$6a9f0dd0$6401a8c0@DUNSLANE
обсуждение исходный текст
Ответ на persistant psql feature suggestion  (James Pye <jwp@rhid.com>)
Ответы Re: persistant psql feature suggestion  (PeterKorman <calvin-pgsql-ml@eigenvision.com>)
Список 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 по дате отправления:

Предыдущее
От: Andreas Pflug
Дата:
Сообщение: Re: Problem when running initdb with latest cvs code
Следующее
От: "Francisco Figueiredo Jr."
Дата:
Сообщение: Re: Problem when running initdb with latest cvs code