diff options
-rw-r--r-- | internal.h | 1 | ||||
-rw-r--r-- | process.c | 23 |
2 files changed, 14 insertions, 10 deletions
diff --git a/internal.h b/internal.h index 2f0a5afe80..b931c115df 100644 --- a/internal.h +++ b/internal.h @@ -1977,6 +1977,7 @@ struct rb_execarg { unsigned uid_given : 1; unsigned gid_given : 1; unsigned exception : 1; + unsigned exception_given : 1; struct waitpid_state *waitpid_state; /* for async process management */ rb_pid_t pgroup_pgid; /* asis(-1), new pgroup(0), specified pgroup (0<V). */ VALUE rlimit_limits; /* Qfalse or [[rtype, softlim, hardlim], ...] */ @@ -2116,6 +2116,13 @@ rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val) "gid option is unimplemented on this machine"); #endif } + else if (id == id_exception) { + if (eargp->exception_given) { + rb_raise(rb_eArgError, "exception option specified twice"); + } + eargp->exception = RTEST(val); + eargp->exception_given = 1; + } else { return ST_STOP; } @@ -2592,23 +2599,16 @@ rb_execarg_get(VALUE execarg_obj) } static VALUE -rb_execarg_init(int argc, const VALUE *orig_argv, int accept_shell, VALUE execarg_obj, int allow_exc_opt) +rb_execarg_init(int argc, const VALUE *orig_argv, int accept_shell, VALUE execarg_obj) { struct rb_execarg *eargp = rb_execarg_get(execarg_obj); - VALUE prog, ret, exception = Qnil; + VALUE prog, ret; VALUE env = Qnil, opthash = Qnil; VALUE argv_buf; VALUE *argv = ALLOCV_N(VALUE, argv_buf, argc); MEMCPY(argv, orig_argv, VALUE, argc); prog = rb_exec_getargs(&argc, &argv, accept_shell, &env, &opthash); - if (allow_exc_opt && !NIL_P(opthash) && rb_hash_has_key(opthash, ID2SYM(id_exception))) { - opthash = rb_hash_dup(opthash); - exception = rb_hash_delete(opthash, ID2SYM(id_exception)); - } rb_exec_fillarg(prog, argc, argv, env, opthash, execarg_obj); - if (RTEST(exception)) { - eargp->exception = 1; - } ALLOCV_END(argv_buf); ret = eargp->use_shell ? eargp->invoke.sh.shell_script : eargp->invoke.cmd.command_name; RB_GC_GUARD(execarg_obj); @@ -2621,7 +2621,10 @@ rb_execarg_new(int argc, const VALUE *argv, int accept_shell, int allow_exc_opt) VALUE execarg_obj; struct rb_execarg *eargp; execarg_obj = TypedData_Make_Struct(0, struct rb_execarg, &exec_arg_data_type, eargp); - rb_execarg_init(argc, argv, accept_shell, execarg_obj, allow_exc_opt); + rb_execarg_init(argc, argv, accept_shell, execarg_obj); + if (!allow_exc_opt && eargp->exception_given) { + rb_raise(rb_eArgError, "exception option is not allowed"); + } return execarg_obj; } |