aboutsummaryrefslogtreecommitdiffstats
path: root/process.c
Commit message (Collapse)AuthorAgeFilesLines
...
* process.c: ensure th->interrupt lock is held when migratingnormal2018-08-061-6/+20
| | | | | | | w->cond may be changed without our knowledge in waitpid_nogvl without th->interrupt_lock git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* process.c (rb_waitpid): reduce sigwait_fd bouncingnormal2018-08-051-14/+19
| | | | | | | | Once a thread has acquired sigwait_fd, hold onto it until waitpid is complete. This prevents unnecessary migration and atomic operations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread: stop trying to deal with cancellationnormal2018-08-051-15/+0
| | | | | | | | | | | | | We don't use pthreads cancellation ourselves and it's painful to use correctly. Any cancelled threads would break vm->living_threads, GVL, thread_sync.c, autoload, etc... So don't bother caring; because we can't stop rogue extensions from completely breaking the VM in other ways, either. [ruby-core:88282] [Misc #14962] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* move #pragma out of functionsshyouhei2018-07-301-12/+10
| | | | | | | | gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18) reportedly fails to compile cf: https://rubyci.org/logs/rubyci.s3.amazonaws.com/centos6/ruby-trunk/log/20180726T093003Z.fail.html.gz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* reduce copy & pasteshyouhei2018-07-301-8/+6
| | | | | | | | | | | We see several occurrence of "diagnostic push/pop" so why not make them macros. Tested on GCC8 / Clang 6. Note that ruby.h is intentionally left untouched because we don't want to introduce new public macros. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* process.c (waitpid_nogvl): prevent conflicting use of sleep_condnormal2018-07-301-1/+17
| | | | | | | | | | We reuse sleep_cond for waitpid notifications as well as GVL waiting. So we must take care to not hold onto sleep_cond when we try to reacquire GVL. [ruby-core:88183] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread: remove timer-thread by restructuring GVLnormal2018-07-291-8/+95
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To reduce resource use and reduce CI failure; remove timer-thread. Single-threaded Ruby processes (including forked children) will never see extra thread overhead. This prevents glibc and jemalloc from going into multi-threaded mode and initializing locks or causing fragmentation via arena explosion. The GVL is implements its own wait-queue as a ccan/list to permit controlling wakeup order. Timeslice under contention is handled by a designated timer thread (similar to choosing a "patrol_thread" for current deadlock checking). There is only one self-pipe, now, as wakeups for timeslice are done independently using condition variables. This reduces FD pressure slightly. Signal handling is handled directly by a Ruby Thread (instead of timer-thread) by exposing signal self-pipe to callers of rb_thread_fd_select, native_sleep, rb_wait_for_single_fd, etc... Acquiring, using, and releasing the self-pipe is exposed via 4 new internal functions: 1) rb_sigwait_fd_get - exclusively acquire timer_thread_pipe.normal[0] 2) rb_sigwait_fd_sleep - sleep and wait for signal (and no other FDs) 3) rb_sigwait_fd_put - release acquired result from rb_sigwait_fd_get 4) rb_sigwait_fd_migrate - migrate signal handling to another thread after calling rb_sigwait_fd_put. rb_sigwait_fd_migrate is necessary for waitpid callers because only one thread can wait on self-pipe at a time, otherwise a deadlock will occur if threads fight over the self-pipe. TRAP_INTERRUPT_MASK is now set for the main thread directly in signal handler via rb_thread_wakeup_timer_thread. Originally, I wanted to use POSIX timers (timer_create/timer_settime) for this. Unfortunately, this proved unfeasible as Mutex#sleep resumes on spurious wakeups and test/thread/test_cv.rb::test_condvar_timed_wait failed. Using pthread_sigmask to mask out SIGVTALRM fixed that test, but test/fiddle/test_function.rb::test_nogvl_poll proved there'd be some unavoidable (and frequent) incompatibilities from that approach. Finally, this allows us to drop thread_destruct_lock and interrupt current ec directly. We don't need to rely on vm->thread_destruct_lock or a coherent vm->running_thread on any platform. Separate timer-thread for time slice and signal handling is relegated to thread_win32.c, now. [ruby-core:88088] [Misc #14937] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* process.c: conditionally used functionsnobu2018-07-261-0/+2
| | | | | | | * process.c (before_fork_ruby, after_fork_ruby): used only if fork() or daemon() is available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64065 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fork() is deprecated on Solarisnobu2018-07-261-0/+14
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Try to suppress warning on some CIkazu2018-07-241-1/+1
| | | | | | | | | | | | | | http://ci.rvm.jp/results/trunk-asserts-nopara@silicon-docker/1149270 ``` /home/ko1/ruby/src/trunk-asserts-nopara/process.c: In function 'assert_close_on_exec': /home/ko1/ruby/src/trunk-asserts-nopara/process.c:298:9: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result] (void)write(2, m, sizeof(m) - 1); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` workaround from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425#c34 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* UNREACHABLE_RETURNnobu2018-07-241-8/+8
| | | | | | | * include/ruby/ruby.h (UNREACHABLE_RETURN): UNREACHABLE at the end of non-void functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* process.c: adjust indent [ci skip]nobu2018-07-151-9/+9
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* process.c (assert_close_on_exec): quiet warning about unused resultnormal2018-07-131-1/+1
| | | | | | Not much we can do if writing to STDERR_FILENO fails. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* timer_thread: do not close pipes around forknormal2018-07-121-2/+20
| | | | | | | | | | | | | | | | | | | There's actually no need to close the pipes used by the sleepy timer thread before forking, only to stop the timer thread itself. Instead, we only close the parent pipes in the child process, either via close-on-exec flag or when reinitializing the timer thread. This change will be necessary when we allow rb_wait_for_single_fd and rb_thread_fd_select to wait on the timer_thread_pipe.normal[0] directly and eliminate timer thread. I don't anticipate compatibility problems with this change alone. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* signal.c: preserve trap(:CHLD, "IGNORE") behavior with SIGCHLDnormal2018-07-081-5/+25
| | | | | | | | | 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
* process.c (rb_f_exec): pause MJIT before replacing processnormal2018-07-071-0/+5
| | | | | | | | | | | | 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
* unrevert r63852 but keep SIGCHLD path disabled for win32normal2018-07-051-43/+244
| | | | | | | | | | | 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
* Revert r63758 and related commitsnaruse2018-07-041-244/+43
| | | | | | | 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
* process.c (waitpid_nogvl): start timer thread polling for lossy SIGCHLDnormal2018-07-021-0/+3
| | | | | | | | 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
* process.c: attempt to reap spawnvp (win32) result from mjitnormal2018-06-301-2/+14
| | | | | | | | 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
* use SIGCHLD_LOSSY to enable waitpid polling modenormal2018-06-301-1/+1
| | | | | | | | | 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
* process.c: handle errno correctly in non-SIGCHLD pathnormal2018-06-291-0/+2
| | | | | | | 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
* process.c (waitpid_nogvl): check interrupts before sleepingnormal2018-06-291-1/+5
| | | | | | | | | | 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
* process.c: fix typo in non-SIGCHLD waitpid :xnormal2018-06-291-1/+1
| | | | | | I expect this to fix [Bug #14873] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* use rb_pid_t instead of pid_tnobu2018-06-271-3/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* process.c (waitpid_wait): do not set ECHILD prematurelynormal2018-06-271-6/+0
| | | | | | | | | | | | 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
* s/pid_t/rb_pid_t/normal2018-06-271-1/+1
| | | | | | 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
* hijack SIGCHLD handler for internal usenormal2018-06-271-43/+229
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* process.c (ruby_fork_ruby): fix race in signal handlingnormal2018-06-241-1/+1
| | | | | | | | | | 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
* process.c (after_fork_ruby): make it a proper functionnormal2018-06-241-1/+6
| | | | | | | 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
* mjit.c: measure time more preciselynobu2018-06-161-3/+11
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* prefer clock_gettimenobu2018-06-141-2/+4
| | | | | | | | | | | * 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
* RSTRING_PTR is not guaranteed to be char*-alignedshyouhei2018-05-141-4/+6
| | | | | | | 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
* fix potential memory leaksnobu2018-05-091-5/+3
| | | | | | | | | | | | | * 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
* RSTRING_PTR is not guaranteed to be VALUE-alignedshyouhei2018-05-091-10/+14
| | | | | | | | | 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
* forgot to add INT2FIX (sorry!)shyouhei2018-05-041-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* passing rb_thread_sleep to rb_protect is IMHO dangerousshyouhei2018-05-041-1/+8
| | | | | | | | | | 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
* process.c: [DOC] fix grammarstomar2018-04-141-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* guard before noreturn functionnobu2018-02-251-3/+5
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* process.c: guard eargp against GCk0kubun2018-02-251-0/+1
| | | | | | | | | | | `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
* [DOC] missing docs at toplevelnobu2018-02-231-0/+7
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [DOC] obsolete classesnobu2018-02-231-1/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [DOC] nodoc internal methods/classesnobu2018-02-231-0/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* process.c: deprecated Struct::Tmsnobu2018-02-231-0/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62540 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* process.c (try_with_sh): fix the wrong number of argumentsmame2018-02-131-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* process.c: command_name encodingnobu2018-02-031-1/+3
| | | | | | | * 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
* process.c: split pst_message_status from pst_messagenobu2018-02-021-4/+11
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* process.c: reduce intermediate stringnobu2018-02-021-3/+4
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Use more verbose status in error messageskazu2018-02-021-3/+6
| | | | | | | 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
* ruby/ruby.h: remove unnecessary exports from C-APInormal2018-01-241-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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