Hi,

At Fri, 11 Aug 2006 11:06:46 +0900,
Kazuhiro NISHIYAMA wrote in [ruby-core:08589]:
> Mac-mini:~ kazu$ sudo ~/opt/ruby18/bin/ruby -e 'include Process::Sys' -e 'p setregid(502, getegid)'
> -e:2:in `setregid': Operation not permitted (Errno::EPERM)
>         from -e:2
> Mac-mini:~ kazu$

Okay.  Since it feels a show-stopper, I'd like to commit it
before 1.8.5 release as soon as possible.


* process.c (proc_setuid, proc_setgid, proc_seteuid, proc_setegid):
  get rid of bogus implementations on 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 11 Aug 2006 02:41:19 -0000 @@ -2153,6 +2153,21 @@ proc_setuid(obj, id) */ -static int SAVED_USER_ID; +static int SAVED_USER_ID = -1; +#ifdef BROKEN_SETREUID +int +setreuid(ruid, euid) + rb_uid_t ruid, euid; +{ + if (ruid != -1 && ruid != getuid()) { + if (euid == -1) euid = geteuid(); + if (setuid(ruid) < 0) return -1; + } + if (euid != -1 && euid != geteuid()) { + if (seteuid(euid) < 0) return -1; + } + return 0; +} +#endif /* @@ -2498,5 +2513,5 @@ proc_setgid(obj, id) if (setregid(gid, -1) < 0) rb_sys_fail(0); #elif defined HAVE_SETRGID - if (setrgid((GIDTYPE)gid) < 0) rb_sys_fail(0); + if (setrgid(gid) < 0) rb_sys_fail(0); #elif defined HAVE_SETGID { @@ -2703,6 +2718,21 @@ proc_setmaxgroups(VALUE obj, VALUE val) */ -static int SAVED_GROUP_ID; +static int SAVED_GROUP_ID = -1; +#ifdef BROKEN_SETREGID +int +setregid(rgid, egid) + rb_gid_t rgid, egid; +{ + if (rgid != -1 && rgid != getgid()) { + if (egid == -1) egid = getegid(); + if (setgid(rgid) < 0) return -1; + } + if (egid != -1 && egid != getegid()) { + if (setegid(egid) < 0) return -1; + } + return 0; +} +#endif /*
-- Nobu Nakada