From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-05-13T23:33:10+09:00 Subject: Re: RCR for child execution On Tue, 13 May 2003 23:44:53 +0900, Brian Candler wrote: > On Tue, May 13, 2003 at 06:50:54PM +0900, Simon Strandgaard wrote: >> > In the general case, your Ruby program could do lots of things which force >> > a direct output to stdout/stderr. Here is one small valid Ruby program: >> > >> > pid = fork do >> > exec("ls /nonexistent") >> > end >> > Process.waitpid(pid) >> > >> > How are you going to modify Ruby so that the output of those four lines are >> > captured in the sandbox? >> >> All "child-process" routines should parse rb_stdout to the children, in >> this case fork. I know I have only mentioned system&backquote before. >> Well all routines in Rubys Core which spawns children should do this. > > Not acceptable... this time I must insist that you answer the question :-) OK. > How exactly are you proposing to modify the Ruby interpreter so that the > above four lines of Ruby code have their output captured? > > "fork" has specific, well-defined semantics: it just calls the underlying > Unix fork. "exec" has specific, well-defined semantics in the same way. > Neither of them involves pipes. > > What *exactly* do you want the two methods Kernel#fork and Kernel#exec to do > instead of their currently defined behaviour? Kernel#exec does not spawn children.. no changes is necessary here. Kernel#fork does spawn a child.. changes to Rubys Core is necessary. unix-fork inherit stdin/stdout/stderr from parent to the child process. I want Rubys Kernel#fork to inherit rb_stdin/rb_stdout/rb_stderr from the parent to the child process. But hey.. unix-fork() does not take any arguments. Is this possible? My guess - Yes this should be possible. Here is some pseudo code. void Kernel#fork() { backup_stdout = stdout; /* what i want */ stdout = rb_stdout; /* what i want */ pid = fork(); if(pid == 0) stdout = backup_stdout; /* what i want */ } Again assignment to stdout is illegal.. freopen should be used. I just use assignment in this pseudo-code in order to keep it simple. Further more stderr/stdin is left out.. they should of cause also be redirected. This way stdout/stderr/stdin should be untouched and remain usable in the C/C++ application. Does it answer the question ? -- Simon Strandgaard