1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* process.c (proc_setgroups): use getgrnam() if getgrnam_r() is

not available.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2011-03-08 00:25:40 +00:00
parent 487185de67
commit 15f0e53a06
3 changed files with 14 additions and 5 deletions

View file

@ -1,4 +1,7 @@
Tue Mar 8 09:08:00 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
Tue Mar 8 09:25:23 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* process.c (proc_setgroups): use getgrnam() if getgrnam_r() is
not available.
* process.c: RARRAY_LEN() returns long int.

View file

@ -1306,7 +1306,7 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall __syscall chroot ge
setitimer setruid seteuid setreuid setresuid setproctitle socketpair\
setrgid setegid setregid setresgid issetugid pause lchown lchmod\
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
getpriority getrlimit setrlimit sysconf close\
getpriority getrlimit setrlimit sysconf close getgrnam_r\
dlopen sigprocmask sigaction sigsetjmp _setjmp _longjmp\
setsid telldir seekdir fchmod cosh sinh tanh log2 round\
setuid setgid daemon select_large_fdset setenv unsetenv\

View file

@ -4626,12 +4626,14 @@ proc_setgroups(VALUE obj, VALUE ary)
{
int ngroups, i;
rb_gid_t *groups;
#ifdef HAVE_GETGRNAM_R
long getgr_buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
char* getgr_buf;
if (getgr_buf_len < 0)
getgr_buf_len = 4096;
getgr_buf = ALLOCA_N(char, getgr_buf_len);
#endif
Check_Type(ary, T_ARRAY);
@ -4657,16 +4659,20 @@ proc_setgroups(VALUE obj, VALUE ary)
groups[i] = NUM2GIDT(g);
}
else {
StringValue(tmp);
const char *grpname = StringValueCStr(tmp);
ret = getgrnam_r(RSTRING_PTR(tmp), &grp, getgr_buf, getgr_buf_len, &p);
#ifdef HAVE_GETGRNAM_R
ret = getgrnam_r(grpname, &grp, getgr_buf, getgr_buf_len, &p);
if (ret)
rb_sys_fail("getgrnam_r");
#else
p = getgrnam(grpname);
#endif
if (p == NULL) {
rb_raise(rb_eArgError,
"can't find group for %s", RSTRING_PTR(tmp));
}
groups[i] = grp.gr_gid;
groups[i] = p->gr_gid;
}
}
}