Skip to content

Commit 8174b51

Browse files
etiennebarriebyroot
andcommitted
Basic use posix_spawn
Co-authored-by: Jean Boussier <[email protected]>
1 parent 15f6ee0 commit 8174b51

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,6 +2134,7 @@ AC_CHECK_FUNCS(popen)
21342134
AC_CHECK_FUNCS(posix_fadvise)
21352135
AC_CHECK_FUNCS(posix_madvise)
21362136
AC_CHECK_FUNCS(posix_memalign)
2137+
AC_CHECK_FUNCS(posix_spawn)
21372138
AC_CHECK_FUNCS(ppoll)
21382139
AC_CHECK_FUNCS(pread)
21392140
AC_CHECK_FUNCS(pwrite)

process.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
# include <process.h>
3939
#endif
4040

41+
#ifdef HAVE_POSIX_SPAWN
42+
#include <spawn.h>
43+
#endif
44+
4145
#ifndef EXIT_SUCCESS
4246
# define EXIT_SUCCESS 0
4347
#endif
@@ -4612,6 +4616,27 @@ rb_execarg_commandline(const struct rb_execarg *eargp, VALUE *prog)
46124616
}
46134617
#endif
46144618

4619+
#if HAVE_POSIX_SPAWN
4620+
static rb_pid_t
4621+
rb_posix_spawn(struct rb_execarg *eargp)
4622+
{
4623+
pid_t pid;
4624+
char *abspath = NULL;
4625+
4626+
if (!NIL_P(eargp->invoke.cmd.command_abspath)) {
4627+
abspath = RSTRING_PTR(eargp->invoke.cmd.command_abspath);
4628+
}
4629+
else {
4630+
errno = ENOENT;
4631+
return -1;
4632+
}
4633+
4634+
pid = posix_spawn(&pid, abspath, NULL, NULL, NULL, NULL);
4635+
4636+
return (rb_pid_t)pid;
4637+
}
4638+
#endif
4639+
46154640
static rb_pid_t
46164641
rb_spawn_process(struct rb_execarg *eargp, char *errmsg, size_t errmsg_buflen)
46174642
{
@@ -4624,6 +4649,19 @@ rb_spawn_process(struct rb_execarg *eargp, char *errmsg, size_t errmsg_buflen)
46244649
# endif
46254650
#endif
46264651

4652+
#if HAVE_POSIX_SPAWN
4653+
if (!eargp->use_shell &&
4654+
!eargp->pgroup_given &&
4655+
!eargp->umask_given &&
4656+
!eargp->unsetenv_others_given &&
4657+
!eargp->close_others_given &&
4658+
!eargp->chdir_given &&
4659+
!eargp->uid_given &&
4660+
!eargp->gid_given &&
4661+
!eargp->exception_given) {
4662+
return rb_posix_spawn(eargp);
4663+
}
4664+
#endif
46274665
#if defined HAVE_WORKING_FORK && !USE_SPAWNV
46284666
pid = fork_check_err(eargp->status, rb_exec_atfork, eargp, eargp->redirect_fds, errmsg, errmsg_buflen, eargp);
46294667
#else

0 commit comments

Comments
 (0)