From: C.DeRykus on
On Jul 30, 5:21 pm, John Kelly <j...(a)isp2dial.com> wrote:
> On Fri, 30 Jul 2010 16:20:45 -0700 (PDT), "C.DeRykus"
>
> <dery...(a)gmail.com> wrote:
> >On Jul 30, 7:39 am, John Kelly <j...(a)isp2dial.com> wrote:
> >> ...

> >On FreeBSD (with small edits above), I don't see that
> >happening.
>
> >$ myscript.pl  sleep 60
> >parent shell=71889 perl process=75147  perl kid=75148
>
JK> That's what I'm saying; the kid pid is only 1 greater than
JK> the perl pid, which means there was never a shell pid
JK> launched.
>
> >$ ps -ax
> >  PID  TT  STAT      TIME COMMAND
> >71889   2  SNs    0:00.01 -bash (bash)
> >75147   2  SN+    0:00.02 /usr/bin/perl ./shell.pl sleep 60
> >75148   2  SN+    0:00.00 sleep 60
> >....
>
> >I believe execl in the perl kid launches a shell
> >which then gets overlaid by sleep().
>
JK> I don't think so.
JK>
JK> You could overlay the shell by prefixing the command
JK> with the "exec" shell builtin, but I didn't do that.
JK>
JK> Seems like perl is recognizing 2>&1 as a limited special
JK> case, copying
JK> fd1 to fd2 , then exec'ing the binary directly, without
JK> sing a shell.

Maybe I missed something but I anything supporting your
supposition in the source or docs:

perlfaq8:
If the second argument to a piped open() contains shell
metacharacters, perl fork()s, then exec()s a shell to
decode the metacharacters and eventually run the desired
program...

perlopentut:
But if the command contains special shell characters, such
as ">" or "*", called 'metacharacters', Perl does not execute
the command directly. Instead, Perl runs the shell, which then
tries to run the command.

--
Charles DeRykus
From: John Kelly on
On Fri, 30 Jul 2010 21:40:51 -0700 (PDT), "C.DeRykus"
<derykus(a)gmail.com> wrote:

>JK> Seems like perl is recognizing 2>&1 as a limited special
>JK> case, copying
>JK> fd1 to fd2 , then exec'ing the binary directly, without
>JK> sing a shell.

>Maybe I missed something but I anything supporting your
>supposition in the source or docs:
>
>perlfaq8:
> If the second argument to a piped open() contains shell
> metacharacters, perl fork()s, then exec()s a shell to
> decode the metacharacters and eventually run the desired
> program...
>
>perlopentut:
> But if the command contains special shell characters, such
> as ">" or "*", called 'metacharacters', Perl does not execute
> the command directly. Instead, Perl runs the shell, which then
> tries to run the command.

Seems the docs are incomplete.


--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php

From: Xho Jingleheimerschmidt on
C.DeRykus wrote:
> On Jul 30, 5:21 pm, John Kelly <j...(a)isp2dial.com> wrote:
>> On Fri, 30 Jul 2010 16:20:45 -0700 (PDT), "C.DeRykus"
>>
>> <dery...(a)gmail.com> wrote:
>>> On Jul 30, 7:39 am, John Kelly <j...(a)isp2dial.com> wrote:
>>>> ...
>
>>> On FreeBSD (with small edits above), I don't see that
>>> happening.
>>> $ myscript.pl sleep 60
>>> parent shell=71889 perl process=75147 perl kid=75148
> JK> That's what I'm saying; the kid pid is only 1 greater than
> JK> the perl pid, which means there was never a shell pid
> JK> launched.
>>> $ ps -ax
>>> PID TT STAT TIME COMMAND
>>> 71889 2 SNs 0:00.01 -bash (bash)
>>> 75147 2 SN+ 0:00.02 /usr/bin/perl ./shell.pl sleep 60
>>> 75148 2 SN+ 0:00.00 sleep 60
>>> ....
>>> I believe execl in the perl kid launches a shell
>>> which then gets overlaid by sleep().
> JK> I don't think so.
> JK>
> JK> You could overlay the shell by prefixing the command
> JK> with the "exec" shell builtin, but I didn't do that.
> JK>
> JK> Seems like perl is recognizing 2>&1 as a limited special
> JK> case, copying
> JK> fd1 to fd2 , then exec'ing the binary directly, without
> JK> sing a shell.
>
> Maybe I missed something but I anything supporting your
> supposition in the source or docs:

I don't see it in the docs either. But I'm quite sure it is in the
source, as the behavior indubitably exists, as verified with strace, and
I doubt perl has a mind of its own.


From: C.DeRykus on
On Jul 31, 2:23 pm, Xho Jingleheimerschmidt <xhos...(a)gmail.com> wrote:
> C.DeRykus wrote:
> > On Jul 30, 5:21 pm, John Kelly <j...(a)isp2dial.com> wrote:
> >> On Fri, 30 Jul 2010 16:20:45 -0700 (PDT), "C.DeRykus"
>
> >> <dery...(a)gmail.com> wrote:
> >>> On Jul 30, 7:39 am, John Kelly <j...(a)isp2dial.com> wrote:
> >>>> ...
>
> >>> On FreeBSD (with small edits above), I don't see that
> >>> happening.
> >>> $ myscript.pl  sleep 60
> >>> parent shell=71889 perl process=75147  perl kid=75148
> > JK> That's what I'm saying; the kid pid is only 1 greater than
> > JK> the perl pid, which means there was never a shell pid
> > JK> launched.
> >>> $ ps -ax
> >>>  PID  TT  STAT      TIME COMMAND
> >>> 71889   2  SNs    0:00.01 -bash (bash)
> >>> 75147   2  SN+    0:00.02 /usr/bin/perl ./shell.pl sleep 60
> >>> 75148   2  SN+    0:00.00 sleep 60
> >>> ....
> >>> I believe execl in the perl kid launches a shell
> >>> which then gets overlaid by sleep().
> > JK> I don't think so.
> > JK>
> > JK> You could overlay the shell by prefixing the command
> > JK> with the "exec" shell builtin, but I didn't do that.
> > JK>
> > JK> Seems like perl is recognizing 2>&1 as a limited special
> > JK> case, copying
> > JK> fd1 to fd2 , then exec'ing the binary directly, without
> > JK> sing a shell.
>
> > Maybe I missed something but I anything supporting your
> > supposition in the source or docs:
>
> I don't see it in the docs either.  But I'm quite sure it is in the
> source, as the behavior indubitably exists, as verified with strace, and
> I doubt perl has a mind of its own.

Yes, IIUC, it looks like there is a dup and the shell's
bypassed:

From doio.c:

/* handle the 2>&1 construct at the end */
if (*s == '>' && s[1] == '&' && s[2] == '1'
...
if (!*t && (PerlLIO_dup2(1,2) != -1)) {
s[-2] = '\0';
break;
}
}

--
Charles DeRykus
From: John Kelly on
On Sun, 1 Aug 2010 01:27:52 -0700 (PDT), "C.DeRykus" <derykus(a)gmail.com>
wrote:

>Yes, IIUC, it looks like there is a dup and the shell's
>bypassed:
>
> From doio.c:
>
> /* handle the 2>&1 construct at the end */
> if (*s == '>' && s[1] == '&' && s[2] == '1'
> ...
> if (!*t && (PerlLIO_dup2(1,2) != -1)) {
> s[-2] = '\0';
> break;
> }
> }

Interesting it says "at the end"

I wonder if placing it elsewhere in the command will circumvent Perl's
shortcut and invoke a shell as usual.


--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php