From b4ab5272980bc0a81575790fee20585b6f205938 Mon Sep 17 00:00:00 2001 From: akr Date: Fri, 25 Apr 2008 15:50:24 +0000 Subject: * process.c (rb_spawn_internal): new function to specify default_close_others. (rb_spawn): specify default_close_others true. (rb_f_system): call rb_spawn_internal with default_close_others as false. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- process.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'process.c') diff --git a/process.c b/process.c index 3ffd6d353..25349b6da 100644 --- a/process.c +++ b/process.c @@ -2544,14 +2544,26 @@ rb_syswait(rb_pid_t pid) } } -rb_pid_t -rb_spawn(int argc, VALUE *argv) +static rb_pid_t +rb_spawn_internal(int argc, VALUE *argv, int default_close_others) { rb_pid_t status; VALUE prog; struct rb_exec_arg earg; - - prog = rb_exec_initarg(argc, argv, Qtrue, &earg); + int argc2 = argc; + VALUE *argv2 = argv, env = Qnil, opthash = Qnil; + VALUE close_others = ID2SYM(rb_intern("close_others")); + + prog = rb_exec_getargs(&argc2, &argv2, Qtrue, &env, &opthash); + if (default_close_others) { + if (NIL_P(opthash)) { + opthash = rb_hash_new(); + RBASIC(opthash)->klass = 0; + } + if (!st_lookup(RHASH_TBL(opthash), close_others, 0)) + rb_hash_aset(opthash, close_others, Qtrue); + } + rb_exec_initarg2(prog, argc2, argv2, env, opthash, &earg); #if defined HAVE_FORK status = rb_fork(&status, rb_exec_atfork, &earg, earg.redirect_fds); @@ -2581,6 +2593,12 @@ rb_spawn(int argc, VALUE *argv) return status; } +rb_pid_t +rb_spawn(int argc, VALUE *argv) +{ + return rb_spawn_internal(argc, argv, Qtrue); +} + /* * call-seq: * system([env,] cmd [, arg, ...] [,options]) => true, false or nil @@ -2618,7 +2636,7 @@ rb_f_system(int argc, VALUE *argv) chfunc = signal(SIGCHLD, SIG_DFL); #endif - status = rb_spawn(argc, argv); + status = rb_spawn_internal(argc, argv, Qfalse); #if defined(HAVE_FORK) || defined(HAVE_SPAWNV) if (status > 0) { rb_syswait(status); -- cgit