From: Nobuyoshi Nakada Date: 2007-02-17T23:35:32+09:00 Subject: [ruby-dev:30376] uid_t/gid_t may be bigger than plain 'int' type なかだです。 しばらく前に[ruby-core:08897]で報告された話ですが、uidやgid、 ついでにpidも必ずしもintでカバーできるとはかぎりません。今のと ころext/etcではuid_t,gid_tについてだけは対応されていますが、 該当する部分はrb_pid_t, rb_uid_t, rb_gid_tを使うべきではないか と思います。 Index: intern.h =================================================================== --- intern.h (revision 11768) +++ intern.h (working copy) @@ -425,11 +425,11 @@ int rb_proc_exec(const char*); VALUE rb_check_argv(int, VALUE*); int rb_exec(const struct rb_exec_arg*); -int rb_fork(int*, int (*)(void*), void*); +rb_pid_t rb_fork(int*, int (*)(void*), void*); VALUE rb_f_exec(int,VALUE*); -int rb_waitpid(int,int*,int); -void rb_syswait(int); -int rb_spawn(int, VALUE*); +rb_pid_t rb_waitpid(rb_pid_t pid, int *status, int flags); +void rb_syswait(rb_pid_t pid); +rb_pid_t rb_spawn(int, VALUE*); VALUE rb_proc_times(VALUE); -VALUE rb_detach_process(int); +VALUE rb_detach_process(pid_t pid); /* range.c */ VALUE rb_range_new(VALUE, VALUE, int); Index: process.c =================================================================== --- process.c (revision 11768) +++ process.c (working copy) @@ -107,4 +107,11 @@ static VALUE S_Tms; #endif +#ifdef BROKEN_SETREUID +#define setreuid ruby_setreuid +#endif +#ifdef BROKEN_SETREGID +#define setregid ruby_setregid +#endif + #if defined(HAVE_44BSD_SETUID) || defined(__MacOS_X__) #if !defined(USE_SETREUID) && !defined(BROKEN_SETREUID) @@ -134,5 +141,5 @@ get_pid(void) { rb_secure(2); - return INT2FIX(getpid()); + return PIDT2NUM(getpid()); } @@ -161,5 +168,5 @@ get_ppid(void) return INT2FIX(0); #else - return INT2FIX(getppid()); + return PIDT2NUM(getppid()); #endif } @@ -210,5 +217,5 @@ rb_last_status_set(int status, rb_pid_t vm->last_status = rb_obj_alloc(rb_cProcStatus); rb_iv_set(vm->last_status, "status", INT2FIX(status)); - rb_iv_set(vm->last_status, "pid", INT2FIX(pid)); + rb_iv_set(vm->last_status, "pid", PIDT2NUM(pid)); } @@ -563,8 +570,8 @@ static st_table *pid_tbl; #endif -int -rb_waitpid(int pid, int *st, int flags) +rb_pid_t +rb_waitpid(rb_pid_t pid, int *st, int flags) { - int result; + rb_pid_t result; #ifndef NO_WAITPID int oflags = flags; @@ -633,10 +640,10 @@ rb_waitpid(int pid, int *st, int flags) #ifdef NO_WAITPID struct wait_data { - int pid; + rb_pid_t pid; int status; }; static int -wait_each(int pid, int status, struct wait_data *data) +wait_each(rb_pid_t pid, int status, struct wait_data *data) { if (data->status != -1) return ST_STOP; @@ -648,8 +655,8 @@ wait_each(int pid, int status, struct wa static int -waitall_each(int pid, int status, VALUE ary) +waitall_each(rb_pid_t pid, int status, VALUE ary) { rb_last_status_set(status, pid); - rb_ary_push(ary, rb_assoc_new(INT2NUM(pid), rb_last_status_get()); + rb_ary_push(ary, rb_assoc_new(PIDT2NUM(pid), rb_last_status_get()); return ST_DELETE; } @@ -719,5 +726,6 @@ proc_wait(int argc, VALUE *argv) { VALUE vpid, vflags; - int pid, flags, status; + rb_pid_t pid; + int flags, status; rb_secure(2); @@ -728,5 +736,5 @@ proc_wait(int argc, VALUE *argv) } else { - pid = NUM2INT(vpid); + pid = NUM2PIDT(vpid); if (argc == 2 && !NIL_P(vflags)) { flags = NUM2UINT(vflags); @@ -739,5 +747,5 @@ proc_wait(int argc, VALUE *argv) return Qnil; } - return INT2FIX(pid); + return PIDT2NUM(pid); } @@ -793,5 +801,6 @@ proc_waitall(void) { VALUE result; - int pid, status; + rb_pid_t pid; + int status; rb_secure(2); @@ -814,5 +823,5 @@ proc_waitall(void) } rb_last_status_set(status, pid); - rb_ary_push(result, rb_assoc_new(INT2NUM(pid), rb_last_status_get())); + rb_ary_push(result, rb_assoc_new(PIDT2NUM(pid), rb_last_status_get())); } #else @@ -825,5 +834,5 @@ proc_waitall(void) rb_sys_fail(0); } - rb_ary_push(result, rb_assoc_new(INT2NUM(pid), rb_last_status_get())); + rb_ary_push(result, rb_assoc_new(PIDT2NUM(pid), rb_last_status_get())); } #endif @@ -834,5 +843,6 @@ static VALUE detach_process_watcher(int *pid_p) { - int cpid, status; + rb_pid_t cpid; + int status; for (;;) { @@ -844,5 +854,5 @@ detach_process_watcher(int *pid_p) VALUE -rb_detach_process(int pid) +rb_detach_process(rb_pid_t pid) { return rb_thread_create(detach_process_watcher, (void*)&pid); @@ -900,5 +910,5 @@ proc_detach(VALUE obj, VALUE pid) { rb_secure(2); - return rb_detach_process(NUM2INT(pid)); + return rb_detach_process(NUM2PIDT(pid)); } @@ -1075,9 +1085,9 @@ rb_proc_exec(const char *str) #define proc_spawn_v(argv, prog) rb_w32_aspawn(P_NOWAIT, prog, argv) #else -static int +static rb_pid_t proc_spawn_v(char **argv, char *prog) { char *extension; - int status; + rb_pid_t status; if (!prog) @@ -1120,5 +1130,5 @@ proc_spawn_v(char **argv, char *prog) #endif -static int +static rb_pid_t proc_spawn_n(int argc, VALUE *argv, VALUE prog) { @@ -1139,10 +1149,10 @@ proc_spawn_n(int argc, VALUE *argv, VALU #define proc_spawn(str) rb_w32_spawn(P_NOWAIT, str, 0) #else -static int +static rb_pid_t proc_spawn(char *str) { char *s, *t; char **argv, **a; - int status; + rb_pid_t status; for (s = str; *s; s++) { @@ -1304,8 +1314,9 @@ proc_syswait(VALUE pid) * +chfunc+ must not raise any exceptions. */ -int +rb_pid_t rb_fork(int *status, int (*chfunc)(void*), void *charg) { - int pid, err, state = 0; + rb_pid_t pid; + int err, state = 0; #ifdef FD_CLOEXEC int ep[2]; @@ -1418,5 +1429,5 @@ rb_f_fork(VALUE obj) { #ifdef HAVE_FORK - int pid; + rb_pid_t pid; rb_secure(2); @@ -1441,5 +1452,5 @@ rb_f_fork(VALUE obj) default: - return INT2FIX(pid); + return PIDT2NUM(pid); } #else @@ -1493,5 +1504,5 @@ rb_f_exit_bang(int argc, VALUE *argv, VA void -rb_syswait(int pid) +rb_syswait(rb_pid_t pid) { static int overriding; @@ -1534,8 +1545,8 @@ rb_syswait(int pid) } -int +rb_pid_t rb_spawn(int argc, VALUE *argv) { - int status; + rb_pid_t status; VALUE prog; @@ -1635,10 +1646,10 @@ static VALUE rb_f_spawn(int argc, VALUE *argv) { - int pid; + rb_pid_t pid; pid = rb_spawn(argc, argv); if (pid == -1) rb_sys_fail(RSTRING_PTR(argv[0])); #if defined(HAVE_FORK) || defined(HAVE_SPAWNV) - return INT2NUM(pid); + return PIDT2NUM(pid); #else return Qnil; @@ -1699,5 +1710,5 @@ static VALUE proc_getpgrp(void) { - int pgrp; + rb_pid_t pgrp; rb_secure(2); @@ -1705,10 +1716,10 @@ proc_getpgrp(void) pgrp = getpgrp(); if (pgrp < 0) rb_sys_fail(0); - return INT2FIX(pgrp); + return PIDT2NUM(pgrp); #else # ifdef HAVE_GETPGID pgrp = getpgid(0); if (pgrp < 0) rb_sys_fail(0); - return INT2FIX(pgrp); + return PIDT2NUM(pgrp); # else rb_notimplement(); @@ -1759,10 +1770,10 @@ proc_getpgid(VALUE obj, VALUE pid) { #if defined(HAVE_GETPGID) && !defined(__CHECKER__) - int i; + rb_pid_t i; rb_secure(2); - i = getpgid(NUM2INT(pid)); + i = getpgid(NUM2PIDT(pid)); if (i < 0) rb_sys_fail(0); - return INT2NUM(i); + return PIDT2NUM(i); #else rb_notimplement(); @@ -1783,9 +1794,9 @@ proc_setpgid(VALUE obj, VALUE pid, VALUE { #ifdef HAVE_SETPGID - int ipid, ipgrp; + rb_pid_t ipid, ipgrp; rb_secure(2); - ipid = NUM2INT(pid); - ipgrp = NUM2INT(pgrp); + ipid = NUM2PIDT(pid); + ipgrp = NUM2PIDT(pgrp); if (setpgid(ipid, ipgrp) < 0) rb_sys_fail(0); @@ -1812,31 +1823,31 @@ proc_setsid(void) { #if defined(HAVE_SETSID) - int pid; + rb_pid_t pid; rb_secure(2); pid = setsid(); if (pid < 0) rb_sys_fail(0); - return INT2FIX(pid); + return PIDT2NUM(pid); #elif defined(HAVE_SETPGRP) && defined(TIOCNOTTY) - rb_pid_t pid; - int ret; + rb_pid_t pid; + int ret; - rb_secure(2); - pid = getpid(); + rb_secure(2); + pid = getpid(); #if defined(SETPGRP_VOID) - ret = setpgrp(); - /* If `pid_t setpgrp(void)' is equivalent to setsid(), - `ret' will be the same value as `pid', and following open() will fail. - In Linux, `int setpgrp(void)' is equivalent to setpgid(0, 0). */ -#else - ret = setpgrp(0, pid); -#endif - if (ret == -1) rb_sys_fail(0); - - if ((fd = open("/dev/tty", O_RDWR)) >= 0) { - ioctl(fd, TIOCNOTTY, NULL); - close(fd); - } - return INT2FIX(pid); + ret = setpgrp(); + /* If `pid_t setpgrp(void)' is equivalent to setsid(), + `ret' will be the same value as `pid', and following open() will fail. + In Linux, `int setpgrp(void)' is equivalent to setpgid(0, 0). */ +#else + ret = setpgrp(0, pid); +#endif + if (ret == -1) rb_sys_fail(0); + + if ((fd = open("/dev/tty", O_RDWR)) >= 0) { + ioctl(fd, TIOCNOTTY, NULL); + close(fd); + } + return PIDT2NUM(pid); #else rb_notimplement(); @@ -2068,5 +2079,5 @@ p_sys_setuid(VALUE obj, VALUE id) #if defined HAVE_SETUID check_uid_switch(); - if (setuid(NUM2INT(id)) != 0) rb_sys_fail(0); + if (setuid(NUM2UIDT(id)) != 0) rb_sys_fail(0); #else rb_notimplement(); @@ -2091,5 +2102,5 @@ p_sys_setruid(VALUE obj, VALUE id) #if defined HAVE_SETRUID check_uid_switch(); - if (setruid(NUM2INT(id)) != 0) rb_sys_fail(0); + if (setruid(NUM2UIDT(id)) != 0) rb_sys_fail(0); #else rb_notimplement(); @@ -2113,5 +2124,5 @@ p_sys_seteuid(VALUE obj, VALUE id) #if defined HAVE_SETEUID check_uid_switch(); - if (seteuid(NUM2INT(id)) != 0) rb_sys_fail(0); + if (seteuid(NUM2UIDT(id)) != 0) rb_sys_fail(0); #else rb_notimplement(); @@ -2137,5 +2148,5 @@ p_sys_setreuid(VALUE obj, VALUE rid, VAL #if defined HAVE_SETREUID check_uid_switch(); - if (setreuid(NUM2INT(rid),NUM2INT(eid)) != 0) rb_sys_fail(0); + if (setreuid(NUM2UIDT(rid),NUM2UIDT(eid)) != 0) rb_sys_fail(0); #else rb_notimplement(); @@ -2161,5 +2172,5 @@ p_sys_setresuid(VALUE obj, VALUE rid, VA #if defined HAVE_SETRESUID check_uid_switch(); - if (setresuid(NUM2INT(rid),NUM2INT(eid),NUM2INT(sid)) != 0) rb_sys_fail(0); + if (setresuid(NUM2UIDT(rid),NUM2UIDT(eid),NUM2UIDT(sid)) != 0) rb_sys_fail(0); #else rb_notimplement(); @@ -2183,6 +2194,6 @@ static VALUE proc_getuid(VALUE obj) { - int uid = getuid(); - return INT2FIX(uid); + rb_uid_t uid = getuid(); + return UIDT2NUM(uid); } @@ -2199,7 +2210,9 @@ static VALUE proc_setuid(VALUE obj, VALUE id) { - int uid = NUM2INT(id); + rb_uid_t uid; check_uid_switch(); + + uid = NUM2UIDT(id); #if defined(HAVE_SETRESUID) && !defined(__CHECKER__) if (setresuid(uid, -1, -1) < 0) rb_sys_fail(0); @@ -2220,5 +2233,5 @@ proc_setuid(VALUE obj, VALUE id) rb_notimplement(); #endif - return INT2FIX(uid); + return id; } @@ -2234,5 +2247,5 @@ proc_setuid(VALUE obj, VALUE id) */ -static int SAVED_USER_ID = -1; +static rb_uid_t SAVED_USER_ID = -1; #ifdef BROKEN_SETREUID @@ -2267,9 +2280,9 @@ static VALUE p_uid_change_privilege(VALUE obj, VALUE id) { - int uid; + rb_uid_t uid; check_uid_switch(); - uid = NUM2INT(id); + uid = NUM2UIDT(id); if (geteuid() == 0) { /* root-user */ @@ -2399,5 +2412,5 @@ p_uid_change_privilege(VALUE obj, VALUE #endif } - return INT2FIX(uid); + return id; } @@ -2418,5 +2431,5 @@ p_sys_setgid(VALUE obj, VALUE id) #if defined HAVE_SETGID check_gid_switch(); - if (setgid(NUM2INT(id)) != 0) rb_sys_fail(0); + if (setgid(NUM2GIDT(id)) != 0) rb_sys_fail(0); #else rb_notimplement(); @@ -2440,5 +2453,5 @@ p_sys_setrgid(VALUE obj, VALUE id) #if defined HAVE_SETRGID check_gid_switch(); - if (setrgid(NUM2INT(id)) != 0) rb_sys_fail(0); + if (setrgid(NUM2GIDT(id)) != 0) rb_sys_fail(0); #else rb_notimplement(); @@ -2463,5 +2476,5 @@ p_sys_setegid(VALUE obj, VALUE id) #if defined HAVE_SETEGID check_gid_switch(); - if (setegid(NUM2INT(id)) != 0) rb_sys_fail(0); + if (setegid(NUM2GIDT(id)) != 0) rb_sys_fail(0); #else rb_notimplement(); @@ -2487,5 +2500,5 @@ p_sys_setregid(VALUE obj, VALUE rid, VAL #if defined HAVE_SETREGID check_gid_switch(); - if (setregid(NUM2INT(rid),NUM2INT(eid)) != 0) rb_sys_fail(0); + if (setregid(NUM2GIDT(rid),NUM2GIDT(eid)) != 0) rb_sys_fail(0); #else rb_notimplement(); @@ -2510,5 +2523,5 @@ p_sys_setresgid(VALUE obj, VALUE rid, VA #if defined HAVE_SETRESGID check_gid_switch(); - if (setresgid(NUM2INT(rid),NUM2INT(eid),NUM2INT(sid)) != 0) rb_sys_fail(0); + if (setresgid(NUM2GIDT(rid),NUM2GIDT(eid),NUM2GIDT(sid)) != 0) rb_sys_fail(0); #else rb_notimplement(); @@ -2561,6 +2574,6 @@ static VALUE proc_getgid(VALUE obj) { - int gid = getgid(); - return INT2FIX(gid); + rb_gid_t gid = getgid(); + return GIDT2NUM(gid); } @@ -2576,7 +2589,9 @@ static VALUE proc_setgid(VALUE obj, VALUE id) { - int gid = NUM2INT(id); + rb_gid_t gid; check_gid_switch(); + + gid = NUM2GIDT(id); #if defined(HAVE_SETRESGID) && !defined(__CHECKER__) if (setresgid(gid, -1, -1) < 0) rb_sys_fail(0); @@ -2597,5 +2612,5 @@ proc_setgid(VALUE obj, VALUE id) rb_notimplement(); #endif - return INT2FIX(gid); + return GIDT2NUM(gid); } @@ -2676,5 +2691,5 @@ proc_setgroups(VALUE obj, VALUE ary) if (FIXNUM_P(g)) { - groups[i] = FIX2INT(g); + groups[i] = NUM2GIDT(g); } else { @@ -2682,5 +2697,5 @@ proc_setgroups(VALUE obj, VALUE ary) if (NIL_P(tmp)) { - groups[i] = NUM2INT(g); + groups[i] = NUM2GIDT(g); } else { @@ -2727,5 +2742,5 @@ proc_initgroups(VALUE obj, VALUE uname, { #ifdef HAVE_INITGROUPS - if (initgroups(StringValuePtr(uname), (rb_gid_t)NUM2INT(base_grp)) != 0) { + if (initgroups(StringValuePtr(uname), NUM2GIDT(base_grp)) != 0) { rb_sys_fail(0); } @@ -2873,9 +2888,9 @@ static VALUE p_gid_change_privilege(VALUE obj, VALUE id) { - int gid; + rb_gid_t gid; check_gid_switch(); - gid = NUM2INT(id); + gid = NUM2GIDT(id); if (geteuid() == 0) { /* root-user */ @@ -3006,5 +3021,5 @@ p_gid_change_privilege(VALUE obj, VALUE #endif } - return INT2FIX(gid); + return id; } @@ -3024,6 +3039,6 @@ static VALUE proc_geteuid(VALUE obj) { - int euid = geteuid(); - return INT2FIX(euid); + rb_uid_t euid = geteuid(); + return NUM2UIDT(euid); } @@ -3040,15 +3055,18 @@ static VALUE proc_seteuid(VALUE obj, VALUE euid) { + rb_uid_t uid; + check_uid_switch(); + + uid = NUM2UIDT(euid); #if defined(HAVE_SETRESUID) && !defined(__CHECKER__) - if (setresuid(-1, NUM2INT(euid), -1) < 0) rb_sys_fail(0); + if (setresuid(-1, uid, -1) < 0) rb_sys_fail(0); #elif defined HAVE_SETREUID - if (setreuid(-1, NUM2INT(euid)) < 0) rb_sys_fail(0); + if (setreuid(-1, uid) < 0) rb_sys_fail(0); #elif defined HAVE_SETEUID - if (seteuid(NUM2INT(euid)) < 0) rb_sys_fail(0); + if (seteuid(uid) < 0) rb_sys_fail(0); #elif defined HAVE_SETUID - euid = NUM2INT(euid); - if (euid == getuid()) { - if (setuid(euid) < 0) rb_sys_fail(0); + if (uid == getuid()) { + if (setuid(uid) < 0) rb_sys_fail(0); } else { @@ -3061,8 +3079,8 @@ proc_seteuid(VALUE obj, VALUE euid) } -static VALUE -rb_seteuid_core(int euid) +static rb_uid_t +rb_seteuid_core(rb_uid_t euid) { - int uid; + rb_uid_t uid; check_uid_switch(); @@ -3092,5 +3110,5 @@ rb_seteuid_core(int euid) rb_notimplement(); #endif - return INT2FIX(euid); + return euid; } @@ -3113,5 +3131,6 @@ static VALUE p_uid_grant_privilege(VALUE obj, VALUE id) { - return rb_seteuid_core(NUM2INT(id)); + rb_seteuid_core(NUM2UIDT(id)); + return id; } @@ -3132,7 +3151,7 @@ static VALUE proc_getegid(VALUE obj) { - int egid = getegid(); + rb_gid_t egid = getegid(); - return INT2FIX(egid); + return GIDT2NUM(egid); } @@ -3149,16 +3168,18 @@ static VALUE proc_setegid(VALUE obj, VALUE egid) { + rb_gid_t gid; + check_gid_switch(); + gid = NUM2GIDT(egid); #if defined(HAVE_SETRESGID) && !defined(__CHECKER__) - if (setresgid(-1, NUM2INT(egid), -1) < 0) rb_sys_fail(0); + if (setresgid(-1, gid, -1) < 0) rb_sys_fail(0); #elif defined HAVE_SETREGID - if (setregid(-1, NUM2INT(egid)) < 0) rb_sys_fail(0); + if (setregid(-1, gid) < 0) rb_sys_fail(0); #elif defined HAVE_SETEGID - if (setegid(NUM2INT(egid)) < 0) rb_sys_fail(0); + if (setegid(gid) < 0) rb_sys_fail(0); #elif defined HAVE_SETGID - egid = NUM2INT(egid); - if (egid == getgid()) { - if (setgid(egid) < 0) rb_sys_fail(0); + if (gid == getgid()) { + if (setgid(gid) < 0) rb_sys_fail(0); } else { @@ -3171,8 +3192,8 @@ proc_setegid(VALUE obj, VALUE egid) } -static VALUE -rb_setegid_core(int egid) +static rb_gid_t +rb_setegid_core(rb_gid_t egid) { - int gid; + rb_gid_t gid; check_gid_switch(); @@ -3202,5 +3223,5 @@ rb_setegid_core(int egid) rb_notimplement(); #endif - return INT2FIX(egid); + return egid; } @@ -3223,5 +3244,6 @@ static VALUE p_gid_grant_privilege(VALUE obj, VALUE id) { - return rb_setegid_core(NUM2INT(id)); + rb_setegid_core(NUM2GIDT(id)); + return id; } @@ -3264,5 +3286,5 @@ static VALUE p_uid_exchange(VALUE obj) { - int uid, euid; + rb_uid_t uid, euid; check_uid_switch(); @@ -3280,5 +3302,5 @@ p_uid_exchange(VALUE obj) rb_notimplement(); #endif - return INT2FIX(uid); + return UIDT2NUM(uid); } @@ -3321,5 +3343,5 @@ static VALUE p_gid_exchange(VALUE obj) { - int gid, egid; + rb_gid_t gid, egid; check_gid_switch(); @@ -3337,5 +3359,5 @@ p_gid_exchange(VALUE obj) rb_notimplement(); #endif - return INT2FIX(gid); + return GIDT2NUM(gid); } @@ -3364,8 +3386,9 @@ p_uid_have_saved_id(void) #if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || defined(_POSIX_SAVED_IDS) static VALUE -p_uid_sw_ensure(int id) +p_uid_sw_ensure(rb_uid_t id) { under_uid_switch = 0; - return rb_seteuid_core(id); + id = rb_seteuid_core(id); + return UIDT2NUM(id); } @@ -3387,5 +3410,5 @@ static VALUE p_uid_switch(VALUE obj) { - int uid, euid; + rb_uid_t uid, euid; check_uid_switch(); @@ -3395,18 +3418,18 @@ p_uid_switch(VALUE obj) if (uid != euid) { - proc_seteuid(obj, INT2FIX(uid)); + proc_seteuid(obj, UIDT2NUM(uid)); if (rb_block_given_p()) { under_uid_switch = 1; return rb_ensure(rb_yield, Qnil, p_uid_sw_ensure, SAVED_USER_ID); } else { - return INT2FIX(euid); + return UIDT2NUM(euid); } } else if (euid != SAVED_USER_ID) { - proc_seteuid(obj, INT2FIX(SAVED_USER_ID)); + proc_seteuid(obj, UIDT2NUM(SAVED_USER_ID)); if (rb_block_given_p()) { under_uid_switch = 1; return rb_ensure(rb_yield, Qnil, p_uid_sw_ensure, euid); } else { - return INT2FIX(uid); + return UIDT2NUM(uid); } } else { @@ -3414,5 +3437,5 @@ p_uid_switch(VALUE obj) rb_sys_fail(0); } - +} #else static VALUE @@ -3426,5 +3449,5 @@ static VALUE p_uid_switch(VALUE obj) { - int uid, euid; + rb_uid_t uid, euid; check_uid_switch(); @@ -3442,8 +3465,8 @@ p_uid_switch(VALUE obj) return rb_ensure(rb_yield, Qnil, p_uid_sw_ensure, obj); } else { - return INT2FIX(euid); + return UIDT2NUM(euid); } -#endif } +#endif @@ -3471,8 +3494,9 @@ p_gid_have_saved_id(void) #if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || defined(_POSIX_SAVED_IDS) static VALUE -p_gid_sw_ensure(int id) +p_gid_sw_ensure(rb_gid_t id) { under_gid_switch = 0; - return rb_setegid_core(id); + id = rb_setegid_core(id); + return GIDT2NUM(id); } @@ -3502,18 +3526,18 @@ p_gid_switch(VALUE obj) if (gid != egid) { - proc_setegid(obj, INT2FIX(gid)); + 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 INT2FIX(egid); + return GIDT2NUM(egid); } } else if (egid != SAVED_GROUP_ID) { - proc_setegid(obj, INT2FIX(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 INT2FIX(gid); + return GIDT2NUM(gid); } } else { @@ -3521,4 +3545,5 @@ p_gid_switch(VALUE obj) rb_sys_fail(0); } +} #else static VALUE @@ -3532,5 +3557,5 @@ static VALUE p_gid_switch(VALUE obj) { - int gid, egid; + rb_gid_t gid, egid; check_gid_switch(); @@ -3548,8 +3573,8 @@ p_gid_switch(VALUE obj) return rb_ensure(rb_yield, Qnil, p_gid_sw_ensure, obj); } else { - return INT2FIX(egid); + return GIDT2NUM(egid); } -#endif } +#endif Index: ruby.h =================================================================== --- ruby.h (revision 11768) +++ ruby.h (working copy) @@ -188,4 +188,37 @@ VALUE rb_ull2inum(unsigned LONG_LONG); #endif +#if SIZEOF_PID_T > SIZEOF_LONG && defined(HAVE_LONG_LONG) +# define PIDT2NUM(v) LL2NUM(v) +# define NUM2PIDT(v) NUM2LL(v) +#elif SIZEOF_PID_T == SIZEOF_LONG +# define PIDT2NUM(v) LONG2NUM(v) +# define NUM2PIDT(v) NUM2LONG(v) +#else +# define PIDT2NUM(v) INT2NUM(v) +# define NUM2PIDT(v) NUM2INT(v) +#endif + +#if SIZEOF_UID_T > SIZEOF_LONG && defined(HAVE_LONG_LONG) +# define UIDT2NUM(v) LL2NUM(v) +# define NUM2UIDT(v) NUM2LL(v) +#elif SIZEOF_UID_T == SIZEOF_LONG +# define UIDT2NUM(v) LONG2NUM(v) +# define NUM2UIDT(v) NUM2LONG(v) +#else +# define UIDT2NUM(v) INT2NUM(v) +# define NUM2UIDT(v) NUM2INT(v) +#endif + +#if SIZEOF_GID_T > SIZEOF_LONG && defined(HAVE_LONG_LONG) +# define GIDT2NUM(v) LL2NUM(v) +# define NUM2GIDT(v) NUM2LL(v) +#elif SIZEOF_GID_T == SIZEOF_LONG +# define GIDT2NUM(v) LONG2NUM(v) +# define NUM2GIDT(v) NUM2LONG(v) +#else +# define GIDT2NUM(v) INT2NUM(v) +# define NUM2GIDT(v) NUM2INT(v) +#endif + #define FIX2LONG(x) RSHIFT((SIGNED_VALUE)x,1) #define FIX2ULONG(x) (((VALUE)(x))>>1) Index: rubyio.h =================================================================== --- rubyio.h (revision 11768) +++ rubyio.h (working copy) @@ -25,5 +25,5 @@ typedef struct OpenFile { FILE *stdio_file; /* stdio ptr for read/write if available */ int mode; /* mode flags */ - int pid; /* child's pid (for pipes) */ + rb_pid_t pid; /* child's pid (for pipes) */ int lineno; /* number of lines read */ char *path; /* pathname for file */ Index: ext/etc/etc.c =================================================================== --- ext/etc/etc.c (revision 11768) +++ ext/etc/etc.c (working copy) @@ -77,6 +77,6 @@ setup_passwd(struct passwd *pwd) safe_setup_str(pwd->pw_passwd), #endif - PW_UID2VAL(pwd->pw_uid), - PW_GID2VAL(pwd->pw_gid), + UIDT2NUM(pwd->pw_uid), + GIDT2NUM(pwd->pw_gid), #ifdef HAVE_ST_PW_GECOS safe_setup_str(pwd->pw_gecos), @@ -126,5 +126,5 @@ etc_getpwuid(int argc, VALUE *argv, VALU rb_secure(4); if (rb_scan_args(argc, argv, "01", &id) == 1) { - uid = PW_VAL2UID(id); + uid = NUM2UIDT(id); } else { @@ -302,5 +302,5 @@ setup_group(struct group *grp) safe_setup_str(grp->gr_passwd), #endif - PW_GID2VAL(grp->gr_gid), + GIDT2NUM(grp->gr_gid), mem); } Index: ext/pty/pty.c =================================================================== --- ext/pty/pty.c (revision 11768) +++ ext/pty/pty.c (working copy) @@ -148,5 +148,6 @@ static VALUE pty_syswait(struct pty_info *info) { - int cpid, status; + rb_pid_t cpid; + int status; for (;;) { @@ -193,4 +194,5 @@ establishShell(int argc, VALUE *argv, st { int i,master,slave; + rb_pid_t pid; char *p,*getenv(); struct passwd *pwent; @@ -219,5 +221,5 @@ establishShell(int argc, VALUE *argv, st info->thread = rb_thread_current(); - if((i = fork()) < 0) { + if ((pid = fork()) < 0) { close(master); close(slave); @@ -225,5 +227,5 @@ establishShell(int argc, VALUE *argv, st } - if(i == 0) { /* child */ + if (pid == 0) { /* child */ /* * Set free from process group and controlling terminal @@ -283,5 +285,5 @@ establishShell(int argc, VALUE *argv, st close(slave); - info->child_pid = i; + info->child_pid = pid; info->fd = master; } @@ -421,5 +423,5 @@ pty_getpty(int argc, VALUE *argv, VALUE rb_ary_store(res,0,(VALUE)rport); rb_ary_store(res,1,(VALUE)wport); - rb_ary_store(res,2,INT2FIX(info.child_pid)); + rb_ary_store(res,2,PIDT2NUM(info.child_pid)); thinfo.thread = rb_thread_create(pty_syswait, (void*)&info); Index: win32/win32.c =================================================================== --- win32/win32.c (revision 11768) +++ win32/win32.c (working copy) @@ -841,5 +841,5 @@ rb_w32_pipe_exec(const char *cmd, const } -int +rb_pid_t rb_w32_spawn(int mode, const char *cmd, const char *prog) { @@ -878,5 +878,5 @@ rb_w32_spawn(int mode, const char *cmd, } -int +rb_pid_t rb_w32_aspawn(int mode, const char *prog, char *const *argv) { @@ -2953,5 +2953,5 @@ poll_child_status(struct ChildRecord *ch rb_pid_t -waitpid (rb_pid_t pid, int *stat_loc, int options) +waitpid(rb_pid_t pid, int *stat_loc, int options) { DWORD timeout; Index: win32/win32.h =================================================================== --- win32/win32.h (revision 11768) +++ win32/win32.h (working copy) @@ -230,6 +230,6 @@ extern rb_pid_t waitpid (rb_pid_t, int * extern int rb_w32_argv_size(char *const *); extern char *rb_w32_join_argv(char *, char *const *); -extern int rb_w32_spawn(int, const char *, const char*); -extern int rb_w32_aspawn(int, const char *, char *const *); +extern rb_pid_t rb_w32_spawn(int, const char *, const char*); +extern rb_pid_t rb_w32_aspawn(int, const char *, char *const *); extern int kill(int, int); extern int fcntl(int, int, ...); -- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦