Skip to content

Commit 7c71826

Browse files
etiennebarriebyroot
andcommitted
Basic use posix_spawn
Co-authored-by: Jean Boussier <[email protected]>
1 parent 927928b commit 7c71826

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
@@ -4614,6 +4618,27 @@ rb_execarg_commandline(const struct rb_execarg *eargp, VALUE *prog)
46144618
}
46154619
#endif
46164620

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

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

0 commit comments

Comments
 (0)