From 57bc5eaf2f9b44ad8321fecf6dfa45d82a50c580 Mon Sep 17 00:00:00 2001 From: yugui Date: Sat, 11 Oct 2014 13:33:14 +0000 Subject: Fixes build failures on Portable Native Client. Note: Some of the fixes are for newlib in general but not NaCl-specific. * include/ruby/intern.h (rb_fd_select): declare struct timeval, or the struct gets local to the function in C99. * file.c (#include): add nacl/stat.h for PNaCl. (utimes): added a declaration for PNaCl. (stat_atimespec): stat::st_atimensec is long long but timespec::tv_nsec is long in PNaCl. (stat_mtimespec, stat_ctimespec): ditto. (rb_group_member): disable getgroups unless HAVE_GETGROUPS. (eaccess): unify the fallback to generic defined(USE_GETEUID). * io.c: include sys/time.h for struct timeval. (rb_close_before_exec): nothing we can do if F_GETFD is not available. (ioctl): pnacl newlib actually doesn't have ioctl. * process.c (maxgroups): it is used iff defined(_SC_NGROUPS_MAX) || defined(NGROUPS_MAX) but not defined(HAVE_GETGROUPS) || defined(HAVE_SETGROUPS). (obj2gid): fail unless the object is a Fixnum if getgrnam is not available. (disable_child_handler_fork_child): sigaction is not available in PNaCl newlib. * configure.in (warnflags, strict_warnflags): avoid -ansi for strlcpy. (rb_cv_gcc_atomic_builtins): also check __atomic_or_etch because it is used in ruby_atomic.h. (rb_cv_gcc_sync_builtins): ditto. (HAVE_GETGRNAM): added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- process.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'process.c') diff --git a/process.c b/process.c index f9bc01c..301735d 100644 --- a/process.c +++ b/process.c @@ -67,8 +67,11 @@ #include #if defined(__native_client__) && defined(NACL_NEWLIB) +# include # include "nacl/stat.h" # include "nacl/unistd.h" +# include "nacl/resource.h" +# undef HAVE_ISSETUGID #endif #ifdef HAVE_SYS_TIME_H @@ -3389,6 +3392,7 @@ disable_child_handler_before_fork(struct child_handler_disabler_state *old) int ret; sigset_t all; +#ifdef HAVE_PTHREAD_SIGMASK ret = sigfillset(&all); if (ret == -1) rb_sys_fail("sigfillset"); @@ -3398,6 +3402,9 @@ disable_child_handler_before_fork(struct child_handler_disabler_state *old) errno = ret; rb_sys_fail("pthread_sigmask"); } +#else +# pragma GCC warning "pthread_sigmask on fork is not available. potentially dangerous" +#endif #ifdef PTHREAD_CANCEL_DISABLE ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old->cancelstate); @@ -3421,11 +3428,15 @@ disable_child_handler_fork_parent(struct child_handler_disabler_state *old) } #endif +#ifdef HAVE_PTHREAD_SIGMASK ret = pthread_sigmask(SIG_SETMASK, &old->sigmask, NULL); /* not async-signal-safe */ if (ret != 0) { errno = ret; rb_sys_fail("pthread_sigmask"); } +#else +# pragma GCC warning "pthread_sigmask on fork is not available. potentially dangerous" +#endif } /* This function should be async-signal-safe. Actually it is. */ @@ -3434,6 +3445,7 @@ disable_child_handler_fork_child(struct child_handler_disabler_state *old, char { int sig; int ret; +#ifdef POSIX_SIGNAL struct sigaction act, oact; act.sa_handler = SIG_DFL; @@ -3443,6 +3455,9 @@ disable_child_handler_fork_child(struct child_handler_disabler_state *old, char ERRMSG("sigemptyset"); return -1; } +#else + sig_t handler; +#endif for (sig = 1; sig < NSIG; sig++) { int reset = 0; @@ -3451,6 +3466,7 @@ disable_child_handler_fork_child(struct child_handler_disabler_state *old, char reset = 1; #endif if (!reset) { +#ifdef POSIX_SIGNAL ret = sigaction(sig, NULL, &oact); /* async-signal-safe */ if (ret == -1 && errno == EINVAL) { continue; /* Ignore invalid signal number. */ @@ -3461,13 +3477,32 @@ disable_child_handler_fork_child(struct child_handler_disabler_state *old, char } reset = (oact.sa_flags & SA_SIGINFO) || (oact.sa_handler != SIG_IGN && oact.sa_handler != SIG_DFL); +#else + handler = signal(sig, SIG_DFL); + if (handler == SIG_ERR && errno == EINVAL) { + continue; /* Ignore invalid signal number */ + } + if (handler == SIG_ERR) { + ERRMSG("signal to obtain old action"); + return -1; + } + reset = (handler != SIG_IGN && handler != SIG_DFL); +#endif } if (reset) { +#ifdef POSIX_SIGNAL ret = sigaction(sig, &act, NULL); /* async-signal-safe */ if (ret == -1) { ERRMSG("sigaction to set default action"); return -1; } +#else + handler = signal(sig, handler); + if (handler == SIG_ERR) { + ERRMSG("signal to set default action"); + return -1; + } +#endif } } @@ -5036,8 +5071,10 @@ obj2gid(VALUE id getgr_buf = RSTRING_PTR(*getgr_tmp); getgr_buf_len = rb_str_capacity(*getgr_tmp); } -#else +#elif defined(HAVE_GETGRNAM) grptr = getgrnam(grpname); +#else + grptr = NULL; #endif if (!grptr) { #if !defined(USE_GETGRNAM_R) && defined(HAVE_ENDGRENT) @@ -5668,7 +5705,7 @@ proc_setgid(VALUE obj, VALUE id) #endif -#if defined(HAVE_SETGROUPS) || defined(HAVE_GETGROUPS) +#if defined(_SC_NGROUPS_MAX) || defined(NGROUPS_MAX) /* * Maximum supplementary groups are platform dependent. * FWIW, 65536 is enough big for our supported OSs. -- cgit v1.1