groups=(p1)
public
Show source
static VALUE
proc_setgroups(VALUE obj, VALUE ary)
{
size_t ngroups, i;
rb_gid_t *groups;
struct group *gr;
Check_Type(ary, T_ARRAY);
ngroups = RARRAY_LEN(ary);
if (ngroups > (size_t)maxgroups)
rb_raise(rb_eArgError, "too many groups, %u max", maxgroups);
groups = ALLOCA_N(rb_gid_t, ngroups);
for (i = 0; i < ngroups && i < (size_t)RARRAY_LEN(ary); i++) {
VALUE g = RARRAY_PTR(ary)[i];
if (FIXNUM_P(g)) {
groups[i] = NUM2GIDT(g);
}
else {
VALUE tmp = rb_check_string_type(g);
if (NIL_P(tmp)) {
groups[i] = NUM2GIDT(g);
}
else {
gr = getgrnam(RSTRING_PTR(tmp));
if (gr == NULL)
rb_raise(rb_eArgError,
"can't find group for %s", RSTRING_PTR(tmp));
groups[i] = gr->gr_gid;
}
}
}
if (setgroups((int)ngroups, groups) == -1) /* ngroups <= maxgroups */
rb_sys_fail(0);
return proc_getgroups(obj);
}