From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-05-14T06:56:51+09:00 Subject: Re: RCR for child execution On Tue, 13 May 2003 21:11:08 +0000, ahoward wrote: >> >> > pid = fork do >> >> > exec("ls /nonexistent") >> >> > end >> >> > Process.waitpid(pid) >> >> > > > why must this be done in ruby simon? > this can all be done from within c or c--: The code you see here is Brian Candlers.. not mine. > i think this does exactly what you want - it captures all output, including > output from any child, from a ruby script run from within c. [snip CODE] Yes your code does *most* of what I want.. but unfortunatly not all. I want a permanent sandbox, not a setup/eval/restore sandbox. The reason why I want a permanent sandbox: I have instances of Ruby classes owned by C++ which I access over long time. Exactly "a permanent sandbox" is what all this trouble is about, I should have wrote that in the RCR. The above is the best description of my problem so far. Does anyone understand me at all? >> 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 */ >> } > > > it is possible, but requires no changes to ruby's core, the above accomplishes > this in c. A permanent sandbox requires changes to ruby's core (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. > > if this is done using dup(2) - all is well in the world. Agree.. There is many examples around in this single thread. -- Simon Strandgaard