summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-23 07:30:26 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-23 07:30:26 +0000
commitf732c5046ed89b0ed669e97f36f5fa05b9a33b73 (patch)
tree8ec82d27a42b5612da1c06f259c21909bb12039d /process.c
parentb25b9569e55ece9e7a4f3971b412d67ff804c504 (diff)
* internal.h (rb_execarg): add rlimit_limits field.
* process.c (EXEC_OPTION_RLIMIT): removed. (mark_exec_arg): mark rlimit_limits field. (rb_execarg_addopt): update the new fields, instead of options array. (run_exec_rlimit): use the new field. (rb_execarg_run_options): clear sarg using MEMZERO. use the new field. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/process.c b/process.c
index bc0f5895f3..bf937dfa7a 100644
--- a/process.c
+++ b/process.c
@@ -1254,7 +1254,6 @@ rb_proc_exec(const char *str)
}
enum {
- EXEC_OPTION_RLIMIT,
EXEC_OPTION_ENV,
EXEC_OPTION_DUP2,
EXEC_OPTION_CLOSE,
@@ -1280,6 +1279,7 @@ mark_exec_arg(void *ptr)
rb_gc_mark(eargp->envp_str);
rb_gc_mark(eargp->envp_buf);
rb_gc_mark(eargp->dup2_tmpbuf);
+ rb_gc_mark(eargp->rlimit_limits);
rb_gc_mark(eargp->chdir_dir);
}
@@ -1588,12 +1588,12 @@ rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val)
#if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM)
if (strncmp("rlimit_", rb_id2name(id), 7) == 0 &&
(rtype = rlimit_type_by_lname(rb_id2name(id)+7)) != -1) {
- VALUE ary = rb_ary_entry(options, EXEC_OPTION_RLIMIT);
+ VALUE ary = eargp->rlimit_limits;
VALUE tmp, softlim, hardlim;
- if (NIL_P(ary)) {
- ary = hide_obj(rb_ary_new());
- rb_ary_store(options, EXEC_OPTION_RLIMIT, ary);
- }
+ if (eargp->rlimit_limits == Qfalse)
+ ary = eargp->rlimit_limits = hide_obj(rb_ary_new());
+ else
+ ary = eargp->rlimit_limits;
tmp = rb_check_array_type(val);
if (!NIL_P(tmp)) {
if (RARRAY_LEN(tmp) == 1)
@@ -2665,7 +2665,6 @@ run_exec_rlimit(VALUE ary, struct rb_execarg *sargp, char *errmsg, size_t errmsg
int rtype = NUM2INT(RARRAY_PTR(elt)[0]);
struct rlimit rlim;
if (sargp) {
- VALUE soptions = sargp->options;
VALUE tmp, newary;
if (getrlimit(rtype, &rlim) == -1) {
ERRMSG("getrlimit");
@@ -2674,11 +2673,10 @@ run_exec_rlimit(VALUE ary, struct rb_execarg *sargp, char *errmsg, size_t errmsg
tmp = hide_obj(rb_ary_new3(3, RARRAY_PTR(elt)[0],
RLIM2NUM(rlim.rlim_cur),
RLIM2NUM(rlim.rlim_max)));
- newary = rb_ary_entry(soptions, EXEC_OPTION_RLIMIT);
- if (NIL_P(newary)) {
- newary = hide_obj(rb_ary_new());
- rb_ary_store(soptions, EXEC_OPTION_RLIMIT, newary);
- }
+ if (sargp->rlimit_limits == Qfalse)
+ newary = sargp->rlimit_limits = hide_obj(rb_ary_new());
+ else
+ newary = sargp->rlimit_limits;
rb_ary_push(newary, tmp);
}
rlim.rlim_cur = NUM2RLIM(RARRAY_PTR(elt)[1]);
@@ -2732,9 +2730,9 @@ rb_execarg_run_options(const struct rb_execarg *eargp, struct rb_execarg *sargp,
if (sargp) {
/* assume that sargp is always NULL on fork-able environments */
+ MEMZERO(sargp, struct rb_execarg, 1);
sargp->options = hide_obj(rb_ary_new());
sargp->redirect_fds = Qnil;
- sargp->envp_str = sargp->envp_buf = 0;
}
#ifdef HAVE_SETPGID
@@ -2745,8 +2743,8 @@ rb_execarg_run_options(const struct rb_execarg *eargp, struct rb_execarg *sargp,
#endif
#if defined(HAVE_SETRLIMIT) && defined(RLIM2NUM)
- obj = rb_ary_entry(options, EXEC_OPTION_RLIMIT);
- if (!NIL_P(obj)) {
+ obj = eargp->rlimit_limits;
+ if (obj != Qfalse) {
if (run_exec_rlimit(obj, sargp, errmsg, errmsg_buflen) == -1) /* hopefully async-signal-safe */
return -1;
}