switch()
public
Switch the effective and real group IDs of the current process. If a
block is given, the group IDs will be switched back after the
block is executed. Returns the new effective group ID if called without a
block, and the return value of the block if one is given.
Show source
static VALUE
p_gid_switch(VALUE obj)
{
rb_gid_t gid, egid;
check_gid_switch();
gid = getgid();
egid = getegid();
if (gid != egid) {
proc_setegid(obj, GIDT2NUM(gid));
if (rb_block_given_p()) {
under_gid_switch = 1;
return rb_ensure(rb_yield, Qnil, p_gid_sw_ensure, SAVED_GROUP_ID);
}
else {
return GIDT2NUM(egid);
}
}
else if (egid != SAVED_GROUP_ID) {
proc_setegid(obj, GIDT2NUM(SAVED_GROUP_ID));
if (rb_block_given_p()) {
under_gid_switch = 1;
return rb_ensure(rb_yield, Qnil, p_gid_sw_ensure, egid);
}
else {
return GIDT2NUM(gid);
}
}
else {
rb_syserr_fail(EPERM, 0);
}
UNREACHABLE;
}