41 #define EXIT_SUCCESS 0
44 #define EXIT_FAILURE 1
47 #ifdef HAVE_SYS_WAIT_H
48 # include <sys/wait.h>
50 #ifdef HAVE_SYS_RESOURCE_H
51 # include <sys/resource.h>
53 #ifdef HAVE_SYS_PARAM_H
54 # include <sys/param.h>
57 # define MAXPATHLEN 1024
66 #if defined(__native_client__) && defined(NACL_NEWLIB)
72 #ifdef HAVE_SYS_TIMES_H
73 #include <sys/times.h>
83 #define numberof(array) (int)(sizeof(array)/sizeof((array)[0]))
88 #define open rb_w32_uopen
91 #if defined(HAVE_TIMES) || defined(_WIN32)
92 static VALUE rb_cProcessTms;
96 #define WIFEXITED(w) (((w) & 0xff) == 0)
99 #define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
102 #define WIFSTOPPED(w) (((w) & 0xff) == 0x7f)
105 #define WEXITSTATUS(w) (((w) >> 8) & 0xff)
108 #define WTERMSIG(w) ((w) & 0x7f)
111 #define WSTOPSIG WEXITSTATUS
114 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__)
115 #define HAVE_44BSD_SETUID 1
116 #define HAVE_44BSD_SETGID 1
124 #ifdef BROKEN_SETREUID
125 #define setreuid ruby_setreuid
126 int setreuid(rb_uid_t ruid, rb_uid_t euid);
128 #ifdef BROKEN_SETREGID
129 #define setregid ruby_setregid
130 int setregid(rb_gid_t rgid, rb_gid_t egid);
133 #if defined(HAVE_44BSD_SETUID) || defined(__APPLE__)
134 #if !defined(USE_SETREUID) && !defined(BROKEN_SETREUID)
135 #define OBSOLETE_SETREUID 1
137 #if !defined(USE_SETREGID) && !defined(BROKEN_SETREGID)
138 #define OBSOLETE_SETREGID 1
142 #define preserving_errno(stmts) \
143 do {int saved_errno = errno; stmts; errno = saved_errno;} while (0)
149 #define p_uid_from_name p_uid_from_name
150 #define p_gid_from_name p_gid_from_name
153 #if defined(HAVE_PWD_H)
154 # if defined(HAVE_GETPWNAM_R) && defined(_SC_GETPW_R_SIZE_MAX)
155 # define USE_GETPWNAM_R 1
156 # define GETPW_R_SIZE_INIT sysconf(_SC_GETPW_R_SIZE_MAX)
157 # define GETPW_R_SIZE_DEFAULT 0x1000
158 # define GETPW_R_SIZE_LIMIT 0x10000
160 # ifdef USE_GETPWNAM_R
161 # define PREPARE_GETPWNAM \
163 # define FINISH_GETPWNAM \
164 ALLOCV_END(getpw_buf)
165 # define OBJ2UID1(id) obj2uid((id), &getpw_buf)
166 # define OBJ2UID(id) obj2uid0(id)
167 static rb_uid_t obj2uid(
VALUE id,
VALUE *getpw_buf);
168 static inline rb_uid_t
178 # define PREPARE_GETPWNAM
179 # define FINISH_GETPWNAM
180 # define OBJ2UID(id) obj2uid((id))
181 static rb_uid_t obj2uid(
VALUE id);
184 # define PREPARE_GETPWNAM
185 # define FINISH_GETPWNAM
186 # define OBJ2UID(id) NUM2UIDT(id)
187 # ifdef p_uid_from_name
188 # undef p_uid_from_name
189 # define p_uid_from_name rb_f_notimplement
193 #if defined(HAVE_GRP_H)
194 # if defined(HAVE_GETGRNAM_R) && defined(_SC_GETGR_R_SIZE_MAX)
195 # define USE_GETGRNAM_R
196 # define GETGR_R_SIZE_INIT sysconf(_SC_GETGR_R_SIZE_MAX)
197 # define GETGR_R_SIZE_DEFAULT 0x1000
198 # define GETGR_R_SIZE_LIMIT 0x10000
200 # ifdef USE_GETGRNAM_R
201 # define PREPARE_GETGRNAM \
203 # define FINISH_GETGRNAM \
204 ALLOCV_END(getgr_buf)
205 # define OBJ2GID1(id) obj2gid((id), &getgr_buf)
206 # define OBJ2GID(id) obj2gid0(id)
207 static rb_gid_t obj2gid(
VALUE id,
VALUE *getgr_buf);
208 static inline rb_gid_t
217 static rb_gid_t obj2gid(
VALUE id,
VALUE *getgr_buf);
219 # define PREPARE_GETGRNAM
220 # define FINISH_GETGRNAM
221 # define OBJ2GID(id) obj2gid((id))
222 static rb_gid_t obj2gid(
VALUE id);
225 # define PREPARE_GETGRNAM
226 # define FINISH_GETGRNAM
227 # define OBJ2GID(id) NUM2GIDT(id)
228 # ifdef p_gid_from_name
229 # undef p_gid_from_name
230 # define p_gid_from_name rb_f_notimplement
348 #define PST2INT(st) NUM2INT(pst_to_i(st))
375 rb_str_catf(str,
" stopped SIG%s (signal %d)", signame, stopsig);
385 rb_str_catf(str,
" SIG%s (signal %d)", signame, termsig);
395 if (WCOREDUMP(status)) {
472 if (st1 == st2)
return Qtrue;
683 if (WCOREDUMP(status))
692 #if !defined(HAVE_WAITPID) && !defined(HAVE_WAIT4)
731 struct waitpid_arg *arg = data;
734 #if defined NO_WAITPID
736 #elif defined HAVE_WAITPID
737 result =
waitpid(arg->pid, arg->st, arg->flags);
739 result = wait4(arg->pid, arg->st, arg->flags,
NULL);
742 return (
void *)(
VALUE)result;
750 struct waitpid_arg arg;
759 if (
errno == EINTR) {
768 if (pid == (rb_pid_t)-1) {
770 data.
pid = (rb_pid_t)-1;
773 if (data.status != -1) {
778 else if (
st_delete(pid_tbl, &piddata, &status)) {
792 if (
errno == EINTR) {
798 if (result == pid || pid == (rb_pid_t)-1) {
887 if (argc == 2 && !
NIL_P(vflags)) {
891 if ((pid =
rb_waitpid(pid, &status, flags)) < 0)
973 if (
errno == EINTR) {
1005 rb_pid_t cpid,
pid = (rb_pid_t)(
VALUE)arg;
1008 while ((cpid =
rb_waitpid(pid, &status, 0)) == 0) {
1081 static RETSIGTYPE (*saved_sigpipe_handler)(int) = 0;
1086 sig_do_nothing(
int sig)
1102 saved_sigpipe_handler =
signal(SIGPIPE, sig_do_nothing);
1133 signal(SIGPIPE, saved_sigpipe_handler);
1153 #define before_fork() before_exec()
1154 #define after_fork() (rb_threadptr_pending_interrupt_clear(GET_THREAD()), after_exec())
1168 #if defined(HAVE_FORK) && !defined(__native_client__)
1171 #define try_with_sh(prog, argv, envp) ((saved_errno == ENOEXEC) ? exec_with_sh((prog), (argv), (envp)) : (void)0)
1173 exec_with_sh(
const char *prog,
char **
argv,
char **envp)
1175 *argv = (
char *)prog;
1176 *--argv = (
char *)
"sh";
1178 execve(
"/bin/sh", argv, envp);
1180 execv(
"/bin/sh", argv);
1184 #define try_with_sh(prog, argv, envp) (void)0
1191 #ifdef __native_client__
1197 # if defined(__EMX__) || defined(OS2)
1198 char **new_argv =
NULL;
1208 # if defined(__EMX__) || defined(OS2)
1210 # define COMMAND "cmd.exe"
1217 for (n = 0; argv[n]; n++)
1219 new_argv =
ALLOC_N(
char*, n + 2);
1221 new_argv[n + 1] = argv[n];
1222 new_argv[1] = strcpy(
ALLOC_N(
char,
strlen(argv[0]) + 1), argv[0]);
1223 for (p = new_argv[1]; *p !=
'\0'; p++)
1226 new_argv[0] = COMMAND;
1238 execve(prog, argv, envp);
1242 # if defined(__EMX__) || defined(OS2)
1275 #define ARGV_COUNT(n) ((n)+1)
1276 #define ARGV_SIZE(n) (sizeof(char*) * ARGV_COUNT(n))
1277 #define ALLOC_ARGV(n, v) ALLOCV_N(char*, (v), ARGV_COUNT(n))
1285 for (i=0; i<
argc; i++) {
1304 #ifdef __native_client__
1311 while (*s ==
' ' || *s ==
'\t' || *s ==
'\n')
1323 #if defined(__CYGWIN32__) || defined(__EMX__)
1329 execl(shell,
"sh",
"-c", str, (
char *)
NULL);
1331 status = system(str);
1337 execle(
"/bin/sh",
"sh",
"-c", str, (
char *)
NULL, (
char **)
RSTRING_PTR(envp_str));
1339 execl(
"/bin/sh",
"sh",
"-c", str, (
char *)
NULL);
1399 #define HAVE_SPAWNV 1
1402 #if !defined(HAVE_FORK) && defined(HAVE_SPAWNV)
1403 # define USE_SPAWNV 1
1405 # define USE_SPAWNV 0
1408 # define P_NOWAIT _P_NOWAIT
1413 #define proc_spawn_cmd_internal(argv, prog) rb_w32_aspawn(P_NOWAIT, (prog), (argv))
1416 proc_spawn_cmd_internal(
char **argv,
char *prog)
1429 status = spawnv(
P_NOWAIT, prog, (
const char **)argv);
1430 if (status == -1 &&
errno == ENOEXEC) {
1431 *argv = (
char *)prog;
1432 *--argv = (
char *)
"sh";
1433 status = spawnv(
P_NOWAIT,
"/bin/sh", (
const char **)argv);
1435 if (status == -1)
errno = ENOEXEC;
1451 flags = CREATE_NEW_PROCESS_GROUP;
1455 pid = proc_spawn_cmd_internal(argv, prog ?
RSTRING_PTR(prog) : 0);
1462 #define proc_spawn_sh(str) rb_w32_spawn(P_NOWAIT, (str), 0)
1465 proc_spawn_sh(
char *str)
1472 status = spawnl(
P_NOWAIT, (shell ? shell :
"/bin/sh"),
"sh",
"-c", str, (
char*)
NULL);
1521 else if (fd >= 3 && iskey) {
1554 VALUE path, flags, perm;
1558 switch (
TYPE(val)) {
1622 flags =
INT2NUM(O_WRONLY|O_CREAT|O_TRUNC);
1634 if (!
NIL_P(val))
goto io;
1640 #if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM)
1641 static int rlimit_type_by_lname(
const char *
name);
1650 #if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM)
1656 switch (
TYPE(key)) {
1667 else if (val ==
Qtrue)
1690 #if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM)
1691 if (strncmp(
"rlimit_",
rb_id2name(
id), 7) == 0 &&
1692 (rtype = rlimit_type_by_lname(
rb_id2name(
id)+7)) != -1) {
1694 VALUE tmp, softlim, hardlim;
1719 if (
id ==
rb_intern(
"unsetenv_others")) {
1742 else if (
id ==
rb_intern(
"close_others")) {
1773 "uid option is unimplemented on this machine");
1788 "gid option is unimplemented on this machine");
1838 VALUE execarg_obj = args[0];
1840 VALUE nonopts = args[1];
1908 if (oldfd != lastfd) {
1939 args[0] = execarg_obj;
1981 const char *
name = 0;
1998 for (i = 0; i <
argc; i++) {
2015 *opthash_ret =
hash;
2030 prog = (*argv_p)[0];
2031 if (accept_shell && *argc_p == 1) {
2049 int ret = strncmp(word->
ptr, el, word->
len);
2050 if (!ret && ((
const char *)el)[word->
len]) ret = -1;
2063 if (!
NIL_P(opthash)) {
2073 eargp->
invoke.
sh.shell_script = prog;
2079 static const char posix_sh_cmds[][9] = {
2138 if (*p ==
' ' || *p ==
'\t') {
2139 if (first.
ptr && !first.
len) first.
len = p - first.
ptr;
2142 if (!first.
ptr) first.
ptr =
p;
2144 if (!has_meta &&
strchr(
"*?{}[]<>()~&|\\$;'`\"\n#", *p))
2150 else if (*p ==
'/') {
2157 if (!has_meta && first.
ptr) {
2158 if (!first.
len) first.
len = p - first.
ptr;
2159 if (first.
len > 0 && first.
len <=
sizeof(posix_sh_cmds[0]) &&
2172 while (*p ==
' ' || *p ==
'\t')
2176 while (*p && *p !=
' ' && *p !=
'\t')
2189 const char *abspath;
2202 for (i = 0; i <
argc; i++) {
2210 const char *
p, *ep, *null=
NULL;
2294 int unsetenv_others;
2310 if (unsetenv_others || envopts !=
Qfalse) {
2313 if (unsetenv_others) {
2426 VALUE execarg_obj, fail_str;
2428 #define CHILD_ERRMSG_BUFLEN 80
2436 #if defined(__APPLE__) || defined(__HAIKU__)
2448 #define ERRMSG(str) do { if (errmsg && 0 < errmsg_buflen) strlcpy(errmsg, (str), errmsg_buflen); } while (0)
2451 #if defined(DEBUG_REDIRECT)
2456 ttyprintf(
const char *fmt, ...)
2462 tty = fopen(
"con",
"w");
2464 tty = fopen(
"/dev/tty",
"w");
2470 vfprintf(tty, fmt, ap);
2481 ttyprintf(
"dup(%d) => %d\n", oldfd, ret);
2485 #define redirect_dup(oldfd) dup(oldfd)
2488 #if defined(DEBUG_REDIRECT) || defined(_WIN32)
2493 ret =
dup2(oldfd, newfd);
2494 if (newfd >= 0 && newfd <= 2)
2495 SetStdHandle(newfd == 0 ? STD_INPUT_HANDLE : newfd == 1 ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE, (HANDLE)
rb_w32_get_osfhandle(newfd));
2496 #if defined(DEBUG_REDIRECT)
2497 ttyprintf(
"dup2(%d, %d)\n", oldfd, newfd);
2502 #define redirect_dup2(oldfd, newfd) dup2((oldfd), (newfd))
2505 #if defined(DEBUG_REDIRECT)
2511 ttyprintf(
"close(%d)\n", fd);
2519 ret = open(pathname, flags, perm);
2520 ttyprintf(
"open(\"%s\", 0x%x, 0%o) => %d\n", pathname, flags, perm, ret);
2525 #define redirect_close(fd) close(fd)
2526 #define redirect_open(pathname, flags, perm) open((pathname), (flags), (perm))
2535 if (save_fd == -1) {
2564 return *(
int*)a - *(
int*)b;
2570 return *(
int*)b - *(
int*)a;
2599 for (i = 0; i < n; i++) {
2613 for (i = 0; i < n; i++) {
2620 while (pairs < found && (found-1)->
oldfd == newfd)
2622 while (found < pairs+n && found->
oldfd == newfd) {
2631 for (i = 0; i < n; i++) {
2633 while (j != -1 && pairs[j].
oldfd != -1 && pairs[j].
num_newer == 0) {
2642 pairs[j].
oldfd = -1;
2650 for (i = 0; i < n; i++) {
2652 if (pairs[i].
oldfd == -1)
2657 ret =
fcntl(fd, F_GETFD);
2659 ERRMSG(
"fcntl(F_GETFD)");
2662 if (ret & FD_CLOEXEC) {
2664 ret =
fcntl(fd, F_SETFD, ret);
2666 ERRMSG(
"fcntl(F_SETFD)");
2674 if (extra_fd == -1) {
2676 if (extra_fd == -1) {
2690 pairs[
i].
oldfd = extra_fd;
2700 pairs[j].
oldfd = -1;
2704 if (extra_fd != -1) {
2814 run_exec_pgroup(
const struct rb_execarg *eargp,
struct rb_execarg *sargp,
char *errmsg,
size_t errmsg_buflen)
2838 ret = setpgid(getpid(), pgroup);
2839 if (ret == -1)
ERRMSG(
"setpgid");
2844 #if defined(HAVE_SETRLIMIT) && defined(RLIM2NUM)
2847 run_exec_rlimit(
VALUE ary,
struct rb_execarg *sargp,
char *errmsg,
size_t errmsg_buflen)
2861 RLIM2NUM(rlim.rlim_cur),
2862 RLIM2NUM(rlim.rlim_max)));
2869 rlim.rlim_cur = NUM2RLIM(
RARRAY_PTR(elt)[1]);
2870 rlim.rlim_max = NUM2RLIM(
RARRAY_PTR(elt)[2]);
2880 #if !defined(HAVE_FORK)
2921 if (run_exec_pgroup(eargp, sargp, errmsg, errmsg_buflen) == -1)
2926 #if defined(HAVE_SETRLIMIT) && defined(RLIM2NUM)
2929 if (run_exec_rlimit(obj, sargp, errmsg, errmsg_buflen) == -1)
2934 #if !defined(HAVE_FORK)
2974 rb_warn(
"cannot close fd before spawn");
3058 #if !defined(HAVE_FORK)
3059 struct rb_execarg sarg, *
const sargp = &sarg;
3074 char *abspath =
NULL;
3079 #if !defined(HAVE_FORK)
3107 #if !defined FD_CLOEXEC && !defined HAVE_SPAWNV
3108 char errmsg[80] = {
'\0' };
3112 fprintf(stderr,
"%s\n", errmsg);
3115 fprintf(stderr,
"%s:%d: command not found: %s\n",
3117 RSTRING_PTR(e->use_shell ? e->invoke.sh.shell_script : e->invoke.cmd.command_name));
3129 rb_exec_atfork(
void* arg,
char *errmsg,
size_t errmsg_buflen)
3136 #if SIZEOF_INT == SIZEOF_LONG
3137 #define proc_syswait (VALUE (*)(VALUE))rb_syswait
3140 proc_syswait(
VALUE pid)
3148 move_fds_to_avoid_crash(
int *fdp,
int n,
VALUE fds)
3152 for (i = 0; i < n; i++) {
3171 pipe_nocrash(
int filedes[2],
VALUE fds)
3179 if (move_fds_to_avoid_crash(filedes, 2, fds) == -1) {
3189 struct chfunc_protect_t {
3190 int (*
chfunc)(
void*,
char *, size_t);
3197 chfunc_protect(
VALUE arg)
3199 struct chfunc_protect_t *
p = (
struct chfunc_protect_t *)arg;
3201 return (
VALUE)(*p->chfunc)(p->arg, p->errmsg, p->buflen);
3235 retry_fork(
int *status,
int *ep,
int chfunc_is_async_signal_safe)
3240 #define prefork() ( \
3241 rb_io_flush(rb_stdout), \
3242 rb_io_flush(rb_stderr) \
3247 if (!chfunc_is_async_signal_safe)
3252 if (!chfunc_is_async_signal_safe)
3259 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
3262 if (!status && !ep) {
3268 if (status) *status = state;
3269 if (!state)
continue;
3283 send_child_error(
int fd,
int state,
char *errmsg,
size_t errmsg_buflen,
int chfunc_is_async_signal_safe)
3288 if (!chfunc_is_async_signal_safe) {
3289 if (write(fd, &state,
sizeof(state)) ==
sizeof(state) && state) {
3297 if (write(fd, &err,
sizeof(err)) < 0) err =
errno;
3298 if (errmsg && 0 < errmsg_buflen) {
3299 errmsg[errmsg_buflen-1] =
'\0';
3300 errmsg_buflen =
strlen(errmsg);
3301 if (errmsg_buflen > 0 && write(fd, errmsg, errmsg_buflen) < 0)
3308 recv_child_error(
int fd,
int *statep,
VALUE *excp,
int *errp,
char *errmsg,
size_t errmsg_buflen,
int chfunc_is_async_signal_safe)
3314 if (!chfunc_is_async_signal_safe) {
3315 if ((read(fd, &state,
sizeof(state))) ==
sizeof(state) && state) {
3320 if (!*statep && state) *statep = state;
3323 #define READ_FROM_CHILD(ptr, len) \
3324 (NIL_P(io) ? read(fd, (ptr), (len)) : rb_io_bufread(io, (ptr), (len)))
3325 if ((size = READ_FROM_CHILD(&err,
sizeof(err))) < 0) {
3329 if (size ==
sizeof(err) &&
3330 errmsg && 0 < errmsg_buflen) {
3331 ssize_t ret = READ_FROM_CHILD(errmsg, errmsg_buflen-1);
3344 rb_fork_internal(
int *status,
int (*
chfunc)(
void*,
char *,
size_t),
void *charg,
3345 int chfunc_is_async_signal_safe,
VALUE fds,
3346 char *errmsg,
size_t errmsg_buflen)
3354 if (status) *status = 0;
3367 if (pipe_nocrash(ep, fds))
return -1;
3368 pid = retry_fork(status, ep, chfunc_is_async_signal_safe);
3375 if (chfunc_is_async_signal_safe)
3376 ret =
chfunc(charg, errmsg, errmsg_buflen);
3378 struct chfunc_protect_t arg;
3381 arg.errmsg = errmsg;
3382 arg.buflen = errmsg_buflen;
3386 send_child_error(ep[1], state, errmsg, errmsg_buflen, chfunc_is_async_signal_safe);
3387 #if EXIT_SUCCESS == 127
3394 error_occurred = recv_child_error(ep[0], &state, &exc, &err, errmsg, errmsg_buflen, chfunc_is_async_signal_safe);
3395 if (state || error_occurred) {
3398 if (state) *status = state;
3412 rb_fork_err(
int *status,
int (*
chfunc)(
void*,
char *,
size_t),
void *charg,
VALUE fds,
3413 char *errmsg,
size_t errmsg_buflen)
3415 return rb_fork_internal(status,
chfunc, charg,
FALSE, fds, errmsg, errmsg_buflen);
3420 char *errmsg,
size_t errmsg_buflen)
3422 return rb_fork_internal(status,
chfunc, charg,
TRUE, fds, errmsg, errmsg_buflen);
3425 struct chfunc_wrapper_t {
3431 chfunc_wrapper(
void *arg_,
char *errmsg,
size_t errmsg_buflen)
3433 struct chfunc_wrapper_t *arg = arg_;
3434 return arg->chfunc(arg->arg);
3438 rb_fork(
int *status,
int (*
chfunc)(
void*),
void *charg,
VALUE fds)
3441 struct chfunc_wrapper_t warg;
3444 return rb_fork_internal(status, chfunc_wrapper, &warg,
FALSE, fds,
NULL, 0);
3460 #if defined(HAVE_FORK) && !defined(CANNOT_FORK_WITH_PTHREAD)
3511 #define rb_f_fork rb_f_notimplement
3528 #if EXIT_SUCCESS != 0
3555 if (argc > 0 &&
rb_scan_args(argc, argv,
"01", &status) == 1) {
3629 if (argc > 0 &&
rb_scan_args(argc, argv,
"01", &status) == 1) {
3690 #if !defined HAVE_FORK || USE_SPAWNV
3695 #if defined HAVE_FORK && !USE_SPAWNV
3708 # if defined HAVE_SPAWNV
3714 pid = proc_spawn_cmd(argv, prog, eargp);
3716 # if defined(_WIN32)
3801 #if defined(SIGCLD) && !defined(SIGCHLD)
3802 # define SIGCHLD SIGCLD
3806 RETSIGTYPE (*
chfunc)(int);
3812 #if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
3816 if (ret == (rb_pid_t)-1)
3817 rb_sys_fail(
"Another thread waited the process started by system().");
4085 VALUE execarg_obj, fail_str;
4097 const char *prog = errmsg;
4103 #if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
4141 end = time(0) - beg;
4147 #if (defined(HAVE_GETPGRP) && defined(GETPGRP_VOID)) || defined(HAVE_GETPGID)
4165 #if defined(HAVE_GETPGRP) && defined(GETPGRP_VOID)
4176 #define proc_getpgrp rb_f_notimplement
4180 #if defined(HAVE_SETPGID) || (defined(HAVE_SETPGRP) && defined(SETPGRP_VOID))
4199 #elif defined(HAVE_SETPGRP) && defined(SETPGRP_VOID)
4205 #define proc_setpgrp rb_f_notimplement
4209 #if defined(HAVE_GETPGID)
4231 #define proc_getpgid rb_f_notimplement
4247 rb_pid_t ipid, ipgrp;
4257 #define proc_setpgid rb_f_notimplement
4291 #define proc_getsid rb_f_notimplement
4295 #if defined(HAVE_SETSID) || (defined(HAVE_SETPGRP) && defined(TIOCNOTTY))
4296 #if !defined(HAVE_SETSID)
4297 static rb_pid_t ruby_setsid(
void);
4298 #define setsid() ruby_setsid()
4322 #if !defined(HAVE_SETSID)
4323 #define HAVE_SETSID 1
4331 #if defined(SETPGRP_VOID)
4337 ret = setpgrp(0, pid);
4339 if (ret == -1)
return -1;
4350 #define proc_setsid rb_f_notimplement
4354 #ifdef HAVE_GETPRIORITY
4375 int prio, iwhich, iwho;
4382 prio = getpriority(iwhich, iwho);
4387 #define proc_getpriority rb_f_notimplement
4391 #ifdef HAVE_GETPRIORITY
4407 int iwhich, iwho, iprio;
4414 if (setpriority(iwhich, iwho, iprio) < 0)
4419 #define proc_setpriority rb_f_notimplement
4422 #if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM)
4424 rlimit_resource_name2int(
const char *
name,
int casetype)
4428 #define RESCHECK(r) \
4430 if (STRCASECMP(name, #r) == 0) { \
4431 resource = RLIMIT_##r; \
4465 #ifdef RLIMIT_MEMLOCK
4468 #ifdef RLIMIT_MSGQUEUE
4474 #ifdef RLIMIT_NOFILE
4489 #ifdef RLIMIT_RTPRIO
4492 #ifdef RLIMIT_RTTIME
4501 #ifdef RLIMIT_SBSIZE
4504 #ifdef RLIMIT_SIGPENDING
4505 RESCHECK(SIGPENDING);
4514 for (p = name; *
p; p++)
4520 for (p = name; *
p; p++)
4526 rb_bug(
"unexpected casetype");
4533 rlimit_type_by_hname(
const char *
name)
4535 return rlimit_resource_name2int(name, 0);
4539 rlimit_type_by_lname(
const char *
name)
4541 return rlimit_resource_name2int(name, 1);
4545 rlimit_resource_type(
VALUE rtype)
4551 switch (
TYPE(rtype)) {
4571 r = rlimit_type_by_hname(name);
4581 rlimit_resource_value(
VALUE rval)
4586 switch (
TYPE(rval)) {
4603 return NUM2RLIM(rval);
4606 #ifdef RLIM_INFINITY
4607 if (strcmp(name,
"INFINITY") == 0)
return RLIM_INFINITY;
4609 #ifdef RLIM_SAVED_MAX
4610 if (strcmp(name,
"SAVED_MAX") == 0)
return RLIM_SAVED_MAX;
4612 #ifdef RLIM_SAVED_CUR
4613 if (strcmp(name,
"SAVED_CUR") == 0)
return RLIM_SAVED_CUR;
4621 #if defined(HAVE_GETRLIMIT) && defined(RLIM2NUM)
4649 if (
getrlimit(rlimit_resource_type(resource), &rlim) < 0) {
4652 return rb_assoc_new(RLIM2NUM(rlim.rlim_cur), RLIM2NUM(rlim.rlim_max));
4655 #define proc_getrlimit rb_f_notimplement
4658 #if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM)
4713 VALUE resource, rlim_cur, rlim_max;
4718 rb_scan_args(argc, argv,
"21", &resource, &rlim_cur, &rlim_max);
4719 if (rlim_max ==
Qnil)
4720 rlim_max = rlim_cur;
4722 rlim.rlim_cur = rlimit_resource_value(rlim_cur);
4723 rlim.rlim_max = rlimit_resource_value(rlim_max);
4725 if (
setrlimit(rlimit_resource_type(resource), &rlim) < 0) {
4731 #define proc_setrlimit rb_f_notimplement
4739 if (under_uid_switch) {
4749 if (under_gid_switch) {
4765 #if defined(HAVE_PWD_H)
4768 # ifdef USE_GETPWNAM_R
4781 struct passwd *pwptr;
4782 #ifdef USE_GETPWNAM_R
4783 struct passwd pwbuf;
4787 getpw_buf_len = GETPW_R_SIZE_INIT;
4788 if (getpw_buf_len < 0) getpw_buf_len = GETPW_R_SIZE_DEFAULT;
4797 while (getpwnam_r(usrname, &pwbuf, getpw_buf, getpw_buf_len, &pwptr)) {
4798 if (
errno != ERANGE || getpw_buf_len >= GETPW_R_SIZE_LIMIT) {
4807 pwptr = getpwnam(usrname);
4810 #ifndef USE_GETPWNAM_R
4815 uid = pwptr->pw_uid;
4816 #ifndef USE_GETPWNAM_R
4823 # ifdef p_uid_from_name
4832 #if defined(HAVE_GRP_H)
4835 # ifdef USE_GETGRNAM_R
4848 struct group *grptr;
4849 #ifdef USE_GETGRNAM_R
4854 getgr_buf_len = GETGR_R_SIZE_INIT;
4855 if (getgr_buf_len < 0) getgr_buf_len = GETGR_R_SIZE_DEFAULT;
4864 while (getgrnam_r(grpname, &grbuf, getgr_buf, getgr_buf_len, &grptr)) {
4865 if (
errno != ERANGE || getgr_buf_len >= GETGR_R_SIZE_LIMIT) {
4874 grptr = getgrnam(grpname);
4877 #ifndef USE_GETGRNAM_R
4882 gid = grptr->gr_gid;
4883 #ifndef USE_GETGRNAM_R
4890 # ifdef p_gid_from_name
4899 #if defined HAVE_SETUID
4917 #define p_sys_setuid rb_f_notimplement
4921 #if defined HAVE_SETRUID
4939 #define p_sys_setruid rb_f_notimplement
4943 #if defined HAVE_SETEUID
4961 #define p_sys_seteuid rb_f_notimplement
4965 #if defined HAVE_SETREUID
4980 rb_uid_t ruid, euid;
4983 ruid = OBJ2UID1(rid);
4984 euid = OBJ2UID1(eid);
4990 #define p_sys_setreuid rb_f_notimplement
4994 #if defined HAVE_SETRESUID
5009 rb_uid_t ruid, euid, suid;
5012 ruid = OBJ2UID1(rid);
5013 euid = OBJ2UID1(eid);
5014 suid = OBJ2UID1(sid);
5016 if (setresuid(ruid, euid, suid) != 0)
rb_sys_fail(0);
5020 #define p_sys_setresuid rb_f_notimplement
5043 #if defined(HAVE_SETRESUID) || defined(HAVE_SETREUID) || defined(HAVE_SETRUID) || defined(HAVE_SETUID)
5060 #if defined(HAVE_SETRESUID)
5062 #elif defined HAVE_SETREUID
5064 #elif defined HAVE_SETRUID
5066 #elif defined HAVE_SETUID
5079 #define proc_setuid rb_f_notimplement
5095 #ifdef BROKEN_SETREUID
5097 setreuid(rb_uid_t ruid, rb_uid_t euid)
5099 if (ruid != (rb_uid_t)-1 && ruid !=
getuid()) {
5100 if (euid == (rb_uid_t)-1) euid =
geteuid();
5101 if (
setuid(ruid) < 0)
return -1;
5103 if (euid != (rb_uid_t)-1 && euid !=
geteuid()) {
5104 if (
seteuid(euid) < 0)
return -1;
5133 #if defined(HAVE_SETRESUID)
5135 SAVED_USER_ID = uid;
5136 #elif defined(HAVE_SETUID)
5138 SAVED_USER_ID = uid;
5139 #elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
5141 if (SAVED_USER_ID == uid) {
5146 if (setreuid(-1, SAVED_USER_ID) < 0)
rb_sys_fail(0);
5147 if (setreuid(SAVED_USER_ID, 0) < 0)
rb_sys_fail(0);
5150 SAVED_USER_ID = uid;
5156 SAVED_USER_ID = uid;
5162 SAVED_USER_ID = uid;
5164 #elif defined(HAVE_SETRUID) && defined(HAVE_SETEUID)
5166 if (SAVED_USER_ID == uid) {
5180 SAVED_USER_ID = uid;
5187 SAVED_USER_ID = uid;
5195 #if defined(HAVE_SETRESUID)
5196 if (setresuid((
getuid() == uid)? (rb_uid_t)-1: uid,
5197 (
geteuid() == uid)? (rb_uid_t)-1: uid,
5198 (SAVED_USER_ID == uid)? (rb_uid_t)-1: uid) < 0)
rb_sys_fail(0);
5199 SAVED_USER_ID = uid;
5200 #elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
5201 if (SAVED_USER_ID == uid) {
5202 if (setreuid((
getuid() == uid)? (rb_uid_t)-1: uid,
5203 (
geteuid() == uid)? (rb_uid_t)-1: uid) < 0)
5206 else if (
getuid() != uid) {
5207 if (setreuid(uid, (
geteuid() == uid)? (rb_uid_t)-1: uid) < 0)
5209 SAVED_USER_ID = uid;
5213 SAVED_USER_ID = uid;
5217 if (setreuid(-1, SAVED_USER_ID) < 0)
rb_sys_fail(0);
5218 if (setreuid(SAVED_USER_ID, uid) < 0)
rb_sys_fail(0);
5219 SAVED_USER_ID = uid;
5222 #elif defined(HAVE_SETRUID) && defined(HAVE_SETEUID)
5223 if (SAVED_USER_ID == uid) {
5230 SAVED_USER_ID = uid;
5234 SAVED_USER_ID = uid;
5238 else if (
getuid() == uid) {
5241 SAVED_USER_ID = uid;
5248 #elif defined HAVE_44BSD_SETUID
5252 SAVED_USER_ID = uid;
5258 #elif defined HAVE_SETEUID
5259 if (
getuid() == uid && SAVED_USER_ID == uid) {
5266 #elif defined HAVE_SETUID
5267 if (
getuid() == uid && SAVED_USER_ID == uid) {
5283 #if defined HAVE_SETGID
5301 #define p_sys_setgid rb_f_notimplement
5305 #if defined HAVE_SETRGID
5323 #define p_sys_setrgid rb_f_notimplement
5327 #if defined HAVE_SETEGID
5345 #define p_sys_setegid rb_f_notimplement
5349 #if defined HAVE_SETREGID
5364 rb_gid_t rgid, egid;
5374 #define p_sys_setregid rb_f_notimplement
5377 #if defined HAVE_SETRESGID
5392 rb_gid_t rgid, egid, sgid;
5399 if (setresgid(rgid, egid, sgid) != 0)
rb_sys_fail(0);
5403 #define p_sys_setresgid rb_f_notimplement
5407 #if defined HAVE_ISSETUGID
5432 #define p_sys_issetugid rb_f_notimplement
5455 #if defined(HAVE_SETRESGID) || defined(HAVE_SETREGID) || defined(HAVE_SETRGID) || defined(HAVE_SETGID)
5471 #if defined(HAVE_SETRESGID)
5473 #elif defined HAVE_SETREGID
5475 #elif defined HAVE_SETRGID
5477 #elif defined HAVE_SETGID
5490 #define proc_setgid rb_f_notimplement
5494 #if defined(HAVE_SETGROUPS) || defined(HAVE_GETGROUPS)
5515 static int _maxgroups = -1;
5517 get_sc_ngroups_max(
void)
5519 #ifdef _SC_NGROUPS_MAX
5520 return (
int)sysconf(_SC_NGROUPS_MAX);
5521 #elif defined(NGROUPS_MAX)
5522 return (
int)NGROUPS_MAX;
5530 if (_maxgroups < 0) {
5531 _maxgroups = get_sc_ngroups_max();
5542 #ifdef HAVE_GETGROUPS
5561 ngroups = getgroups(0,
NULL);
5565 groups =
ALLOCV_N(rb_gid_t, tmp, ngroups);
5567 ngroups = getgroups(ngroups, groups);
5572 for (i = 0; i < ngroups; i++)
5580 #define proc_getgroups rb_f_notimplement
5584 #ifdef HAVE_SETGROUPS
5609 if (ngroups > maxgroups())
5612 groups =
ALLOCV_N(rb_gid_t, tmp, ngroups);
5614 for (i = 0; i < ngroups; i++) {
5617 groups[
i] = OBJ2GID1(g);
5621 if (setgroups(ngroups, groups) == -1)
5629 #define proc_setgroups rb_f_notimplement
5633 #ifdef HAVE_INITGROUPS
5660 #define proc_initgroups rb_f_notimplement
5663 #if defined(_SC_NGROUPS_MAX) || defined(NGROUPS_MAX)
5680 #define proc_getmaxgroups rb_f_notimplement
5683 #ifdef HAVE_SETGROUPS
5696 int ngroups_max = get_sc_ngroups_max();
5704 if (ngroups_max > 0 && ngroups > ngroups_max)
5705 ngroups = ngroups_max;
5707 _maxgroups = ngroups;
5712 #define proc_setmaxgroups rb_f_notimplement
5715 #if defined(HAVE_DAEMON) || (defined(HAVE_FORK) && defined(HAVE_SETSID))
5716 static int rb_daemon(
int nochdir,
int noclose);
5735 VALUE nochdir, noclose;
5742 n = rb_daemon(
RTEST(nochdir),
RTEST(noclose));
5748 rb_daemon(
int nochdir,
int noclose)
5753 err = daemon(nochdir, noclose);
5759 #define fork_daemon() \
5760 switch (rb_fork_ruby(NULL)) { \
5761 case -1: return -1; \
5762 case 0: rb_thread_atfork(); break; \
5763 default: _exit(EXIT_SUCCESS); \
5768 if (setsid() < 0)
return -1;
5776 if (!noclose && (n =
rb_cloexec_open(
"/dev/null", O_RDWR, 0)) != -1) {
5788 #define proc_daemon rb_f_notimplement
5803 #ifdef BROKEN_SETREGID
5805 setregid(rb_gid_t rgid, rb_gid_t egid)
5807 if (rgid != (rb_gid_t)-1 && rgid !=
getgid()) {
5808 if (egid == (rb_gid_t)-1) egid =
getegid();
5809 if (
setgid(rgid) < 0)
return -1;
5811 if (egid != (rb_gid_t)-1 && egid !=
getegid()) {
5812 if (
setegid(egid) < 0)
return -1;
5841 #if defined(HAVE_SETRESGID)
5843 SAVED_GROUP_ID = gid;
5844 #elif defined HAVE_SETGID
5846 SAVED_GROUP_ID = gid;
5847 #elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
5849 if (SAVED_GROUP_ID == gid) {
5854 if (setregid(-1, SAVED_GROUP_ID) < 0)
rb_sys_fail(0);
5855 if (setregid(SAVED_GROUP_ID, 0) < 0)
rb_sys_fail(0);
5858 SAVED_GROUP_ID = gid;
5864 SAVED_GROUP_ID = gid;
5870 SAVED_GROUP_ID = gid;
5872 #elif defined(HAVE_SETRGID) && defined (HAVE_SETEGID)
5874 if (SAVED_GROUP_ID == gid) {
5889 SAVED_GROUP_ID = gid;
5896 SAVED_GROUP_ID = gid;
5903 #if defined(HAVE_SETRESGID)
5904 if (setresgid((
getgid() == gid)? (rb_gid_t)-1: gid,
5905 (
getegid() == gid)? (rb_gid_t)-1: gid,
5906 (SAVED_GROUP_ID == gid)? (rb_gid_t)-1: gid) < 0)
rb_sys_fail(0);
5907 SAVED_GROUP_ID = gid;
5908 #elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
5909 if (SAVED_GROUP_ID == gid) {
5910 if (setregid((
getgid() == gid)? (rb_uid_t)-1: gid,
5911 (
getegid() == gid)? (rb_uid_t)-1: gid) < 0)
5914 else if (
getgid() != gid) {
5915 if (setregid(gid, (
getegid() == gid)? (rb_uid_t)-1: gid) < 0)
5917 SAVED_GROUP_ID = gid;
5921 SAVED_GROUP_ID = gid;
5925 if (setregid(-1, SAVED_GROUP_ID) < 0)
rb_sys_fail(0);
5926 if (setregid(SAVED_GROUP_ID, gid) < 0)
rb_sys_fail(0);
5927 SAVED_GROUP_ID = gid;
5930 #elif defined(HAVE_SETRGID) && defined(HAVE_SETEGID)
5931 if (SAVED_GROUP_ID == gid) {
5938 SAVED_GROUP_ID = gid;
5942 SAVED_GROUP_ID = gid;
5946 else if (
getgid() == gid) {
5949 SAVED_GROUP_ID = gid;
5956 #elif defined HAVE_44BSD_SETGID
5960 SAVED_GROUP_ID = gid;
5966 #elif defined HAVE_SETEGID
5967 if (
getgid() == gid && SAVED_GROUP_ID == gid) {
5974 #elif defined HAVE_SETGID
5975 if (
getgid() == gid && SAVED_GROUP_ID == gid) {
6009 #if defined(HAVE_SETRESUID) || defined(HAVE_SETREUID) || defined(HAVE_SETEUID) || defined(HAVE_SETUID) || defined(_POSIX_SAVED_IDS)
6011 proc_seteuid(rb_uid_t uid)
6013 #if defined(HAVE_SETRESUID)
6015 #elif defined HAVE_SETREUID
6017 #elif defined HAVE_SETEUID
6019 #elif defined HAVE_SETUID
6032 #if defined(HAVE_SETRESUID) || defined(HAVE_SETREUID) || defined(HAVE_SETEUID) || defined(HAVE_SETUID)
6049 #define proc_seteuid_m rb_f_notimplement
6055 #if defined(HAVE_SETRESUID) || (defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID))
6061 #if defined(HAVE_SETRESUID) || (defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID))
6065 #if defined(HAVE_SETRESUID)
6068 SAVED_USER_ID = euid;
6073 #elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
6078 SAVED_USER_ID = euid;
6080 #elif defined HAVE_SETEUID
6082 #elif defined HAVE_SETUID
6134 #if defined(HAVE_SETRESGID) || defined(HAVE_SETREGID) || defined(HAVE_SETEGID) || defined(HAVE_SETGID) || defined(_POSIX_SAVED_IDS)
6146 #if defined(HAVE_SETRESGID) || defined(HAVE_SETREGID) || defined(HAVE_SETEGID) || defined(HAVE_SETGID)
6152 #if defined(HAVE_SETRESGID) || defined(HAVE_SETREGID) || defined(HAVE_SETEGID) || defined(HAVE_SETGID)
6156 #if defined(HAVE_SETRESGID)
6158 #elif defined HAVE_SETREGID
6160 #elif defined HAVE_SETEGID
6162 #elif defined HAVE_SETGID
6176 #if defined(HAVE_SETRESGID) || defined(HAVE_SETREGID) || defined(HAVE_SETEGID) || defined(HAVE_SETGID)
6177 #define proc_setegid_m proc_setegid
6179 #define proc_setegid_m rb_f_notimplement
6185 #if defined(HAVE_SETRESGID) || (defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID))
6191 #if defined(HAVE_SETRESGID) || (defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID))
6195 #if defined(HAVE_SETRESGID)
6198 SAVED_GROUP_ID = egid;
6203 #elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
6208 SAVED_GROUP_ID = egid;
6210 #elif defined HAVE_SETEGID
6212 #elif defined HAVE_SETGID
6256 #if defined(HAVE_SETRESUID)
6258 #elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
6282 #if defined(HAVE_SETRESUID) || (defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID))
6289 #if defined(HAVE_SETRESUID) || (defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID))
6293 #if defined(HAVE_SETRESUID)
6294 if (setresuid(euid, uid, uid) < 0)
rb_sys_fail(0);
6295 SAVED_USER_ID = uid;
6296 #elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
6298 SAVED_USER_ID = uid;
6318 #if defined(HAVE_SETRESGID)
6320 #elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
6344 #if defined(HAVE_SETRESGID) || (defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID))
6351 #if defined(HAVE_SETRESGID) || (defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID))
6355 #if defined(HAVE_SETRESGID)
6356 if (setresgid(egid, gid, gid) < 0)
rb_sys_fail(0);
6357 SAVED_GROUP_ID = gid;
6358 #elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
6360 SAVED_GROUP_ID = gid;
6381 #if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || defined(_POSIX_SAVED_IDS)
6389 #if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || defined(_POSIX_SAVED_IDS)
6393 under_uid_switch = 0;
6425 under_uid_switch = 1;
6432 else if (euid != SAVED_USER_ID) {
6433 proc_seteuid(SAVED_USER_ID);
6435 under_uid_switch = 1;
6453 under_uid_switch = 0;
6473 under_uid_switch = 1;
6497 #if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || defined(_POSIX_SAVED_IDS)
6504 #if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || defined(_POSIX_SAVED_IDS)
6508 under_gid_switch = 0;
6540 under_gid_switch = 1;
6547 else if (egid != SAVED_GROUP_ID) {
6548 proc_setegid(obj,
GIDT2NUM(SAVED_GROUP_ID));
6550 under_gid_switch = 1;
6568 under_gid_switch = 0;
6588 under_gid_switch = 1;
6598 #if defined(HAVE_TIMES)
6614 const double hertz =
6615 #ifdef HAVE__SC_CLK_TCK
6616 (double)sysconf(_SC_CLK_TCK);
6638 #define rb_proc_times rb_f_notimplement
6733 #ifdef HAVE_GETPRIORITY
6744 #if defined(RLIM2NUM) && defined(RLIM_INFINITY)
6746 VALUE inf = RLIM2NUM(RLIM_INFINITY);
6747 #ifdef RLIM_SAVED_MAX
6749 VALUE v = RLIM_INFINITY == RLIM_SAVED_MAX ? inf : RLIM2NUM(RLIM_SAVED_MAX);
6756 #ifdef RLIM_SAVED_CUR
6758 VALUE v = RLIM_INFINITY == RLIM_SAVED_CUR ? inf : RLIM2NUM(RLIM_SAVED_CUR);
6799 #ifdef RLIMIT_MEMLOCK
6806 #ifdef RLIMIT_MSGQUEUE
6821 #ifdef RLIMIT_NOFILE
6844 #ifdef RLIMIT_RTPRIO
6851 #ifdef RLIMIT_RTTIME
6859 #ifdef RLIMIT_SBSIZE
6864 #ifdef RLIMIT_SIGPENDING
6899 #if defined(HAVE_TIMES) || defined(_WIN32)
6927 #ifdef p_uid_from_name
6930 #ifdef p_gid_from_name
static VALUE p_uid_have_saved_id(void)
static int run_exec_close(VALUE ary, char *errmsg, size_t errmsg_buflen)
struct timeval rb_time_interval(VALUE num)
void rb_syswait(rb_pid_t pid)
void rb_thread_schedule(void)
static VALUE rb_cProcessStatus
#define RUBY_VM_CHECK_INTS(th)
#define redirect_close(fd)
static void before_exec_async_signal_safe(void)
RUBY_EXTERN VALUE rb_cData
static VALUE proc_getgid(VALUE obj)
void rb_thread_atfork(void)
static void check_exec_redirect(VALUE key, VALUE val, struct rb_execarg *eargp)
static int run_exec_open(VALUE ary, struct rb_execarg *sargp, char *errmsg, size_t errmsg_buflen)
int rb_cloexec_fcntl_dupfd(int fd, int minfd)
VALUE rb_ary_new4(long n, const VALUE *elts)
static VALUE rb_check_argv(int argc, VALUE *argv)
VALUE rb_ary_entry(VALUE ary, long offset)
void rb_bug(const char *fmt,...)
static VALUE check_exec_fds(struct rb_execarg *eargp)
static void rb_check_exec_options(VALUE opthash, VALUE execarg_obj)
size_t strlen(const char *)
void rb_update_max_fd(int fd)
struct rb_execarg * rb_execarg_get(VALUE execarg_obj)
#define redirect_open(pathname, flags, perm)
void rb_free_tmp_buffer(volatile VALUE *store)
static VALUE save_env_i(VALUE i, VALUE ary, int argc, VALUE *argv)
rb_pid_t rb_spawn_err(int argc, VALUE *argv, char *errmsg, size_t errmsg_buflen)
void ruby_finalize(void)
Runs the VM finalization processes.
void rb_define_virtual_variable(const char *, VALUE(*)(ANYARGS), void(*)(ANYARGS))
static VALUE hide_obj(VALUE obj)
static VALUE p_uid_exchange(VALUE obj)
static void after_exec(void)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
static VALUE rb_f_system(int argc, VALUE *argv)
int rb_io_modestr_oflags(const char *modestr)
static int under_gid_switch
static VALUE pst_bitand(VALUE st1, VALUE st2)
int rb_cloexec_open(const char *pathname, int flags, mode_t mode)
static VALUE p_uid_exchangeable(void)
static VALUE pst_to_s(VALUE st)
int rb_execarg_run_options(const struct rb_execarg *eargp, struct rb_execarg *sargp, char *errmsg, size_t errmsg_buflen)
void rb_execarg_setenv(VALUE execarg_obj, VALUE env)
static VALUE detach_process_pid(VALUE thread)
int st_insert(st_table *, st_data_t, st_data_t)
static long run_exec_dup2_tmpbuf_size(long n)
struct rb_execarg::@87::@89 cmd
int rb_env_path_tainted(void)
#define TypedData_Get_Struct(obj, type, data_type, sval)
unsigned unsetenv_others_given
static int check_exec_env_i(st_data_t st_key, st_data_t st_val, st_data_t arg)
static int check_exec_fds_1(struct rb_execarg *eargp, VALUE h, int maxhint, VALUE ary)
static rb_gid_t SAVED_GROUP_ID
SOCKET rb_w32_get_osfhandle(int)
static VALUE p_uid_sw_ensure(VALUE obj)
int execl(const char *path, const char *arg0,...)
static VALUE proc_waitall(void)
static int run_exec_dup2_child(VALUE ary, struct rb_execarg *sargp, char *errmsg, size_t errmsg_buflen)
VALUE rb_struct_new(VALUE,...)
int rb_proc_exec(const char *str)
VALUE rb_ary_push(VALUE ary, VALUE item)
void rb_close_before_exec(int lowfd, int maxhint, VALUE noclose_fds)
int rb_proc_exec_n(int argc, VALUE *argv, const char *prog)
int rb_thread_alone(void)
rb_pid_t rb_w32_aspawn_flags(int, const char *, char *const *, DWORD)
static VALUE p_gid_have_saved_id(void)
static VALUE p_gid_exchangeable(void)
rb_pid_t rb_fork_ruby(int *status)
void rb_str_set_len(VALUE, long)
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_raise(VALUE exc, const char *fmt,...)
static int run_exec_dup2(VALUE ary, VALUE tmpbuf, struct rb_execarg *sargp, char *errmsg, size_t errmsg_buflen)
rb_pid_t rb_waitpid(rb_pid_t pid, int *st, int flags)
static void check_gid_switch(void)
VALUE rb_convert_type(VALUE, int, const char *, const char *)
int rb_exec(const struct rb_exec_arg *e)
static VALUE p_gid_change_privilege(VALUE obj, VALUE id)
VALUE rb_ary_new3(long n,...)
static VALUE check_exec_redirect_fd(VALUE v, int iskey)
VALUE rb_f_exit(int argc, VALUE *argv)
void rb_gc_mark(VALUE ptr)
static VALUE pst_equal(VALUE st1, VALUE st2)
int setrlimit(int resource, const struct rlimit *rlp)
static int rb_exec_without_timer_thread(const struct rb_execarg *eargp, char *errmsg, size_t errmsg_buflen)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
static void rb_exec_fillarg(VALUE prog, int argc, VALUE *argv, VALUE env, VALUE opthash, VALUE execarg_obj)
static VALUE pst_success_p(VALUE st)
static VALUE proc_wait(int argc, VALUE *argv)
static void * rb_waitpid_blocking(void *data)
VALUE rb_block_call(VALUE, ID, int, VALUE *, VALUE(*)(ANYARGS), VALUE)
static const rb_data_type_t exec_arg_data_type
int rb_exec_err(const struct rb_exec_arg *e, char *errmsg, size_t errmsg_buflen)
static VALUE pst_wtermsig(VALUE st)
void rb_undef_method(VALUE klass, const char *name)
#define GetOpenFile(obj, fp)
void rb_thread_start_timer_thread(void)
static VALUE pst_wstopsig(VALUE st)
VALUE rb_thread_local_aref(VALUE, ID)
VALUE rb_str_buf_cat(VALUE, const char *, long)
static VALUE pst_wifsignaled(VALUE st)
void rb_exc_raise(VALUE mesg)
unsigned unsetenv_others_do
static rb_pid_t rb_spawn_process(struct rb_execarg *eargp, char *errmsg, size_t errmsg_buflen)
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
#define preserving_errno(stmts)
#define RB_TYPE_P(obj, type)
VALUE rb_last_status_get(void)
#define MEMZERO(p, type, n)
static void before_exec_non_async_signal_safe(void)
void rb_execarg_fixup(VALUE execarg_obj)
static VALUE proc_wait2(int argc, VALUE *argv)
static rb_gid_t rb_setegid_core(rb_gid_t egid)
void rb_thread_sleep(int)
static void mark_exec_arg(void *ptr)
VALUE rb_marshal_dump(VALUE, VALUE)
VALUE rb_class_new_instance(int, VALUE *, VALUE)
int execv(const char *path, char *const argv[])
static VALUE rb_f_exit_bang(int argc, VALUE *argv, VALUE obj)
int rb_block_given_p(void)
int getrlimit(int resource, struct rlimit *rlp)
RUBY_EXTERN VALUE rb_cObject
static VALUE rb_f_spawn(int argc, VALUE *argv)
static rb_uid_t SAVED_USER_ID
#define proc_getmaxgroups
static VALUE proc_detach(VALUE obj, VALUE pid)
const char * ruby_signal_name(int)
rb_pid_t rb_w32_spawn(int, const char *, const char *)
VALUE rb_io_check_io(VALUE io)
int rb_run_exec_options_err(const struct rb_exec_arg *e, struct rb_exec_arg *s, char *errmsg, size_t errmsg_buflen)
VALUE rb_str_cat2(VALUE, const char *)
VALUE rb_str_buf_cat2(VALUE, const char *)
static void after_exec_async_signal_safe(void)
static VALUE pst_wifexited(VALUE st)
VALUE rb_iv_get(VALUE, const char *)
static void after_exec_non_async_signal_safe(void)
void rb_thread_stop_timer_thread(int close_anyway)
int st_delete(st_table *, st_data_t *, st_data_t *)
static int proc_exec_v(char **argv, const char *prog)
rb_pid_t rb_fork_async_signal_safe(int *status, int(*chfunc)(void *, char *, size_t), void *charg, VALUE fds, char *errmsg, size_t errmsg_buflen)
void rb_define_const(VALUE, const char *, VALUE)
void rb_ary_store(VALUE ary, long idx, VALUE val)
static VALUE pst_rshift(VALUE st1, VALUE st2)
void rb_sys_fail_str(VALUE mesg)
static VALUE rb_check_exec_env(VALUE hash)
#define ALLOCV_N(type, v, n)
mode_t umask(mode_t mask)
void ruby_stop(int ex)
Calls ruby_cleanup() and exits the process.
VALUE rb_obj_alloc(VALUE)
static size_t memsize_exec_arg(const void *ptr)
static int save_redirect_fd(int fd, struct rb_execarg *sargp, char *errmsg, size_t errmsg_buflen)
static VALUE proc_geteuid(VALUE obj)
void * rb_thread_call_without_gvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
int rb_exec_async_signal_safe(const struct rb_execarg *eargp, char *errmsg, size_t errmsg_buflen)
static void free_exec_arg(void *ptr)
static void before_exec(void)
size_t rb_str_capacity(VALUE)
VALUE rb_const_get(VALUE, ID)
VALUE rb_thread_local_aset(VALUE, ID, VALUE)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
int rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val)
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
static rb_pid_t rb_spawn_internal(int argc, VALUE *argv, char *errmsg, size_t errmsg_buflen)
VALUE rb_io_fdopen(int, int, const char *)
unsigned close_others_given
static int compare_posix_sh(const void *key, const void *el)
void * rb_alloc_tmp_buffer(volatile VALUE *store, long len)
static VALUE p_uid_switch(VALUE obj)
static VALUE pst_wcoredump(VALUE st)
VALUE rb_sprintf(const char *format,...)
static int chfunc(void *data, char *errbuf, size_t errbuf_len)
static int under_uid_switch
static int proc_exec_cmd(const char *prog, VALUE argv_str, VALUE envp_str)
VALUE rb_iv_set(VALUE, const char *, VALUE)
static void save_env(struct rb_execarg *sargp)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static VALUE pst_pid(VALUE st)
void rb_str_modify_expand(VALUE, long)
char * dln_find_exe_r(const char *, const char *, char *, size_t)
static void pst_message(VALUE str, rb_pid_t pid, int status)
VALUE rb_check_hash_type(VALUE hash)
unsigned char buf[MIME_BUF_SIZE]
VALUE rb_assoc_new(VALUE car, VALUE cdr)
VALUE tied_io_for_writing
static VALUE detach_process_watcher(void *arg)
unsigned new_pgroup_given
static VALUE p_gid_switch(VALUE obj)
#define CHILD_ERRMSG_BUFLEN
const char * rb_class2name(VALUE)
char * strchr(char *, char)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
#define proc_setmaxgroups
VALUE rb_str_new_cstr(const char *)
static int check_exec_options_i_extract(st_data_t st_key, st_data_t st_val, st_data_t arg)
#define RARRAY_LENINT(ary)
st_table * st_init_numtable(void)
void rb_sys_fail(const char *mesg)
static int intcmp(const void *a, const void *b)
void rb_jump_tag(int tag)
void ruby_error_print(void)
static void security(const char *str)
union rb_execarg::@87 invoke
VALUE rb_define_module_under(VALUE outer, const char *name)
#define StringValueCStr(v)
static int check_exec_options_i(st_data_t st_key, st_data_t st_val, st_data_t arg)
static rb_uid_t rb_seteuid_core(rb_uid_t euid)
static VALUE p_gid_grant_privilege(VALUE obj, VALUE id)
VALUE rb_f_abort(int argc, VALUE *argv)
void rb_thread_wait_for(struct timeval)
VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash)
#define try_with_sh(prog, argv, envp)
static st_table * pid_tbl
VALUE rb_equal(VALUE, VALUE)
RUBY_EXTERN VALUE rb_stderr
#define rb_check_arity(argc, min, max)
#define UNLIMITED_ARGUMENTS
sighandler_t signal(int signum, sighandler_t handler)
void rb_last_status_set(int status, rb_pid_t pid)
int utime(const char *filename, const struct utimbuf *times)
static VALUE pst_wifstopped(VALUE st)
VALUE rb_check_convert_type(VALUE, int, const char *, const char *)
#define redirect_dup2(oldfd, newfd)
static VALUE p_gid_exchange(VALUE obj)
void rb_set_errinfo(VALUE err)
static VALUE p_uid_grant_privilege(VALUE obj, VALUE id)
VALUE rb_execarg_init(int argc, VALUE *argv, int accept_shell, VALUE execarg_obj)
static VALUE pst_to_i(VALUE st)
VALUE rb_check_array_type(VALUE ary)
static void check_uid_switch(void)
VALUE rb_exec_arg_init(int argc, VALUE *argv, int accept_shell, struct rb_exec_arg *e)
VALUE rb_str_catf(VALUE str, const char *format,...)
void rb_thread_reset_timer_thread(void)
VALUE rb_f_kill(int, VALUE *)
VALUE rb_check_string_type(VALUE)
static VALUE proc_getegid(VALUE obj)
static VALUE get_ppid(void)
#define ARGVSTR2ARGV(argv_str)
static int exit_status_code(VALUE status)
VALUE rb_execarg_new(int argc, VALUE *argv, int accept_shell)
static int waitall_each(rb_pid_t pid, int status, VALUE ary)
static int fill_envp_buf_i(st_data_t st_key, st_data_t st_val, st_data_t arg)
static VALUE p_gid_sw_ensure(VALUE obj)
static VALUE pst_inspect(VALUE st)
VALUE rb_marshal_load(VALUE)
#define TypedData_Make_Struct(klass, type, data_type, sval)
VALUE rb_ary_dup(VALUE ary)
VALUE rb_io_puts(int, VALUE *, VALUE)
void rb_notimplement(void)
void rb_last_status_clear(void)
static unsigned int hash(const char *str, unsigned int len)
#define SafeStringValue(v)
VALUE rb_ary_join(VALUE ary, VALUE sep)
static VALUE rb_f_sleep(int argc, VALUE *argv)
static int proc_exec_sh(const char *str, VALUE envp_str)
static VALUE p_uid_change_privilege(VALUE obj, VALUE id)
static VALUE rb_exec_getargs(int *argc_p, VALUE **argv_p, int accept_shell, VALUE *env_ret, VALUE *opthash_ret)
const char * rb_id2name(ID id)
#define StringValuePtr(v)
#define redirect_dup(oldfd)
static char fbuf[MAXPATHLEN]
RUBY_EXTERN int dup2(int, int)
int rb_exec_arg_addopt(struct rb_exec_arg *e, VALUE key, VALUE val)
VALUE rb_str_new_frozen(VALUE)
#define STRCASECMP(s1, s2)
#define CONST_ID(var, str)
static VALUE proc_getuid(VALUE obj)
VALUE rb_struct_define(const char *,...)
int rb_run_exec_options(const struct rb_exec_arg *e, struct rb_exec_arg *s)
VALUE rb_define_module(const char *name)
rb_pid_t rb_spawn(int argc, VALUE *argv)
static VALUE check_exec_redirect1(VALUE ary, VALUE key, VALUE param)
#define ARGVSTR2ARGC(argv_str)
VALUE rb_str_buf_new(long)
VALUE rb_detach_process(rb_pid_t pid)
void rb_exec_arg_fixup(struct rb_exec_arg *e)
static VALUE get_pid(void)
VALUE rb_hash_aset(VALUE, VALUE, VALUE)
struct rb_execarg::@87::@88 sh
VALUE rb_thread_create(VALUE(*)(ANYARGS), void *)
VALUE rb_thread_blocking_region(rb_blocking_function_t *func, void *data1, rb_unblock_function_t *ubf, void *data2)
static rb_thread_t * GET_THREAD(void)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
void ruby_setenv(const char *name, const char *value)
VALUE rb_str_new2(const char *)
void rb_warn(const char *fmt,...)
static VALUE pst_wexitstatus(VALUE st)
static int intrcmp(const void *a, const void *b)
rb_pid_t waitpid(rb_pid_t, int *, int)
VALUE rb_attr_get(VALUE, ID)
static int wait_each(rb_pid_t pid, int status, struct wait_data *data)
char * strrchr(const char *, const char)
void rb_thread_sleep_forever(void)
VALUE rb_str_new(const char *, long)
VALUE rb_f_exec(int argc, VALUE *argv)