summaryrefslogtreecommitdiff
path: root/process.c
AgeCommit message (Collapse)Author
2018-07-08signal.c: preserve trap(:CHLD, "IGNORE") behavior with SIGCHLDnormal
We need to preserve "IGNORE" behavior from Ruby 2.5 and earlier. We can't rely on SA_NOCLDWAIT any more, since we always need system() and MJIT to work; so we fake that behavior using dedicated reaper (currently in timer-thread). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-07process.c (rb_f_exec): pause MJIT before replacing processnormal
Non-parallel "make test-spec" caused spec/ruby/core/process/wait2_spec.rb failures because mspec uses "exec" in single-process mode, so there's no chance the post-exec state could know about the MJIT child process from its pre-exec state. [ruby-core:87846] [Bug #14867] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-05unrevert r63852 but keep SIGCHLD path disabled for win32normal
Reading win32/win32.c waitpid implementation, maybe waitpid(-1, ...) on that platform will never conflict with mjit use of waitpid. In any case, I've added WAITPID_USE_SIGCHLD macro to vm_core.h so it can be easy for Linux/BSD users to test (hopefully!) win32-compatible code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-04Revert r63758 and related commitsnaruse
The change is unstable on Windows. Please re-commit it when it correctly supports Windows. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63852 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-02process.c (waitpid_nogvl): start timer thread polling for lossy SIGCHLDnormal
For systems with lossy SIGCHLD, an infinitely sleeping timer thread needs to be aware of rb_waitpid callers in the first place before it can check and reset polling status. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-30process.c: attempt to reap spawnvp (win32) result from mjitnormal
Basically in win32, mjit.c seems to work directly on spawnvp result while normal Ruby code wraps process handles to look like *nix PIDs. I'm only guessing, here... git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-30use SIGCHLD_LOSSY to enable waitpid polling modenormal
Some systems lack SIGCHLD or have incomplete SIGCHLD implementations. So enable polling mode for them. [ruby-core:87705] [Bug #14867] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-29process.c: handle errno correctly in non-SIGCHLD pathnormal
It's a bit redundant, but we optimize for platforms with SIGCHLD, not without. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63790 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-29process.c (waitpid_nogvl): check interrupts before sleepingnormal
We may be interrupted by another thread after setting ubf, but before we re-acquire interrupt_lock again to sleep on w->cond. This should fix test_wait_interrupt in test/ruby/test_process.rb git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63789 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-29process.c: fix typo in non-SIGCHLD waitpid :xnormal
I expect this to fix [Bug #14873] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-27use rb_pid_t instead of pid_tnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-27process.c (waitpid_wait): do not set ECHILD prematurelynormal
It is possible to have both MJIT and normal child processes alive, so we cannot set ECHILD based on such a guess. We can still elide waitpid(PID <= 0) calls if we have callers in vm->waiting_pids, however. For specs, ensure Process.waitall does not leak MJIT PIDs to Rubyspace. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-27s/pid_t/rb_pid_t/normal
Some platforms do not have pid_t :x git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-27hijack SIGCHLD handler for internal usenormal
Use a global SIGCHLD handler to guard all callers of rb_waitpid. To work safely with multi-threaded programs, we introduce a VM-wide waitpid_lock to be acquired BEFORE fork/vfork spawns the process. This is to be combined with the new ruby_waitpid_locked function used by mjit.c in a non-Ruby thread. Ruby-level SIGCHLD handlers registered with Signal.trap(:CHLD) continues to work as before and there should be no regressions in any existing use cases. Splitting the wait queues for PID > 0 and groups (PID <= 0) ensures we favor PID > 0 callers. The disabling of SIGCHLD in rb_f_system is longer necessary, as we use deferred signal handling and no longer make ANY blocking waitpid syscalls in other threads which could "beat" the waitpid call made by rb_f_system. We prevent SIGCHLD from firing in normal Ruby Threads and only enable it in the timer-thread, to prevent spurious wakeups from in test/-ext-/gvl/test_last_thread.rb with MJIT enabled. I've tried to guard as much of the code for RUBY_SIGCHLD==0 using C "if" statements rather than CPP "#if" so to reduce the likelyhood of portability problems as the compiler will see more code. We also work to suppress false-positives from Process.wait(-1, Process::WNOHANG) to quiets warnings from spec/ruby/core/process/wait2_spec.rb with MJIT enabled. Lastly, we must implement rb_grantpt for ext/pty. We need a MJIT-compatible way of supporting grantpt(3) which may spawn the `pt_chown' binary and call waitpid(2) on it. [ruby-core:87605] [Ruby trunk Bug#14867] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-24process.c (ruby_fork_ruby): fix race in signal handlingnormal
We must block signals before stopping timer-thread, otherwise signal handing may be delayed until (and if) another signal is received after timer-thread is restarted. [ruby-core:87622] [Bug #14868] [Bug #13916] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-24process.c (after_fork_ruby): make it a proper functionnormal
Improves readability to me, and there's no point in using macros for this with decent compilers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-16mjit.c: measure time more preciselynobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-14prefer clock_gettimenobu
* configure.ac: clock_gettime or gettimeofday must exist. * process.c (rb_clock_gettime): prefer clock_gettime over gettimeofday, as the latter is obsolete in SUSv4. * random.c (fill_random_seed): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-14RSTRING_PTR is not guaranteed to be char*-alignedshyouhei
This commit eliminates (char **)RSTRING_PTR(...) like usages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-09fix potential memory leaksnobu
* gc.c (rb_alloc_tmp_buffer_with_count): keep the order; allocate an empty imemo first then xmalloc, to get rid of potential memory leak when allocation imemo failed. * parse.y (rb_parser_malloc, rb_parser_calloc, rb_parser_realloc): ditto. * process.c (rb_execarg_allocate_dup2_tmpbuf): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63385 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-09RSTRING_PTR is not guaranteed to be VALUE-alignedshyouhei
Don't abuse struct RString to hold arbitrary memory region. Thanks to @mame we now have rb_imemo_alloc_auto_free_pointer so use it instead. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-04forgot to add INT2FIX (sorry!)shyouhei
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-04passing rb_thread_sleep to rb_protect is IMHO dangerousshyouhei
rb_thread_sleep's argument is int, while rb_protect expects the function to take VALUE. Depending on ABI this could be a problem. We should wrap rb_thread_sleep here. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63339 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-14process.c: [DOC] fix grammarstomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-25guard before noreturn functionnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-25process.c: guard eargp against GCk0kubun
`rb_str_append` may trigger GC, and in that case eargp might be GCed. Probably for protecting it, `RB_GC_GUARD(execarg_obj)` can be seen in other places. Hoping to fix: http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/569818 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23[DOC] missing docs at toplevelnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23[DOC] obsolete classesnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23[DOC] nodoc internal methods/classesnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23process.c: deprecated Struct::Tmsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62540 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-13process.c (try_with_sh): fix the wrong number of argumentsmame
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-03process.c: command_name encodingnobu
* process.c (rb_exec_fillarg): share subsequence of argv_buf for command_name, and copy the encoding from the command string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-02process.c: split pst_message_status from pst_messagenobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-02process.c: reduce intermediate stringnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-02Use more verbose status in error messageskazu
of `system` with `exception: true` like `Process::Status#inspect` [Feature #14386] [ruby-core:85013] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-24ruby/ruby.h: remove unnecessary exports from C-APInormal
Needlessly exporting can reduce performance locally and increase binary size. Increasing the footprint of our C-API larger is also detrimental to our development as it encourages tighter coupling with our internals; making it harder for us to preserve compatibility. If some parts of the core codebase needs access to globals, internal.h should be used instead of anything in include/ruby/*. "Urabe, Shyouhei" <shyouhei@ruby-lang.org> wrote: > On Thu, Jan 18, 2018 at 7:33 PM, Eric Wong <normalperson@yhbt.net> wrote: > > shyouhei@ruby-lang.org wrote: > >> https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61908 > >> > >> export rb_mFConst > > > > Why are we exporting all these and making the public C-API bigger? > > If anything, we should make these static. Thanks. > > No concrete reason, except they have already been externed in 2.5. > These variables had lacked declarations so far, which resulted in their > visibility to be that of extern. The commit is just confirming the status quo. > > I'm not against to turn them into static. This reverts changes from r61910, r61909, r61908, r61907, and r61906. * transcode.c (rb_eUndefinedConversionError): make static (rb_eInvalidByteSequenceError): ditto (rb_eConverterNotFoundError): ditto * process.c (rb_mProcGID, rb_mProcUid, rb_mProcID_Syscall): ditto * file.c (rb_mFConst): ditto * error.c (rb_mWarning, rb_cWarningBuffer): ditto * enumerator.c (rb_cLazy): ditto [Misc #14381] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-24process.c: add :exception option to Kernel.#systemk0kubun
to raise error when it fails. [Feature 14386] [GH-1795] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-19there is no guarantee that mode_t is as wide as intshyouhei
POSIX only defines mode_t to be "an integer typea", and in fact MacOS defines it to be uint16_t. We didn't have NUM2USHORT before so it did not make sense but now that we have it. Why not check apptopriately. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-18merge extern declarations into internal.hshyouhei
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-17process.c: get_clk_tck fallbacknobu
* process.c (get_clk_tck): prefer CLK_TCK over older HZ, next to _SC_CLK_TCK. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-17process.c: remove useless castnobu
* process.c (get_clk_tck): remove useless cast, implicitly cast to long again. * process.c (rb_proc_times): cast explicitly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09Include ruby/{io,encoding}.h before internal.hkazu
because of r61712 and r61713 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-14process.c: [DOC] fix grammar and double negativestomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61231 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-13process.c: adjust indentnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12[DOC] Process.last_status may return nilkazu
[ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12process.c: add Process.last_statusmrkn
* process.c (proc_s_last_status): add Process.last_status [ruby-core:83514] [Feature #14043] * test/ruby/test_process.rb (test_last_status): add a test case for Process.last_status. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-04hide internal data objectsnobu
* marshal.c (compat_allocator_table): hide the wrapper object of compat_allocator_tbl. * process.c (rb_execarg_new): hide wrapper objects of struct rb_execarg. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-26util.h: remove my_getcwdnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-14process.c: removed preserving_errnonobu
* process.c (try_with_sh, handle_fork_error): added argument for errno. * process.c (proc_exec_cmd, proc_exec_sh, exec_async_signal_safe): now return errno instead of -1. * process.c (rb_fork_ruby): merged retry_fork_ruby() and unified clean-up after fork regardless failure. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-06move rb_thread_t::interrupt_flag and maskko1
to rb_execution_context_t. * vm_core.h (rb_thread_t): move `rb_thread_t::interrupt_flag` and `rb_thread_t::interrupt_mask` to rb_execution_context_t. RUBY_VM_CHECK_INTS() accepts `ec` instead of `th`. * cont.c (rb_fiber_terminate): to propagate interrupt information, add new parameter `need_interrupt`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e