IO.popen("-") with no fork

e$B$J$+$@$G$9!#e(B

[ruby-dev:30679]e$B$K4XO"$7$F!“e(Bwin32e$B$J$I$Ne(Bforke$B$N$J$$4D6-$G$Oe(B
IO.popen(”-")e$B$Oe(Bforke$BF1MMe(BNotImplementedErrore$B$K$J$k$Y$-$8$c$J$$$Ge(B
e$B$7$g$&$+!#e(B

Index: io.c

— io.c (revision 12141)
+++ io.c (working copy)
@@ -3057,9 +3057,9 @@ pipe_open(int argc, VALUE *argv, const c
int status;
struct popen_arg arg;

  • volatile int doexec;
    #elif defined(_WIN32)
    int openmode = rb_io_mode_modenum(mode);
    char *exename = NULL;
    #endif
  • volatile int doexec;
    char *cmd;
    FILE *fp = 0;
    @@ -3072,7 +3072,8 @@ pipe_open(int argc, VALUE *argv, const c
    }

-#if defined(HAVE_FORK) && defined(HAVE_SOCKETPAIR)
cmd = StringValueCStr(prog);
doexec = (strcmp("-", cmd) != 0);
+
+#if defined(HAVE_FORK) && defined(HAVE_SOCKETPAIR)
if (!doexec) {
fflush(stdin); /* is it really needed? */
@@ -3134,4 +3135,5 @@ pipe_open(int argc, VALUE *argv, const c
}
#elif defined(_WIN32)

  • if (!doexec) rb_notimplement();
    if (argc) {
    char **args = ALLOCA_N(char *, argc+1);
    @@ -3146,7 +3148,4 @@ pipe_open(int argc, VALUE *argv, const c
    exename = RSTRING_PTR(prog);
    }
  • else {
  • cmd = StringValueCStr(prog);
  • }
    while ((pid = rb_w32_pipe_exec(cmd, exename, openmode, &fd)) == -1)
    {
    /* exec failed */
    @@ -3164,7 +3163,10 @@ pipe_open(int argc, VALUE *argv, const c
    }
    #else
  • if (argc)
  • if (!doexec) rb_notimplement();
  • if (argc) {
    prog = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" "));
  • fp = popen(StringValueCStr(prog), mode);
  • cmd = StringValueCStr(prog);
  • }
  • fp = popen(cmd, mode);
    if (!fp) rb_sys_fail(RSTRING_PTR(prog));
    fd = fileno(fp);

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30681] IO.popen(”-“) with no fork”
on Wed, 4 Apr 2007 00:41:49 +0900, Nobuyoshi N.
[email protected] writes:

|[ruby-dev:30679]e$B$K4XO"$7$F!“e(Bwin32e$B$J$I$Ne(Bforke$B$N$J$$4D6-$G$Oe(B
|IO.popen(”-")e$B$Oe(Bforke$BF1MMe(BNotImplementedErrore$B$K$J$k$Y$-$8$c$J$$$Ge(B
|e$B$7$g$&$+!#e(B

e$B$=$s$J5$$,$7$^$9!#$A$J$_$K8=>u$O2?$,5/$-$k$s$G$7$g$&!)e(B

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message “[ruby-dev:30683] Re: IO.popen(”-“) with no fork”
on Apr.04,2007 01:20:04, [email protected] wrote:
| |[ruby-dev:30679]e$B$K4XO"$7$F!“e(Bwin32e$B$J$I$Ne(Bforke$B$N$J$$4D6-$G$Oe(B
| |IO.popen(”-")e$B$Oe(Bforke$BF1MMe(BNotImplementedErrore$B$K$J$k$Y$-$8$c$J$$$Ge(B
| |e$B$7$g$&$+!#e(B
|
| e$B$=$s$J5$$,$7$^$9!#$A$J$_$K8=>u$O2?$,5/$-$k$s$G$7$g$&!)e(B

“-” e$B$H$$$&%3%^%s%I$r<B9T$7$h$&$H$7$^$9e(B :slight_smile:

e$B$=$l$G$O!#e(B

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message “[ruby-dev:30681] IO.popen(”-“) with no fork”
on Apr.04,2007 00:41:49, [email protected] wrote:
| [ruby-dev:30679]e$B$K4XO"$7$F!“e(Bwin32e$B$J$I$Ne(Bforke$B$N$J$$4D6-$G$Oe(B
| IO.popen(”-")e$B$Oe(Bforke$BF1MMe(BNotImplementedErrore$B$K$J$k$Y$-$8$c$J$$$Ge(B
| e$B$7$g$&$+!#e(B

e$B$3$N%Q%C%A$,F~$C$F5$IU$$$?$N$G$9$,!"e(Brb_notimplement() e$B$,=PNOe(B
e$B$9$k%a%C%;!<%8Cf$N4X?tL>$,0lCJ$:$l$F$$$k$h$&$G$9!#e(B

e$B$=$l$O$=$l$H$7$F!“$3$l$,D>$C$F$be(B
The popen() function is unimplemented on this machine
e$B$H$+=P$k$N$O$=$l$O$=$l$GJ6$i$o$7$$$H;W$&$s$G$9$,!”$I$&$7$?$be(B
e$B$N$G$7$g$&$+$M!#e(B

Index: error.c

— error.c (revision 12144)
+++ error.c (working copy)
@@ -1029,7 +1029,7 @@ rb_notimplement(void)
{
rb_raise(rb_eNotImpError,
“The %s() function is unimplemented on this machine”,

  •   rb_id2name(rb_frame_callee()));
    
  •   rb_id2name(rb_frame_this_func()));
    

}

void

e$B$=$l$G$O!#e(B

Hi,

In message “Re: [ruby-dev:30685] Re: IO.popen(”-“) with no fork”
on Wed, 4 Apr 2007 11:19:02 +0900, “U.Nakamura”
[email protected] writes:

|e$B$3$N%Q%C%A$,F~$C$F5$IU$$$?$N$G$9$,!"e(Brb_notimplement() e$B$,=PNOe(B
|e$B$9$k%a%C%;!<%8Cf$N4X?tL>$,0lCJ$:$l$F$$$k$h$&$G$9!#e(B

e$B%Q%C%AEv$F$F$/$@$5$$!#e(B

|e$B$=$l$O$=$l$H$7$F!“$3$l$,D>$C$F$be(B
| The popen() function is unimplemented on this machine
|e$B$H$+=P$k$N$O$=$l$O$=$l$GJ6$i$o$7$$$H;W$&$s$G$9$,!”$I$&$7$?$be(B
|e$B$N$G$7$g$&$+$M!#e(B

e$B$3$3$Oe(Brb_notimplement()e$B$r;H$o$J$$$GD>@\e(BNotImplementErrore$B$re(B
raisee$B$9$k$H$$$&$3$H$K$9$k$7$+$J$$$G$9$+$M$(!#e(B

e$B$J$+$@$G$9!#e(B

At Wed, 4 Apr 2007 11:56:05 +0900,
Yukihiro M. wrote in [ruby-dev:30686]:

|e$B$=$l$O$=$l$H$7$F!"$3$l$,D>$C$F$be(B
| The popen() function is unimplemented on this machine
|e$B$H$+=P$k$N$O$=$l$O$=$l$GJ6$i$o$7$$$H;W$&$s$G$9$,!"$I$&$7$?$be(B
|e$B$N$G$7$g$&$+$M!#e(B

e$B$3$3$Oe(Brb_notimplement()e$B$r;H$o$J$$$GD>@\e(BNotImplementErrore$B$re(B
raisee$B$9$k$H$$$&$3$H$K$9$k$7$+$J$$$G$9$+$M$(!#e(B

e$B$A$g$C$H>r7o$r@0M}$7$F$_$^$7$?!#e(B

Index: trunk/io.c

— trunk/io.c (revision 12144)
+++ trunk/io.c (working copy)
@@ -3057,5 +3057,5 @@ pipe_open(int argc, VALUE *argv, const c
rb_io_t *fptr;
VALUE port, prog;
-#if defined(HAVE_FORK) && defined(HAVE_SOCKETPAIR)
+#if defined(HAVE_FORK)
int status;
struct popen_arg arg;
@@ -3078,5 +3078,12 @@ pipe_open(int argc, VALUE *argv, const c
doexec = (strcmp("-", cmd) != 0);

-#if defined(HAVE_FORK) && defined(HAVE_SOCKETPAIR)
+#if !defined(HAVE_FORK)

  • if (!doexec) {
  • rb_raise(rb_eNotImpError,
  • "The fork() function is unimplemented on this machine");
    
  • }
    +#endif

+#if defined(HAVE_FORK)
if (!doexec) {
fflush(stdin); /* is it really needed? */
@@ -3086,17 +3093,20 @@ pipe_open(int argc, VALUE *argv, const c
arg.modef = modef;
arg.pair[0] = arg.pair[1] = -1;

  • if ((modef & FMODE_READABLE) && (modef & FMODE_WRITABLE)) {
  • switch (modef & (FMODE_READABLE|FMODE_WRITABLE)) {
    +#if defined(HAVE_SOCKETPAIR)
  •  case FMODE_READABLE|FMODE_WRITABLE:
       if (socketpair(AF_UNIX, SOCK_STREAM, 0, arg.pair) < 0)
           rb_sys_fail(cmd);
    
  • }
  • else if (modef & FMODE_READABLE) {
  • break;
    +#endif
  •  case FMODE_READABLE:
       if (pipe(arg.pair) < 0)
           rb_sys_fail(cmd);
    
  • }
  • else if (modef & FMODE_WRITABLE) {
  • break;
  •  case FMODE_WRITABLE:
       if (pipe(arg.pair) < 0)
           rb_sys_fail(cmd);
    
  • }
  • else {
  • break;
  •  default:
       rb_sys_fail(cmd);
    
    }
    @@ -3138,5 +3148,4 @@ pipe_open(int argc, VALUE *argv, const c
    }
    #elif defined(_WIN32)
  • if (!doexec) rb_notimplement();
    if (argc) {
    char **args = ALLOCA_N(char *, argc+1);
    @@ -3166,5 +3175,4 @@ pipe_open(int argc, VALUE *argv, const c
    }
    #else
  • if (!doexec) rb_notimplement();
    if (argc) {
    prog = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" "));
    Index: stable/io.c
    ===================================================================
    — stable/io.c (revision 12144)
    +++ stable/io.c (working copy)
    @@ -3027,10 +3027,27 @@ pipe_open(pstr, pname, mode)
    int modef = rb_io_mode_flags(mode);
    OpenFile *fptr;

#if defined(DJGPP) || defined(human68k) || defined(__VMS)
FILE *f;
+#else

  • int pid;
    +#ifdef _WIN32

  • FILE *fpr, *fpw;
    +#else

  • int pr[2], pw[2];
    +#endif
    +#endif

  • volatile int doexec;

    if (!pname) pname = StringValueCStr(pstr);

  • if (strcmp("-", pname) == 0) rb_notimplement();
  • doexec = (strcmp("-", pname) != 0);

+#if defined(DJGPP) || defined(human68k) || defined(__VMS) ||
defined(_WIN32)

  • if (!doexec) {
  • rb_raise(rb_eNotImpError,
  • "The fork() function is unimplemented on this machine");
    
  • }
    +#endif

+#if defined(DJGPP) || defined(human68k) || defined(__VMS)
f = popen(pname, mode);

@@ -3054,9 +3071,4 @@ pipe_open(pstr, pname, mode)
#else
#ifdef _WIN32

  • int pid;

  • FILE *fpr, *fpw;

  • if (!pname) pname = StringValueCStr(pstr);

  • if (strcmp("-", pname) == 0) rb_notimplement();
    retry:
    pid = pipe_exec(pname, rb_io_mode_modenum(mode), &fpr, &fpw);
    @@ -3088,14 +3100,8 @@ retry:
    }
    #else

  • int pid, pr[2], pw[2];

  • volatile int doexec;

  • if (!pname) pname = StringValueCStr(pstr);

  • if (((modef & FMODE_READABLE) && pipe(pr) == -1) ||
    ((modef & FMODE_WRITABLE) && pipe(pw) == -1))
    rb_sys_fail(pname);

  • doexec = (strcmp("-", pname) != 0);
    if (!doexec) {
    fflush(stdin); /* is it really needed? */

e$BKNIt$G$9!#e(B

Yukihiro M. wrote:

e$B!Ve(BThe fork() functione$B!W$r!Ve(Bfork(2)e$B!W$H$+$KCV$-49$($F$/$@$5$$!#e(B

Win32e$B$Ge(BUnixe$B$N%^%K%e%"%k%;%/%7%g%s$r<($5$l$F$b:$$k$@$1$@$H;W$&$N$G$9$,!#e(B
e$BCV$-49$($J$$J}$,$$$$$H;W$$$^$9!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30687] Re: IO.popen(”-“) with no fork”
on Wed, 4 Apr 2007 16:40:08 +0900, Nobuyoshi N.
[email protected] writes:

|> e$B$3$3$Oe(Brb_notimplement()e$B$r;H$o$J$$$GD>@\e(BNotImplementErrore$B$re(B
|> raisee$B$9$k$H$$$&$3$H$K$9$k$7$+$J$$$G$9$+$M$(!#e(B
|
|e$B$A$g$C$H>r7o$r@0M}$7$F$_$^$7$?!#e(B

e$B!Ve(BThe fork()
functione$B!W$r!Ve(Bfork(2)e$B!W$H$+$KCV$-49$($F$/$@$5$$!#e(B
e$B9%$$NLdBj$G$9$,!#8e$O$=$N$^$^%3%%C%H$7$F$/$@$5$$$^$;$s$+!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30689] Re: IO.popen(”-“) with no fork”
on Wed, 4 Apr 2007 17:13:33 +0900, Urabe S.
[email protected] writes:

|Yukihiro M. wrote:
|> e$B!Ve(BThe fork() functione$B!W$r!Ve(Bfork(2)e$B!W$H$+$KCV$-49$($F$/$@$5$$!#e(B

|Win32e$B$Ge(BUnixe$B$N%^%K%e%"%k%;%/%7%g%s$r<($5$l$F$b:$$k$@$1$@$H;W$&$N$G$9$,!#e(B
|e$BCV$-49$($J$$J}$,$$$$$H;W$$$^$9!#e(B

e$B$=$&$+!#$=$l$K$D$$$F$OG<F@!#$?$@!“%(%i!<%a%C%;!<%8$r!Ve(BThee$B!A!We(B
e$B$G$O$8$a$k47=,$OL5$$$N$G!”$=$3$@$1D>$7$F$/$@$5$$!#e(B

e$B$J$+$@$G$9!#e(B

At Wed, 4 Apr 2007 17:19:27 +0900,
Yukihiro M. wrote in [ruby-dev:30690]:

|Yukihiro M. wrote:
|> e$B!Ve(BThe fork() functione$B!W$r!Ve(Bfork(2)e$B!W$H$+$KCV$-49$($F$/$@$5$$!#e(B

|Win32e$B$Ge(BUnixe$B$N%^%K%e%"%k%;%/%7%g%s$r<($5$l$F$b:$$k$@$1$@$H;W$&$N$G$9$,!#e(B
|e$BCV$-49$($J$$J}$,$$$$$H;W$$$^$9!#e(B

e$B$=$&$+!#$=$l$K$D$$$F$OG<F@!#$?$@!"%(%i!<%a%C%;!<%8$r!Ve(BThee$B!A!We(B
e$B$G$O$8$a$k47=,$OL5$$$N$G!"$=$3$@$1D>$7$F$/$@$5$$!#e(B

e$B$3$l$Oe(Brb_notimplement()e$B$+$i%3%T!<$7$?$b$N$J$s$G$9$,!"85$bD>$7$^e(B
e$B$9$+!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30693] Re: IO.popen(”-“) with no fork”
on Wed, 4 Apr 2007 18:23:48 +0900, “U.Nakamura”
[email protected] writes:

|0.95e$B$^$G$Oe(Brb_notimplement()e$B<+BN$,$J$/$F!"e(B0.99.4-961224e$B$K$O$“e(B
|e$B$k$s$G$9$,!”$3$N;~E@$G4{$K!Ve(BThee$B!A!W$K$J$C$F$^$9!#e(B
|e$B$H$$$&$+e(B0.95e$B;~E@$G$ONc30%/%i%9$,$J$+$C$?$s$G$9$,!"e(BChangeLoge$B$+e(B
|e$B$iA[A|$9$k$K!"Nc30%/%i%9$,$G$-$?$H$-$K$3$N%a%C%;!<%8$b0l=o$Ke(B
|e$BF~$C$?$N$G$O$J$$$+$H;W$$$^$9!#e(B

e$B$I$&$b$"$j$,$H$&$4$6$$$^$9!#e(B1.8e$B$G$O!Ve(Bthee$B!W$K$J$C$F$^$9$M!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30691] Re: IO.popen(”-“) with no fork”
on Wed, 4 Apr 2007 17:24:11 +0900, Nobuyoshi N.
[email protected] writes:

|> e$B$=$&$+!#$=$l$K$D$$$F$OG<F@!#$?$@!“%(%i!<%a%C%;!<%8$r!Ve(BThee$B!A!We(B
|> e$B$G$O$8$a$k47=,$OL5$$$N$G!”$=$3$@$1D>$7$F$/$@$5$$!#e(B
|
|e$B$3$l$Oe(Brb_notimplement()e$B$+$i%3%T!<$7$?$b$N$J$s$G$9$,!"85$bD>$7$^e(B
|e$B$9$+!#e(B

e$B$$!"$$$D$N4V$Ke(B(e$B;d$,$d$C$?$s$@$C$1e(B)e$B!#e(BThee$B$r<h$kJ}8~$G$I$&$G$7$g$&!#e(B

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message “[ruby-dev:30692] Re: IO.popen(”-“) with no fork”
on Apr.04,2007 18:11:57, [email protected] wrote:
| |> e$B$=$&$+!#$=$l$K$D$$$F$OG<F@!#$?$@!“%(%i!<%a%C%;!<%8$r!Ve(BThee$B!A!We(B
| |> e$B$G$O$8$a$k47=,$OL5$$$N$G!”$=$3$@$1D>$7$F$/$@$5$$!#e(B
| |
| |e$B$3$l$Oe(Brb_notimplement()e$B$+$i%3%T!<$7$?$b$N$J$s$G$9$,!“85$bD>$7$^e(B
| |e$B$9$+!#e(B
|
| e$B$$!”$$$D$N4V$Ke(B(e$B;d$,$d$C$?$s$@$C$1e(B)e$B!#e(BThee$B$r<h$kJ}8~$G$I$&$G$7$g$&!#e(B

0.95e$B$^$G$Oe(Brb_notimplement()e$B<+BN$,$J$/$F!"e(B0.99.4-961224e$B$K$O$“e(B
e$B$k$s$G$9$,!”$3$N;~E@$G4{$K!Ve(BThee$B!A!W$K$J$C$F$^$9!#e(B
e$B$H$$$&$+e(B0.95e$B;~E@$G$ONc30%/%i%9$,$J$+$C$?$s$G$9$,!"e(BChangeLoge$B$+e(B
e$B$iA[A|$9$k$K!"Nc30%/%i%9$,$G$-$?$H$-$K$3$N%a%C%;!<%8$b0l=o$Ke(B
e$BF~$C$?$N$G$O$J$$$+$H;W$$$^$9!#e(B

e$B$H$+!"$I$&$G$b$$$$$3$H$r$D$$D4$Y$F$7$^$$$^$7$?!#e(B

e$B$=$l$G$O!#e(B