summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-25 15:50:24 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-25 15:50:24 +0000
commitfe9b92f14902e9a7521d1da8467ec9d932a5ce65 (patch)
tree1d6638ff57c908d341a2dc0b35ca4b154d7fe129 /process.c
parent4d93af26df1c322515e535d60cd5b0a66dcc222d (diff)
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@16195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/process.c b/process.c
index 3ffd6d353e..25349b6da6 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);