From 5309af971dd9588e142688d1130cb2a7ad0d26bc Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 20 Jun 2012 12:27:09 +0000 Subject: [PATCH] * internal.h (struct rb_execarg): add umask_given and umask_mask fields. * process.c (STATIC_ASSERT): removed. (rb_execarg_addopt): follow the rb_execarg change. (rb_execarg_run_options): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ internal.h | 2 ++ process.c | 20 +++++++++----------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 409af90238..6bff3490d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Wed Jun 20 21:25:37 2012 Tanaka Akira + + * internal.h (struct rb_execarg): add umask_given and umask_mask + fields. + + * process.c (STATIC_ASSERT): removed. + (rb_execarg_addopt): follow the rb_execarg change. + (rb_execarg_run_options): ditto. + Wed Jun 20 20:38:23 2012 Tanaka Akira * internal.h (struct rb_execarg) moved and renamed from diff --git a/internal.h b/internal.h index e9a0ba1ed8..a849b09b2b 100644 --- a/internal.h +++ b/internal.h @@ -177,6 +177,8 @@ struct rb_execarg { VALUE envp_str; VALUE envp_buf; VALUE dup2_tmpbuf; + unsigned umask_given : 1; + mode_t umask_mask; }; /* argv_str contains extra two elements. diff --git a/process.c b/process.c index ee5ba48773..68b850ab44 100644 --- a/process.c +++ b/process.c @@ -17,8 +17,6 @@ #include "internal.h" #include "vm_core.h" -#define STATIC_ASSERT(name, expr) typedef int static_assert_##name##_check[1 - 2*!(expr)] - #include #include #include @@ -1261,7 +1259,6 @@ enum { EXEC_OPTION_UNSETENV_OTHERS, EXEC_OPTION_ENV, EXEC_OPTION_CHDIR, - EXEC_OPTION_UMASK, EXEC_OPTION_DUP2, EXEC_OPTION_CLOSE, EXEC_OPTION_OPEN, @@ -1633,12 +1630,12 @@ rb_execarg_addopt(struct rb_execarg *e, VALUE key, VALUE val) hide_obj(rb_str_dup(val))); } else if (id == rb_intern("umask")) { - STATIC_ASSERT(sizeof_mode_t, sizeof(long) >= sizeof(mode_t)); /* for LONG2NUM */ mode_t cmask = NUM2MODET(val); - if (!NIL_P(rb_ary_entry(options, EXEC_OPTION_UMASK))) { + if (e->umask_given) { rb_raise(rb_eArgError, "umask option specified twice"); } - rb_ary_store(options, EXEC_OPTION_UMASK, LONG2FIX(cmask)); + e->umask_given = 1; + e->umask_mask = cmask; } else if (id == rb_intern("close_others")) { if (!NIL_P(rb_ary_entry(options, EXEC_OPTION_CLOSE_OTHERS))) { @@ -2767,12 +2764,13 @@ rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, char *e } #endif - obj = rb_ary_entry(options, EXEC_OPTION_UMASK); - if (!NIL_P(obj)) { - mode_t mask = (mode_t)FIX2LONG(obj); /* no method calls */ + if (e->umask_given) { + mode_t mask = e->umask_mask; mode_t oldmask = umask(mask); /* never fail */ /* async-signal-safe */ - if (!NIL_P(soptions)) - rb_ary_store(soptions, EXEC_OPTION_UMASK, MODET2NUM(oldmask)); + if (s) { + s->umask_given = 1; + s->umask_mask = oldmask; + } } obj = rb_ary_entry(options, EXEC_OPTION_DUP2);