Skip to content

Commit

Permalink
use POSIX_SPAWN_SETSIGMASK and POSIX_SPAWN_SETSIGDEF instead of rb_en…
Browse files Browse the repository at this point in the history
…able_interrupt hax to fix for rbx too
  • Loading branch information
tmm1 committed Mar 9, 2011
1 parent 95a7533 commit f649812
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions ext/posix-spawn.c
Expand Up @@ -5,6 +5,7 @@


#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h>
#include <spawn.h> #include <spawn.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
Expand All @@ -14,15 +15,11 @@


#ifdef RUBY_VM #ifdef RUBY_VM
#include <ruby/st.h> #include <ruby/st.h>
extern void rb_enable_interrupt(void);
extern void rb_disable_interrupt(void);
#else #else
#ifndef RBX_CAPI_RUBY_H #ifndef RBX_CAPI_RUBY_H
#include <node.h> #include <node.h>
#endif #endif
#include <st.h> #include <st.h>
#define rb_enable_interrupt()
#define rb_disable_interrupt()
#endif #endif


#ifndef RARRAY_LEN #ifndef RARRAY_LEN
Expand Down Expand Up @@ -291,6 +288,8 @@ rb_posixspawn_pspawn(VALUE self, VALUE env, VALUE argv, VALUE options)
pid_t pid; pid_t pid;
posix_spawn_file_actions_t fops; posix_spawn_file_actions_t fops;
posix_spawnattr_t attr; posix_spawnattr_t attr;
sigset_t mask;
short flags = 0;


/* argv is a [[cmdname, argv0], argv1, argvN, ...] array. */ /* argv is a [[cmdname, argv0], argv1, argvN, ...] array. */
if (TYPE(argv) != T_ARRAY || if (TYPE(argv) != T_ARRAY ||
Expand Down Expand Up @@ -349,14 +348,25 @@ rb_posixspawn_pspawn(VALUE self, VALUE env, VALUE argv, VALUE options)
} }


posixspawn_file_actions_init(&fops, options); posixspawn_file_actions_init(&fops, options);

posix_spawnattr_init(&attr); posix_spawnattr_init(&attr);

/* child does not block any signals */
flags |= POSIX_SPAWN_SETSIGMASK;
sigemptyset(&mask);
posix_spawnattr_setsigmask(&attr, &mask);

/* child uses default signal handlers for all signals */
flags |= POSIX_SPAWN_SETSIGDEF;
sigfillset(&mask);
posix_spawnattr_setsigdefault(&attr, &mask);

#if defined(POSIX_SPAWN_USEVFORK) || defined(__linux__) #if defined(POSIX_SPAWN_USEVFORK) || defined(__linux__)
/* Force USEVFORK on linux. If this is undefined, it's probably because /* Force USEVFORK on linux. If this is undefined, it's probably because
* you forgot to define _GNU_SOURCE at the top of this file. * you forgot to define _GNU_SOURCE at the top of this file.
*/ */
posix_spawnattr_setflags(&attr, POSIX_SPAWN_USEVFORK); flags |= POSIX_SPAWN_USEVFORK;
#endif #endif
posix_spawnattr_setflags(&attr, flags);


if (RTEST(dirname = rb_hash_delete(options, ID2SYM(rb_intern("chdir"))))) { if (RTEST(dirname = rb_hash_delete(options, ID2SYM(rb_intern("chdir"))))) {
char *new_cwd = StringValuePtr(dirname); char *new_cwd = StringValuePtr(dirname);
Expand All @@ -365,9 +375,7 @@ rb_posixspawn_pspawn(VALUE self, VALUE env, VALUE argv, VALUE options)
} }


if (RHASH_SIZE(options) == 0) { if (RHASH_SIZE(options) == 0) {
rb_enable_interrupt();
ret = posix_spawnp(&pid, file, &fops, &attr, cargv, envp ? envp : environ); ret = posix_spawnp(&pid, file, &fops, &attr, cargv, envp ? envp : environ);
rb_disable_interrupt();
if (cwd) { if (cwd) {
chdir(cwd); chdir(cwd);
free(cwd); free(cwd);
Expand Down

0 comments on commit f649812

Please sign in to comment.