summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-03-07 08:44:45 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-03-07 08:44:45 +0000
commit1df42597d15416357a20bd68700ce1a2d245e8bb (patch)
treef588f28559958e27464866d7b137955bfff04a6f /process.c
parentfc634cc092f486adfc911f614b7b4aa2c48c698d (diff)
cancel subversion backfire. sorry
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c80
1 files changed, 51 insertions, 29 deletions
diff --git a/process.c b/process.c
index 7ca3dfe063..8711ab7c90 100644
--- a/process.c
+++ b/process.c
@@ -122,17 +122,6 @@ static VALUE rb_cProcessTms;
#endif
#endif
-#if SIZEOF_RLIM_T == SIZEOF_INT
-# define RLIM2NUM(v) UINT2NUM(v)
-# define NUM2RLIM(v) NUM2UINT(v)
-#elif SIZEOF_RLIM_T == SIZEOF_LONG
-# define RLIM2NUM(v) ULONG2NUM(v)
-# define NUM2RLIM(v) NUM2ULONG(v)
-#elif SIZEOF_RLIM_T == SIZEOF_LONG_LONG
-# define RLIM2NUM(v) ULL2NUM(v)
-# define NUM2RLIM(v) NUM2ULL(v)
-#endif
-
#define preserving_errno(stmts) \
do {int saved_errno = errno; stmts; errno = saved_errno;} while (0)
@@ -1294,7 +1283,7 @@ enum {
};
static VALUE
-check_exec_redirect_fd(VALUE v)
+check_exec_redirect_fd(VALUE v, int iskey)
{
VALUE tmp;
int fd;
@@ -1326,6 +1315,11 @@ check_exec_redirect_fd(VALUE v)
wrong:
rb_raise(rb_eArgError, "negative file descriptor");
}
+#ifdef _WIN32
+ else if (fd >= 3 && iskey) {
+ rb_raise(rb_eArgError, "wrong file descriptor (%d)", fd);
+ }
+#endif
return INT2FIX(fd);
}
@@ -1363,7 +1357,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
break;
case T_FILE:
- val = check_exec_redirect_fd(val);
+ val = check_exec_redirect_fd(val, 0);
/* fall through */
case T_FIXNUM:
index = EXEC_OPTION_DUP2;
@@ -1375,7 +1369,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
if (RARRAY_LEN(val) == 2 && SYMBOL_P(path) &&
SYM2ID(path) == rb_intern("child")) {
index = EXEC_OPTION_DUP2_CHILD;
- param = check_exec_redirect_fd(rb_ary_entry(val, 1));
+ param = check_exec_redirect_fd(rb_ary_entry(val, 1), 0);
}
else {
index = EXEC_OPTION_OPEN;
@@ -1399,7 +1393,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
path = val;
FilePathValue(path);
if (TYPE(key) == T_FILE)
- key = check_exec_redirect_fd(key);
+ key = check_exec_redirect_fd(key, 1);
if (FIXNUM_P(key) && (FIX2INT(key) == 1 || FIX2INT(key) == 2))
flags = INT2NUM(O_WRONLY|O_CREAT|O_TRUNC);
else
@@ -1419,21 +1413,21 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
rb_ary_store(options, index, ary);
}
if (TYPE(key) != T_ARRAY) {
- VALUE fd = check_exec_redirect_fd(key);
+ VALUE fd = check_exec_redirect_fd(key, !NIL_P(param));
rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param)));
}
else {
int i, n=0;
for (i = 0 ; i < RARRAY_LEN(key); i++) {
VALUE v = RARRAY_PTR(key)[i];
- VALUE fd = check_exec_redirect_fd(v);
+ VALUE fd = check_exec_redirect_fd(v, !NIL_P(param));
rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param)));
n++;
}
}
}
-#ifdef RLIM2NUM
+#if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM)
static int rlimit_type_by_lname(const char *name);
#endif
@@ -1471,7 +1465,7 @@ rb_exec_arg_addopt(struct rb_exec_arg *e, VALUE key, VALUE val)
}
else
#endif
-#ifdef RLIM2NUM
+#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);
@@ -2228,7 +2222,7 @@ run_exec_pgroup(VALUE obj, VALUE save, char *errmsg, size_t errmsg_buflen)
}
#endif
-#ifdef RLIM2NUM
+#if defined(HAVE_SETRLIMIT) && defined(RLIM2NUM)
static int
run_exec_rlimit(VALUE ary, VALUE save, char *errmsg, size_t errmsg_buflen)
{
@@ -2290,7 +2284,7 @@ rb_run_exec_options_err(const struct rb_exec_arg *e, struct rb_exec_arg *s, char
}
#endif
-#ifdef RLIM2NUM
+#if defined(HAVE_SETRLIMIT) && defined(RLIM2NUM)
obj = rb_ary_entry(options, EXEC_OPTION_RLIMIT);
if (!NIL_P(obj)) {
if (run_exec_rlimit(obj, soptions, errmsg, errmsg_buflen) == -1)
@@ -3632,7 +3626,7 @@ proc_setpriority(VALUE obj, VALUE which, VALUE who, VALUE prio)
#define proc_setpriority rb_f_notimplement
#endif
-#if defined(RLIM2NUM)
+#if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM)
static int
rlimit_resource_name2int(const char *name, int casetype)
{
@@ -4526,7 +4520,28 @@ proc_setgid(VALUE obj, VALUE id)
#endif
-static int maxgroups = 32;
+/*
+ * Maximum supplementary groups are platform dependent.
+ * FWIW, 65536 is enough big for our supported OSs.
+ *
+ * OS Name max groups
+ * -----------------------------------------------
+ * Linux Kernel >= 2.6.3 65536
+ * Linux Kernel < 2.6.3 32
+ * IBM AIX 5.2 64
+ * IBM AIX 5.3 ... 6.1 128
+ * IBM AIX 7.1 128 (can be configured to be up to 2048)
+ * OpenBSD, NetBSD 16
+ * FreeBSD < 8.0 16
+ * FreeBSD >=8.0 1023
+ * Darwin (Mac OS X) 16
+ * Sun Solaris 7,8,9,10 16
+ * Sun Solaris 11 / OpenSolaris 1024
+ * HP-UX 20
+ * Windows 1015
+ */
+#define RB_MAX_GROUPS (65536)
+static int maxgroups = RB_MAX_GROUPS;
#ifdef HAVE_GETGROUPS
@@ -4548,9 +4563,13 @@ proc_getgroups(VALUE obj)
int i, ngroups;
rb_gid_t *groups;
- groups = ALLOCA_N(rb_gid_t, maxgroups);
+ ngroups = getgroups(0, NULL);
+ if (ngroups == -1)
+ rb_sys_fail(0);
+
+ groups = ALLOCA_N(rb_gid_t, ngroups);
- ngroups = getgroups(maxgroups, groups);
+ ngroups = getgroups(ngroups, groups);
if (ngroups == -1)
rb_sys_fail(0);
@@ -4687,10 +4706,13 @@ proc_getmaxgroups(VALUE obj)
static VALUE
proc_setmaxgroups(VALUE obj, VALUE val)
{
- int ngroups = FIX2UINT(val);
+ int ngroups = FIX2INT(val);
- if (ngroups > 4096)
- ngroups = 4096;
+ if (ngroups <= 0)
+ rb_raise(rb_eArgError, "maxgroups %d shold be positive", ngroups);
+
+ if (ngroups > RB_MAX_GROUPS)
+ ngroups = RB_MAX_GROUPS;
maxgroups = ngroups;
@@ -5668,7 +5690,7 @@ Init_process(void)
rb_define_module_function(rb_mProcess, "getrlimit", proc_getrlimit, 1);
rb_define_module_function(rb_mProcess, "setrlimit", proc_setrlimit, -1);
-#ifdef RLIM2NUM
+#if defined(RLIM2NUM) && defined(RLIM_INFINITY)
{
VALUE inf = RLIM2NUM(RLIM_INFINITY);
#ifdef RLIM_SAVED_MAX