From: nobu@... Date: 2006-08-09T10:23:39+09:00 Subject: Re: [ ruby-Bugs-5351 ] Process.gid= fails on OS X Hi, At Wed, 9 Aug 2006 00:36:10 +0900, Kazuhiro NISHIYAMA wrote in [ruby-core:08560]: > > It's that simple. Assign to Process.gid= as root and Ruby > > will send you an EPERM. setgid() from libc does not have this > > issue. > | if (setregid(gid, -1) < 0) rb_sys_fail(0); > is used in Mac OS X, and setregid(nonzero, -1) failed. SUSv2 specifies as: The setregid() function is used to set the real and effective group IDs of the calling process. If rgid is -1, the real group ID is not changed; if egid is -1, the effective group ID is not changed. The real and effective group IDs may be set to different values in the same call. http://opengroup.org/onlinepubs/007908799/xsh/setregid.html Also, http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/setregid.2.html says: Supplying a value of -1 for either the real or effective group ID forces the system to substitute the current ID in place of the -1 parameter. Seems a bug of Mac OS X. Index: process.c =================================================================== RCS file: /cvs/ruby/src/ruby/process.c,v retrieving revision 1.92.2.33 diff -p -U 2 -r1.92.2.33 process.c --- process.c 25 Jul 2006 04:58:15 -0000 1.92.2.33 +++ process.c 9 Aug 2006 01:22:24 -0000 @@ -2123,5 +2123,5 @@ proc_setuid(obj, id) #if defined(HAVE_SETRESUID) && !defined(__CHECKER__) if (setresuid(uid, -1, -1) < 0) rb_sys_fail(0); -#elif defined HAVE_SETREUID +#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID) if (setreuid(uid, -1) < 0) rb_sys_fail(0); #elif defined HAVE_SETRUID @@ -2495,5 +2495,5 @@ proc_setgid(obj, id) #if defined(HAVE_SETRESGID) && !defined(__CHECKER__) if (setresgid(gid, -1, -1) < 0) rb_sys_fail(0); -#elif defined HAVE_SETREGID +#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID) if (setregid(gid, -1) < 0) rb_sys_fail(0); #elif defined HAVE_SETRGID @@ -2895,5 +2895,5 @@ proc_seteuid(obj, euid) #if defined(HAVE_SETRESUID) && !defined(__CHECKER__) if (setresuid(-1, NUM2INT(euid), -1) < 0) rb_sys_fail(0); -#elif defined HAVE_SETREUID +#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID) if (setreuid(-1, NUM2INT(euid)) < 0) rb_sys_fail(0); #elif defined HAVE_SETEUID @@ -3009,5 +3009,5 @@ proc_setegid(obj, egid) #if defined(HAVE_SETRESGID) && !defined(__CHECKER__) if (setresgid(-1, NUM2INT(egid), -1) < 0) rb_sys_fail(0); -#elif defined HAVE_SETREGID +#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID) if (setregid(-1, NUM2INT(egid)) < 0) rb_sys_fail(0); #elif defined HAVE_SETEGID -- Nobu Nakada