Front page | perl.perl5.porters |
Postings from April 2010
Re: system() and protecting descriptors #0, #1 and #3
Thread Previous
|
Thread Next
From:
Ruslan Zakirov
Date:
April 15, 2010 17:34
Subject:
Re: system() and protecting descriptors #0, #1 and #3
Message ID:
g2p589c94401004151734o54ffbc1er7e40049add337f57@mail.gmail.com
Hello,
I asked questions quoted below a few weeks ago, but nobody commented.
Is the problem poorly described, author is a moron or picked at a sore
place?
On Thu, Apr 1, 2010 at 11:50 PM, Ruslan Zakirov <ruz@bestpractical.com> wrote:
> Hello,
>
> Here is simple script:
> -----------------------
> close STDOUT;
> open my $fh, ">/tmp/test2";
> print STDERR "FILE FD: ", fileno($fh), "\n";
> open *STDOUT, ">/tmp/test";
> print STDERR "new STDOUT FD: ". fileno(STDOUT) ."\n";
> system("/bin/echo", "boo");
> ------------------------
>
> STDERR output:
> ------------------------
> FILE FD: 1
> new STDOUT FD: 3
> ------------------------
>
> As you can guess output of the system call is in /tmp/test2.
>
> I have several questions:
> 1) Can you help me write a wrapper function for code blocks with
> system() and open "|-" to protect FD #1?
> 2) Can system() do something about that? Shouldn't it do some magic
> after fork and before exec. For example: fork, check perl's STDOUT, if
> it's fd #1 then do nothing, if it's not then dup2(stdout's_fd, 1) or
> close fd #1 if STDOUT in perl is closed and only then fork. Not sure
> if it's possible, but I think it's sane and desireable behaviour.
> 3) Can perl protect FDs 1, 2 and 3?
>
> If somebody is interested in real situation then I can describe on
> request. In a few words: mod_perl/apache that close FD #1, DBI that
> gets it for connection and third party extension that calls
> system("/program/that/prints/to/STDOUT").
>
> --
> Best regards, Ruslan.
--
Best regards, Ruslan.
Thread Previous
|
Thread Next