Граф коммитов

949 Коммитов

Автор SHA1 Сообщение Дата
naruse df4a126d65 Revert r63758 and related commits
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-04 15:08:56 +00:00
normal ca37c5d41e process.c (waitpid_nogvl): start timer thread polling for lossy SIGCHLD
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-07-02 23:14:52 +00:00
normal 9eb6861502 process.c: attempt to reap spawnvp (win32) result from mjit
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-30 06:11:33 +00:00
normal ce2a3b40ed use SIGCHLD_LOSSY to enable waitpid polling mode
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-30 00:51:57 +00:00
normal be076acb51 process.c: handle errno correctly in non-SIGCHLD path
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-29 08:51:33 +00:00
normal 25b15f9441 process.c (waitpid_nogvl): check interrupts before sleeping
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-29 07:52:24 +00:00
normal 54394b3b71 process.c: fix typo in non-SIGCHLD waitpid :x
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-29 02:21:08 +00:00
nobu 797fb39f1e use rb_pid_t instead of pid_t
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-27 13:42:49 +00:00
normal 92f5653f45 process.c (waitpid_wait): do not set ECHILD prematurely
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-27 10:09:33 +00:00
normal ea5efa117f s/pid_t/rb_pid_t/
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-27 06:01:33 +00:00
normal 054a412d54 hijack SIGCHLD handler for internal use
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-27 03:14:30 +00:00
normal 4bbdb9ea19 process.c (ruby_fork_ruby): fix race in signal handling
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-24 12:36:44 +00:00
normal 5767162197 process.c (after_fork_ruby): make it a proper function
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-24 10:30:48 +00:00
nobu b701946418 mjit.c: measure time more precisely
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-16 23:22:42 +00:00
nobu a03ea378e7 prefer clock_gettime
* 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-06-14 13:10:25 +00:00
shyouhei 4f3c4c7d6d RSTRING_PTR is not guaranteed to be char*-aligned
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-14 03:30:03 +00:00
nobu 6e06d6440b fix potential memory leaks
* 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-09 17:40:04 +00:00
shyouhei a6108df948 RSTRING_PTR is not guaranteed to be VALUE-aligned
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-09 07:46:11 +00:00
shyouhei a99d017db7 forgot to add INT2FIX (sorry!)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-04 15:20:17 +00:00
shyouhei 1096be5ac6 passing rb_thread_sleep to rb_protect is IMHO dangerous
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-05-04 15:18:42 +00:00
stomar 15192b64e0 process.c: [DOC] fix grammar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-14 16:49:27 +00:00
nobu e110c0ddc5 guard before noreturn function
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-25 03:08:40 +00:00
k0kubun 71da3c50ef process.c: guard eargp against GC
`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-25 02:12:25 +00:00
nobu 96db72ce38 [DOC] missing docs at toplevel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23 02:18:52 +00:00
nobu b9d01e2257 [DOC] obsolete classes
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23 02:16:43 +00:00
nobu 16ef24ac08 [DOC] nodoc internal methods/classes
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23 02:16:42 +00:00
nobu 44c53ee473 process.c: deprecated Struct::Tms
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62540 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23 02:16:41 +00:00
mame 9b96817b94 process.c (try_with_sh): fix the wrong number of arguments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-13 07:42:51 +00:00
nobu 28490dd1fd process.c: command_name encoding
* 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-03 03:50:28 +00:00
nobu 2cbb6fa218 process.c: split pst_message_status from pst_message
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-02 16:14:21 +00:00
nobu 228bffe5e1 process.c: reduce intermediate string
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-02 16:10:17 +00:00
kazu 1659a1660c Use more verbose status in error messages
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-02-02 11:03:22 +00:00
normal 7e669f40be ruby/ruby.h: remove unnecessary exports from C-API
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-24 21:07:14 +00:00
k0kubun fb29cffab0 process.c: add :exception option to Kernel.#system
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-24 14:11:25 +00:00
shyouhei de9d264026 there is no guarantee that mode_t is as wide as int
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-19 09:12:06 +00:00
shyouhei 449cceb8b1 merge extern declarations into internal.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-18 09:44:36 +00:00
nobu e9f77725d2 process.c: get_clk_tck fallback
* 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-17 11:22:14 +00:00
nobu 9a952626f1 process.c: remove useless cast
* 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-17 11:16:24 +00:00
kazu 51edb30042 Include ruby/{io,encoding}.h before internal.h
because of r61712 and r61713

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 12:35:12 +00:00
stomar 09004db450 process.c: [DOC] fix grammar and double negative
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61231 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-14 10:24:38 +00:00
nobu b81ac5150a process.c: adjust indent
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-13 10:16:05 +00:00
kazu b9253be504 [DOC] Process.last_status may return nil
[ci skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12 15:01:02 +00:00
mrkn 8624cec9d3 process.c: add Process.last_status
* 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-12 09:00:17 +00:00
nobu 340fe20a3b hide internal data objects
* 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-12-04 07:37:21 +00:00
nobu cea5a91163 util.h: remove my_getcwd
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-26 01:36:33 +00:00
nobu fe3decb201 process.c: removed preserving_errno
* 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-14 04:42:38 +00:00
ko1 5dfdaa9299 move rb_thread_t::interrupt_flag and mask
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
2017-11-06 07:44:28 +00:00
ko1 a93c650312 `rb_ec_error_print()`.
* eval_error.c (rb_threadptr_error_print): renamed to
  rb_ec_error_print() and it accepts `ec`.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-29 14:06:58 +00:00
ko1 f56288d7a8 replace `GET_THREAD()->ec` to `GET_EC()`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26 14:44:09 +00:00
ko1 837fd5e494 Use rb_execution_context_t instead of rb_thread_t
to represent execution context [Feature #14038]

* vm_core.h (rb_thread_t): rb_thread_t::ec is now a pointer.
  There are many code using `th` to represent execution context
  (such as cfp, VM stack and so on). To access `ec`, they need to
  use `th->ec->...` (adding one indirection) so that we need to
  replace them by passing `ec` instead of `th`.

* vm_core.h (GET_EC()): introduced to access current ec. Also
  remove `ruby_current_thread` global variable.

* cont.c (rb_context_t): introduce rb_context_t::thread_ptr instead of
  rb_context_t::thread_value.

* cont.c (ec_set_vm_stack): added to update vm_stack explicitly.

* cont.c (ec_switch): added to switch ec explicitly.

* cont.c (rb_fiber_close): added to terminate fibers explicitly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26 08:32:49 +00:00
nobu 6b818dd961 common conversion functions
* array.c (rb_to_array_type): make public to share common code
  internally.

* hash.c (rb_to_hash_type): make public to share common code
  internally.

* symbol.c (rb_to_symbol_type): make public to share common code
  internally.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26 07:23:23 +00:00
hsbt 0e2d2e6a79 Drop to support NaCl platform.
Because NaCl and PNaCl are already sunset status.
  see https://bugs.chromium.org/p/chromium/issues/detail?id=239656#c160

  configure.ac: Patch for this file was provided by @nobu.

  [Feature #14041][ruby-core:83497][fix GH-1726]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23 05:56:25 +00:00
nobu 0c551b7a6d process.c: null byte at initgroups
* process.c (proc_initgroups): check null byte.  patched by
  tommy (Masahiro Tomita) in [ruby-dev:50287].  [Bug #13995]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60161 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-11 06:16:03 +00:00
normal 5be3869221 process: block/unblock signals around fork
As with forking for execve(2) in `spawn', we must block signals
to ensure they are handled correctly in a freshly `fork'-ed child.

* process.c (retry_fork_ruby): block/unblock signals around fork
  (rb_fork_ruby): re-enable signals in forked child
* test/ruby/test_process.rb (test_forked_child_signal): new test
  [ruby-core:82883] [Bug #13916]

  Thanks to Russell Davis for the bug report and test case.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-20 18:47:14 +00:00
nobu b823ecc34e adjust indent
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-19 23:09:10 +00:00
nobu 1e84c8343f process.c: null bytes
* process.c (rlimit_type_by_sym): prohibit null bytes in key
  names.  [ruby-core:82033] [Bug #13744]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59325 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-14 04:43:16 +00:00
normal 5c4db58b12 process.c: handle dynamic :rlimit_* symbols in spawn execopts
* process.c (rb_execarg_addopt_rlimit): hoist out of rb_execarg_addopt
  (rlimit_type_by_sym): new wrapper for dynamic symbol
  (rb_execarg_addopt): check for dsym via rlimit_type_by_sym
* test/ruby/test_process.rb (test_execopts_rlimit): check dsym w/o pindown
  Add extra check for bogus rlimit args, too.
  [ruby-core:82033] [Bug #13744]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-13 20:47:36 +00:00
ko1 8dd9c12c58 move fields to ec.
* vm_core.h (rb_thread.h): move errinfo and trace_arg to
  rb_execution_context_t.

* cont.c (fiber_switch, rb_cont_call): do not restore "trace_arg" here.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-28 14:27:49 +00:00
ko1 1939d097e6 move several fields from rb_thread_t to rb_execution_context_t.
* vm_core.h (rb_thread_t): move several fields which are copied at cont.c
  to rb_execution_context_t.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-26 07:56:44 +00:00
nobu aea98ff0d5 removed ruby_error_print
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-16 01:53:15 +00:00
watson1978 d0015e4ac6 Improve performance of implicit type conversion
To convert the object implicitly, it has had two parts in convert_type() which are
  1. lookink up the method's id
  2. calling the method

Seems that strncmp() and strcmp() in convert_type() are slightly heavy to look up
the method's id for type conversion.

This patch will add and use internal APIs (rb_convert_type_with_id, rb_check_convert_type_with_id)
to call the method without looking up the method's id when convert the object.

Array#flatten -> 19 % up
Array#+       ->  3 % up

[ruby-dev:50024] [Bug #13341] [Fix GH-1537]

### Before
       Array#flatten    104.119k (± 1.1%) i/s -    525.690k in   5.049517s
             Array#+      1.993M (± 1.8%) i/s -     10.010M in   5.024258s

### After
       Array#flatten    124.005k (± 1.0%) i/s -    624.240k in   5.034477s
             Array#+      2.058M (± 4.8%) i/s -     10.302M in   5.019328s

### Test Code
require 'benchmark/ips'

class Foo
  def to_ary
    [1,2,3]
  end
end

Benchmark.ips do |x|

  ary = []
  100.times { |i| ary << i }
  array = [ary]

  x.report "Array#flatten" do |i|
    i.times { array.flatten }
  end

  x.report "Array#+" do |i|
    obj = Foo.new
    i.times { array + obj }
  end

end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-31 12:30:57 +00:00
k0kubun 253232c028 process.c: Use getrusage(2) in Process.times
if getrusage(2) is available, to improve precision of Process.times and
its user like lib/benchmark.rb.

On macOS, since getrusage(2) has better precision than times(3),
they are much improved like:

* Before

Process.times
=> #<struct Process::Tms utime=0.56, stime=0.35, cutime=0.04, cstime=0.03>

puts Benchmark.measure { "a" * 1_000_000_000 }
  0.340000   0.310000   0.650000 (  0.674025)

* After

Process.times
=> #<struct Process::Tms utime=0.561899, stime=0.35076, cutime=0.046483, cstime=0.038929>

puts Benchmark.measure { "a" * 1_000_000_000 }
  0.343223   0.310037   0.653260 (  0.674025)

On Linux, since struct rusage from getrusage(2) is used instead of struct tms
from times(2), they are slightly improved like:

* Before

Process.times
=> #<struct Process::Tms utime=0.43, stime=0.11, cutime=0.0, cstime=0.0>

puts Benchmark.measure { "a" * 1_000_000_000 }
  0.120000   0.040000   0.170000 (  0.171621)

* After

Process.times
=> #<struct Process::Tms utime=0.432, stime=0.116, cutime=0.0, cstime=0.0>

puts Benchmark.measure { "a" * 1_000_000_000 }
  0.124000   0.048000   0.172000 (  0.171621)

[ruby-dev:49471] [Feature #11952]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-28 01:48:11 +00:00
nobu cb302650a0 process.c: fix error check
* process.c (obj2uid, obj2gid): check the error number returned by
  `getpwnam_r()` and `getgrnam_r()`, instead of `errno`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-11 02:38:09 +00:00
nobu 8f9a46a304 .
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-10 23:34:33 +00:00
nobu ec70309ffa process.c: temporary string for buffer
* process.c (obj2uid, obj2gid): use temporary string as the buffer
  instead of `rb_alloc_tmp_buffer`, which is `NODE_ALLOCA` since
  r51492.  [ruby-core:81084] [Bug #13554]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-10 23:18:07 +00:00
sorah af4b7c8e86 Add documents on Process::CLOCK_* constants
* process.c: Add documents on Process::CLOCK_* constants.
  Patch by Sunao Komuro <sunao-komuro@cookpad.com>.
  Closes [GH-1567] [Bug #13386]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-29 09:31:13 +00:00
shyouhei 3106f9412a use HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW
We already check for __builtin_mul_overflow in configure but never
actually referred it before.  Why not call it if available, because
that should render supposedly-optimial assembly outputs.

Optionally if __builtin_mul_overflow_p is available, which is the case
for recent GCC, use that to detect fixnum overflow.  This is much
faster than the previous.  On my machine generated assembly of
numeric.c:int_pow reduces from 480 to 448 bytes, according to nm(1).
Also on my machine, following script boosts from 7.819 to 6.929 sec.

time ./miniruby -e 'i=0; while i < 30_000_000 do i += 1; 7 ** 23; end'

Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org>


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-06 06:04:52 +00:00
nobu 4b7fd61a05 process.c: PATH env in spawn
* process.c (rb_exec_fillarg): honor the given path environment
  variable.  [ruby-core:53103] [Bug #8004]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56618 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-06 00:58:49 +00:00
nobu 4e44f6ef86 [DOC] replace Fixnum with Integer [ci skip]
* numeric.c: [DOC] update document for Integer class.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-26 06:11:23 +00:00
nobu 5d4309d068 process.c: use uaspawn
* process.c (proc_exec_cmd): use UTF-8 version aspawn.
  [ruby-dev:49838] [Bug #12841]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-14 15:54:03 +00:00
nobu 0cc169d1de fid typos [ci skip]
* fix typos, "a" before "Integer" to "an".  [Fix GH-1438]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-24 02:28:25 +00:00
naruse fdaea1596a * process.c (InitVM_process): Support CLOCK_MONOTONIC_RAW_APPROX,
CLOCK_UPTIME_RAW, and CLOCK_UPTIME_RAW_APPROX which are introduced
  by macOS 10.12.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-21 08:46:06 +00:00
akr 577de1e93d replace fixnum by integer in documents.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-08 04:57:49 +00:00
ko1 9f60791a04 * vm_core.h: revisit the structure of frame, block and env.
[Bug #12628]

  This patch introduce many changes.

  * Introduce concept of "Block Handler (BH)" to represent
    passed blocks.

  * move rb_control_frame_t::flag to ep[0] (as a special local
    variable). This flags represents not only frame type, but also
    env flags such as escaped.

  * rename `rb_block_t` to `struct rb_block`.

  * Make Proc, Binding and RubyVM::Env objects wb-protected.

  Check [Bug #12628] for more details.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-28 11:02:30 +00:00
naruse c73eb62b3f fix typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-04 07:05:00 +00:00
naruse 37c32dc6d1 * process.c: define sig_t if not exist.
at least Solaris 10 and 11 doesn't have sig_t.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-04 04:57:27 +00:00
normal 80a0c0f808 process.c (disable_child_handler_fork_child): simplify
signal(2) is portable for SIG_DFL and SIG_IGN, so we do not
need the extra code for sigaction(2).

Also, execve will reset all signal handlers to default
anyways, so there is little sense in preserving old
signal handler besides SIG_IGN.

Hopefully this makes the code easier-to-understand and
maintain.

* process.c (disable_child_handler_fork_child): simplify
  [ruby-core:75781] [Misc #12439]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55566 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-02 21:13:26 +00:00
nobu 294f653163 process.c: [DOC] Process.abort [ci skip]
* process.c (rb_f_abort): [DOC] Process.abort is a singleton
  method of Process, but not an instance method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-27 11:43:23 +00:00
nobu aa107497cd fix build on no-fork-spawnv platforms
* process.c (rb_execarg_commandline): build command line string
  from argument vector in rb_execarg.
  [ruby-core:75611] [Bug #12398]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-20 15:36:34 +00:00
naruse 28f5e12c24 * configure.in: check function attirbute const and pure,
and define CONSTFUNC and PUREFUNC if available.
  Note that I don't add those options as default because
  it still shows many false-positive (it seems not to consider
  longjmp).

* vm_eval.c (stack_check): get rb_thread_t* as an argument
  to avoid duplicate call of GET_THREAD().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-08 17:44:51 +00:00
naruse a6c8e8d15b * configure.in: add -Wsuggest-attribute=noreturn and suppress warnings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-08 00:55:28 +00:00
nobu 48ed66868c process.c: argument types over conversion
* process.c (rb_exec_getargs): honor the expected argument types
  over the conversion method.  the basic language functionality
  should be robust.  [ruby-core:75388] [Bug #12355]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54934 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-06 22:58:03 +00:00
normal ebfb401e77 process.c (disable_child_handler_fork_child): initialize handler for SIGPIPE
This only happens on the !POSIX_SIGNAL case; but one may
test with the following:

    --- a/process.c
    +++ b/process.c
    @@ -3479,6 +3479,7 @@ disable_child_handler_fork_parent(struct child_handler_disabler_state *old)
     #endif
     }

    +#undef POSIX_SIGNAL
     /* This function should be async-signal-safe.  Actually it is. */
     static int
     disable_child_handler_fork_child(struct child_handler_disabler_state *old, char *errmsg, size_t errmsg_buflen)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54890 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-02 21:04:17 +00:00
nobu 24eb2e9cfe process.c: prefer rb_check_arity
* process.c: use rb_check_arity instead of rb_scan_args for simple
  optional arguments.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-14 04:41:47 +00:00
usa 8ff043d8cb * process.c (rb_execarg_parent_start1): need to convert the encoding to
ospath's one.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-27 12:15:20 +00:00
usa 956100bc2e * process.c (rb_execarg_addopt): need to convert to ospath.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-27 12:03:45 +00:00
usa fe0194e25e * process.c: use rb_w32_uchdir() instead of plain chdir() on Windows.
reported by naruse via twitter.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53346 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-27 11:54:59 +00:00
nobu f4166e2dd7 prefer rb_syserr_fail
* file.c, io.c, util.c: prefer rb_syserr_fail with saved errno
  over setting errno then call rb_sys_fail, not to be clobbered
  potentially and to reduce thread local errno accesses.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53264 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-23 08:57:48 +00:00
hsbt 52cd994814 * enum.c: fix a typo in documentation.
[ci skip][fix GH-1140] Patch by @jutaz
* io.c: ditto.
* iseq.c: ditto.
* numeric.c: ditto.
* process.c: ditto.
* string.c: ditto.
* vm_trace.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53105 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-14 02:52:14 +00:00
nobu f604375832 process.c: fix rdoc of Process.getsid [ci skip]
* process.c (proc_getsid): [DOC] Fix double word 'for' and typo.
  [Fix GH-1080]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-04 02:38:25 +00:00
kosaki 4ad2057f27 * ChangeLog: Good-bye OS/2.
* common.mk: ditto.
* configure.in: ditto.
* dln_find.c: ditto.
* ext/Setup.emx: ditto.
* ext/extmk.rb: ditto.
* ext/socket/extconf.rb: ditto.
* ext/zlib/extconf.rb: ditto.
* file.c: ditto.
* include/ruby/defines.h: ditto.
* io.c: ditto.
* lib/mkmf.rb: ditto.
* missing/os2.c: ditto.
* process.c: ditto.
* ruby.c: ditto.
* NEWS: announce OS/2 is no longer supported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52161 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18 01:18:34 +00:00
nobu 09cbe9d640 process.c: do not inherit saved fds
* process.c (save_redirect_fd): make saved FDs close-on-exec not
  to be inherited.
* process.c (run_exec_dup2): restore close-on-exec flags too.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51832 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-12 05:30:05 +00:00
nobu 9fb0863f4f Clarify spawn pgroup documentation [ci skip]
* process.c (rb_f_spawn): Be more specific regarding "other
  values" by having "non-zero positive integers" Add nil, the
  default value, as a possible value and what it means.
  Try to use more consistent language.
  [Fix GH-1008]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-10 13:15:55 +00:00
nobu d3022c424c process.c: keep GVL if WNOHANG
* process.c (rb_waitpid): do not release GVL when WNOHANG is set,
  it should return immediately without blocking.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51793 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-08 07:15:09 +00:00
nobu 2a87a0fc73 process.c: retry loop
* process.c (rb_waitpid): refactor retry loop by interrupt.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-08 07:00:13 +00:00
nobu cfecd21a89 process.c: open exception message
* process.c (rb_execarg_parent_start1): raise with the target path
  name when open() failed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51787 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-07 15:14:46 +00:00
nobu be3de529c2 process.c: chdir exception message
* process.c (rb_exec_fail): raise with the target directory name
  when chdir() failed.  pointed out by sorah.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-07 14:45:31 +00:00
nobu d2f4d5a5fe Fix typo in Process.detatch doc [ci skip]
* process.c (proc_detach): [DOC] fix typo "intent" as "intend" in
  rdoc.  [Fix GH-1011]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-02 08:18:39 +00:00
nobu c670b75ec2 process.c: [DOC] env values in spawn [ci skip]
* process.c (rb_f_spawn): [DOC] elaborate environment variable
  values.  [ruby-core:70456] [Bug #11463]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51641 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-19 14:55:32 +00:00
normal f224fecc0f improve handling of timer thread shutdown
Shutting down the timer thread now always closes pipes to free FDs.
In fact, we close the write ends of the pipes is done in the main
RubyVM to signal the timer thread shutdown.

To effectively close pipes, we implement userspace locks via
atomics to force the pipe closing thread to wait on any signal
handlers which may be waking up.

While we're at it, improve robustness during resource exhaustion and
allow it to limp along non-fatally if restarting a timer thread
fails.

This reverts r51268

Note: this change is tested with VM_CHECK_MODE 1 in vm_core.h

* process.c (close_unless_reserved): add extra check
  (dup2_with_divert): remove
  (redirect_dup2): use dup2 without divert
  (before_exec_non_async_signal_safe): adjust call + comment
  (rb_f_exec): stop timer thread for all OSes
  (rb_exec_without_timer_thread): remove
* eval.c (ruby_cleanup): adjust call
* thread.c (rb_thread_stop_timer_thread): always close pipes
* thread_pthread.c (struct timer_thread_pipe): add writing field,
    mark owner_process volatile for signal handlers
  (rb_thread_wakeup_timer_thread_fd): check valid FD
  (rb_thread_wakeup_timer_thread): set writing flag to prevent close
  (rb_thread_wakeup_timer_thread_low): ditto
  (CLOSE_INVALIDATE): new macro
  (close_invalidate): new function
  (close_communication_pipe): removed
  (setup_communication_pipe_internal): make errors non-fatal
  (setup_communication_pipe): ditto
  (thread_timer): close reading ends inside timer thread
  (rb_thread_create_timer_thread): make errors non-fatal
  (native_stop_timer_thread): close write ends only, always,
   wait for signal handlers to finish
  (rb_divert_reserved_fd): remove
* thread_win32.c (native_stop_timer_thread): adjust (untested)
  (rb_divert_reserved_fd): remove
* vm_core.h: adjust prototype

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-14 09:44:10 +00:00
nobu 46b39cb0ba revert r31760 and r31761
seems that rb_bug_errno() is called in sigpipe() intentionally.
https://gist.github.com/sorah/831169

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-26 05:37:59 +00:00
normal 4fd2443580 avoid redundant GET_THREAD() calls
This reduces binary size slightly on my 32-bit system:

   text    data     bss     dec     hex filename
2847705   12360   30632 2890697  2c1bc9 ruby.orig
2847641   12360   30632 2890633  2c1b89 ruby

* iseq.c (rb_iseq_compile_with_option): reuse result of previous
  GET_THREAD() call
* thread.c (thread_create_core): ditto
  (rb_mutex_trylock): ditto
  (rb_mutex_lock): ditto
* process.c (rb_waitpid): avoid multiple eval from RUBY_VM_CHECK_INTS
* thread.c (rb_thread_check_ints): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51273 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-16 20:42:43 +00:00
ngoto f242e17f9b * process.c (redirect_dup2): when the new FD of dup2() coflicts
with one of the timer thread FDs, the internal FD is diverted.
  [Bug #11336] [ruby-core:69886] [Bug #11350] [ruby-core:69961]
    
* process.c (dup2_with_divert): new function for the above purpose.
   
* thread_pthread.c (rb_divert_reserved_fd): new function for
  diverting reserved FD. If the given FD is the same as one of the
  reserved FDs, the reserved FD number is internally changed.
  It returns -1 when error. Otherwise, returns 0. It also returns
  0 if there is no need to change reserved FD number.

* thread_win32.c (rb_divert_reserved_fd): always returns 0 because
  of no reserved FDs.

* internal.h (rb_divert_reserved_fd): prototype declaration.
  It is Ruby internal use only.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-16 13:06:13 +00:00
ngoto db2fe4b8ef Revert r51209 because signals after stopping timer thread before
entering exec(2) system call may be lost.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51265 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-16 12:08:56 +00:00
normal e981a61c53 process.c (close_unless_reserved): declare type of `fd' arg
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-16 02:39:30 +00:00
ngoto d1bce9ec55 * process.c (redirect_close, parent_redirect_close): should not close
reserved FD. It should be closed in the exec system call due to the
  O_CLOEXEC or FD_CLOEXEC flag. [Bug #11353] [ruby-core:69977]
    
* process.c (close_unless_reserved): new function to close FD unless
  it is reserved for internal communication.
      
* thread_pthread.c (rb_reserved_fd_p): should check owner_process pid
  to avoid false positive in forked child process.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-15 14:26:22 +00:00
ngoto 4d23a784f5 * process.c (rb_f_exec): rb_exec_without_timer_thread should be
used on every OS, not only on Mac OS X or Haiku, to prevent
  timer thread communications using file descriptor 3 after
  setting redirection of the fd 3 before calling exec.
  [Bug #11336] [ruby-core:69886]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51209 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-10 11:27:43 +00:00
ngoto f59356a85a * process.c (rb_execarg_parent_start1): new macro ALWAYS_NEED_ENVP
to generate envp_str anytime on Solaris 10 (or earlier version
  of Solaris) to avoid calling execv() which is async-signal unsafe
  on Solaris 10. [Bug #11265] [ruby-dev:49089]
      
* process.c (exec_with_sh, proc_exec_cmd): On Solaris 10,
  because ALWAYS_NEED_ENVP is 1 and envp_str is always generated,
  execv() in exec_with_sh() and proc_exec_cmd() are never called.
  To guarantee this, execv() is replaced by a macro to print
  out error message on Solaris 10.
	      
* process.c (proc_exec_sh): Because proc_exec_sh() may be called
  by rb_proc_exec() with envp_str = Qfalse, execl() is replaced
  by a macro that calls execle() with "extern char **environ"
  traditional global variable on Solaris 10.
  TODO: This may be unsafe and sholud be changed
  in the future.
  Although rb_proc_exec() is not used from inside current version
  of ruby, it may be called by third-party extensions.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-19 17:49:27 +00:00
hsbt 5d6ca9e950 * include/ruby/ruby.h: $SAFE=2 is now obsolete.
* dir.c, ext/fiddle/handle.c, ext/socket/basicsocket.c, file.c
  gc.c, io.c, process.c, safe.c, signal.c, win32/file.c:
  removed code for $SAFE=2
* test/erb/test_erb.rb, test/fiddle/test_handle.rb
  test/ruby/test_env.rb: removed tests for $SAFE=2.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-18 14:21:03 +00:00
nobu 46c64caff6 process.c: do not discard status
* process.c (rb_spawn_process): do not discard global escape
  status.  [ruby-core:69304] [Bug #11166]
* process.c (rb_execarg_spawn): extract the start procedure in a
  parent process with ensuring the end procedure.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50600 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-22 10:42:09 +00:00
nobu d1fb37bca8 process.c: initgroups on cygwin
* process.c (initgroups): not declared on cygwin if _POSIX_SOURCE
  or _XOPEN_SOURCE are defined.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-14 02:25:02 +00:00
akr ff381ca19b * process.c (rb_execarg_parent_start1): Handle EINTR.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-10 09:45:29 +00:00
akr ce28a7539d * process.c: Release GVL when opening a file in spawn() to avoid whole
process blocking when opening a named pipe.
  (open_func): New function.
  (rb_execarg_parent_start1): Extracted from rb_execarg_parent_start and
  use rb_thread_call_without_gvl2 to release GVL when opening a file.
  (rb_execarg_parent_start): Invoke rb_execarg_parent_start1 via
  rb_protect and invoke rb_execarg_parent_end when error.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-09 16:33:02 +00:00
akr 6cf4e97b3e move debug functions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-09 14:23:42 +00:00
akr 3bf92fb10d * process.c (redirect_open): Removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-09 13:19:47 +00:00
akr f6b1dd28c9 * internal.h (rb_execarg_parent_end): Declared.
* process.c: "spawn" opens files in the parent process.
  (check_exec_redirect): Add an placeholder for fd in parameters
  for fd_open.
  (check_exec_fds_1): Delete fd_open condition.
  (check_exec_fds): Don't call check_exec_fds_1 with fd_open.
  (rb_execarg_parent_start): Open files specified as "spawn" options
  and add "dup2" options.
  (rb_execarg_parent_end): New function to close opened fds.
  (run_exec_open): Removed.
  (rb_execarg_run_options): Don't call run_exec_open.
  (rb_spawn_internal): Call rb_execarg_parent_end.

* io.c (pipe_open): Call rb_execarg_parent_end.

* ext/pty/pty.c (establishShell): Call rb_execarg_parent_end.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50194 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-09 12:44:35 +00:00
akr 9960558337 * internal.h (rb_execarg_parent_start): Renamed from rb_execarg_fixup.
* process.c: Follows the above change.

* io.c: Ditto.

* ext/pty/pty.c: Ditto.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-09 11:53:49 +00:00
akr 00478a98ac * process.c (fd_clear_cloexec): Extracted from run_exec_dup2.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-09 11:35:52 +00:00
nobu 0d20fbe3bd eval.c: static IDs
* eval.c (ruby_static_id_signo, ruby_static_id_status): add static
  IDs, signo and status.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-23 07:05:30 +00:00
nobu 802d71a57e [DOC] ENV keys must be strings [ci skip]
* hash.c (env_aset): state that ENV keys must be strings.

* process.c (rb_f_spawn): ditto.  [ruby-core:68146] [Bug #10859]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-18 02:42:58 +00:00
nobu 76ec09062a process.c: missing parenthesis
* process.c (proc_detach): [DOC] fix missing closing parenthesis.
  [Fix GH-799]  [ci skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-29 01:37:07 +00:00
akr 81e9d9799a * process.c: Unused code removed.
It seems waitpid() is universaly available on POSIX platforms.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-27 08:03:29 +00:00
nobu 1db0393eb1 uninitialized variable
* process.c (rb_spawn_process): get rid of usage of uninitialized
  variable.
  reported by Denis Denisov <denji0k AT gmail.com>.
* regexec.c (match_at): ditto.
* ext/win32ole/win32ole.c (ole_wc2mb_alloc, ole_vstr2wc, ole_mb2wc):
  ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-26 06:09:11 +00:00
nobu 7307c32f1f process.c: unused variables
* process.c (rb_fork_async_signal_safe): remove initialized but
  never assigned local variables.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-11 03:02:36 +00:00
nobu e580a631be use 0 for reserved
use 0 for rb_data_type_t::reserved instead of NULL, since its type
may be changed in the future and possibly not a pointer type.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-01 06:38:04 +00:00
nobu 63aafb2004 process.c: initialize static IDs first
* process.c (Init_process): initialize static IDs before constant
  definitions.  [ruby-core:66445]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-25 03:14:45 +00:00
nobu 09fbd56e6f process.c: get rid of inadvertent ID pindown
* process.c (check_exec_redirect_fd, check_exec_redirect),
  (rb_execarg_addopt): get rid of inadvertent ID pindown.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48552 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-24 03:44:45 +00:00
nobu a6755b6e5f process.c: intern IDs
* process.c (Init_process): intern IDs at initialization.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-24 03:44:24 +00:00
akr 7cd76ab0c5 * internal.h: Include ruby.h and ruby/encoding.h to be
includable without prior inclusion.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-15 11:49:06 +00:00
yugui 57bc5eaf2f 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
2014-10-11 13:33:14 +00:00
nobu 28b9f11d5a protoize no-arguments functions
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-30 05:25:32 +00:00
normal d198d64e04 trivial packing for on-stack structs
* io.c (struct io_advise_struct): 32 => 24 bytes on 64-bit
* io.c (struct io_internal_writev_struct): 24 => 16 bytes on 64-bit
* process.c (struct waitpid_arg): ditto

Slightly reduce stack pressure.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-15 07:31:38 +00:00
normal d2e3c03409 simplify some trivial rb_data_type_t callbacks
* process.c (free_exec_arg): remove
  (memsize_exec_arg): ptr is never NULL
  (exec_arg_data_type): use RUBY_TYPED_DEFAULT_FREE

* variable.c (autoload_i_free): remove
  (autoload_data_i_type): use RUBY_TYPED_DEFAULT_FREE
  (autoload_memsize): ptr is never NULL

* vm_backtrace.c (location_free): remove
  (location_mark): ptr is never NULL
  (location_data_type): use RUBY_TYPED_DEFAULT_FREE
  (backtrace_mark): ditto
  (backtrace_free): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-13 05:14:51 +00:00
normal afa512d9e1 Process.detach: avoid singleton class creation
* process.c (Init_process): subclass Thread as Process::Waiter
  (rb_detach_process): use Process::Waiter instead of singleton class

* test/ruby/test_process.rb (test_process_detach): new test

* inits.c (rb_call_inits): call Init_Thread before Init_process to
  ensure Process::Waiter may be a subclass of Thread

Thanks to headius for reporting [Bug #10231]
Thanks to nobu for review of my initial patch.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-12 19:42:01 +00:00
akr e6368921ea * process.c: PTHREAD_CANCEL_DISABLE is not defined on Android.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-07 03:47:47 +00:00
nobu ed0a7d4627 process.c: disable vfork on OS X
* process.c (retry_fork_async_signal_safe): revert r47439 but
  disable use of vfork on OS X instead, as it cause hang-up at
  test_process.rb:test_deadlock_by_signal_at_forking with parallel
  test.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-07 01:57:44 +00:00
nobu e81a0d8f36 process.c: vfork may not work with pthread
* process.c (retry_fork_async_signal_safe): vfork may not work
  with pthread always even if fork works with it.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-07 01:10:43 +00:00
akr 11a8187bd1 * process.c (has_privilege): The gid zero is not a privilege.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-06 12:08:02 +00:00
akr 42becbddc2 * process.c (struct child_handler_disabler_state): cancelstate field
added.
  (disable_child_handler_before_fork): Record cancelstate.
  (disable_child_handler_fork_parent): Restore cancelstate.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47437 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-06 11:20:08 +00:00
akr 3de392def9 * process.c (struct child_handler_disabler_state): Defined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47436 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-06 10:27:54 +00:00
nobu c54e8cabe8 process.c: missing semicolon
* process.c (rb_exec_without_timer_thread): add missing semicolon
  to fix compilation error on OS X and Haiku.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-05 23:45:11 +00:00
akr 3146827521 * process.c (rb_f_exec): Call before_exec_async_signal_safe and
after_exec_async_signal_safe around rb_exec_async_signal_safe.
  (rb_exec_async_signal_safe): Don't call
  before_exec_async_signal_safe and after_exec_async_signal_safe.
  (rb_exec_without_timer_thread): Call before_exec and
  after_exec.
  (disable_child_handler_fork_child): Make SIGPIPE handler SIG_DFL.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-05 16:36:35 +00:00
akr 2942657a56 Unwrap a useless block.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-05 16:10:16 +00:00
akr 0610a859d9 * process.c (disable_child_handler_before_fork): New function.
(disable_child_handler_fork_parent): Ditto.
  (disable_child_handler_fork_child): Ditto.
  (retry_fork_async_signal_safe): Call above functions to disable
  signal handlers in child process.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47412 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-05 12:46:09 +00:00
akr 01689aa9b1 * process.c (handle_fork_error): Make try_gc_p argument volatile to
suppress "clobbered" warning.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47411 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-05 12:03:54 +00:00
akr 5e42cc3085 * process.c (handle_fork_error): Don't need state_p argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-05 11:49:04 +00:00
akr 4eed59e667 * process.c (has_privilege): Fix a return value.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-05 11:36:19 +00:00
akr 192c39532b * process.c (has_privilege): Refine uid/gid check.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-05 03:58:42 +00:00
akr 82d85fe441 * configure.in: Check sys/id.h, getuidx and getgidx for AIX.
* process.c (getresuid): Defined for AIX.
  (getresgid): Ditto
  AIX don't have getresuid/getresgid but getuidx/getgidx.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-05 03:43:28 +00:00
akr 2cf2d7ee20 * process.c (has_privilege): Fix assignements.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-05 03:28:53 +00:00
akr f20d51b0ad * process.c (has_privilege): New function.
(retry_fork_async_signal_safe): Don't use vfork() for privileged
  process.

* configure.in (getresuid): Check function.
  (getresgid): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47386 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-04 14:56:03 +00:00
akr 777d61faf4 * process.c (before_fork_ruby): Renamed from before_fork.
(after_fork_ruby): Renamed from after_fork.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-03 10:23:24 +00:00
akr ed0f2528e8 * process.c (forked_child): Removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-03 09:56:38 +00:00
akr 9b16f90692 * process.c (retry_fork_async_signal_safe): Use vfork() if available.
vfork() is still faster than fork() especially when the parent
  process uses big memory.

  ruby -rbenchmark -e 'a = "a" * 1_000_000_000; puts Benchmark.measure { system("true") }'
  fork:   0.000000   0.010000   0.010000 (  0.014968)
  vfork:  0.000000   0.000000   0.000000 (  0.000912)
  on Debian sid.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-03 03:06:17 +00:00
akr 93a7bf4b17 * configure.in: Use AC_FUNC_FORK.
* io.c: Use HAVE_WORKING_FORK instead of HAVE_FORK.

* process.c: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-02 22:51:03 +00:00
akr 34af76e318 * process.c (retry_fork_async_signal_safe): Don't return on in child
process.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-02 15:13:36 +00:00
akr 93621161d6 * process.c (retry_fork_async_signal_safe): Specialized version of
retry_fork respect to rb_fork_async_signal_safe.
  (retry_fork_ruby): Specialized version of retry_fork respect to
  rb_fork_ruby.
  (rb_fork_ruby): Removed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47357 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-02 14:47:46 +00:00
akr de88408813 * process.c (send_child_error): Simplified.
(recv_child_error): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47356 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-02 14:27:10 +00:00
akr a78a9b0d17 * process.c (rb_fork_async_signal_safe): Inline rb_fork_internal.
(rb_fork_ruby): Ditto.
  (rb_fork_internal): Removed.
  (chfunc_protect): Removed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-02 13:56:35 +00:00
akr 557802a1da * process.c (handle_fork_error): Extracted from retry_fork.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-02 11:47:35 +00:00
nobu e5a7c2db98 get rid of function calls in RSTRING_PTR
* process.c (rlimit_resource_type, rlimit_resource_value): get rid
  of function calls in RSTRING_PTR(), as it evaluates the argument
  twice.

* re.c (match_backref_number): ditto.

* signal.c (esignal_init, rb_f_kill, trap_signm): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-30 13:46:41 +00:00
ktsj 3b895e8355 * process.c (rlimit_resource_type, rlimit_resource_value):
get rid of inadvertent dynamic symbol pin-down.

* re.c (match_backref_number): ditto.

* signal.c (esignal_init, rb_f_kill, trap_signm): ditto.

* transcode.c (econv_opts): ditto.

* vm_trace.c (symbol2event_flag): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-30 13:17:45 +00:00
nobu e99ee55abc constify parameters
* include/ruby/intern.h: constify `argv` parameters.

* include/ruby/ruby.h: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-18 06:16:39 +00:00
nobu fd444f90b5 process.c: use UTF-8
* process.c (open): use UTF-8 version function to support
  non-ascii path properly.  [ruby-core:63185] [Bug #9946]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-16 05:35:59 +00:00
nobu d327c8da66 process.c: variable as macro argument
* process.c (run_exec_open): use a local variable to get rid of
  RARRAY_AREF() is evaluated multiple times by RSTRING_PTR().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-16 05:28:03 +00:00
nobu efc70c74c2 process.c: use RB_TYPE_P
* process.c (check_exec_redirect): use RB_TYPE_P instead of single
  comparison of TYPE().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46435 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-15 01:09:17 +00:00
normal d450229a27 process.c (proc_getgroups, proc_setgroups): use ALLOCV_N
* process.c (proc_getgroups, proc_setgroups): use ALLOCV_N
  [Bug #9856]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46075 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-24 07:22:54 +00:00
nobu 55d4afc77e process.c: use ruby_stop
* process.c (rb_exit): call ruby_stop() which calls ruby_cleanup(),
  instead of calling ruby_finalize() directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45900 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-10 04:41:02 +00:00
akr 058b5bce60 [DOC]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-09 13:57:04 +00:00
akr 7a69a3583c * process.c (check_exec_redirect): Open the file in write mode for
redirect from [:out, :err].
  Proposed and implemented by Yusuke Endoh.
  [ruby-dev:41430] [Feature #3348]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-05 13:37:09 +00:00
akr 1388beb195 [DOC]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45789 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-02 13:35:47 +00:00
akr 960c8ab125 * process.c (OBJ2UID1): Defined even if getpwnam_r is not usable.
(OBJ2GID1): Defined even if getgrnam_r is not usable.
  This fixes compilation error on Android.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45541 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-09 12:05:14 +00:00
nobu c0dee604fe process.c: preserve encodings
* process.c (rlimit_resource_type, rlimit_resource_value):
  preserve argument encoding in error messages.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-30 21:00:53 +00:00
nobu d64ba37ad0 process.c: constify
* process.c (rb_execarg_new, rb_execarg_init): constify argv.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45357 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-17 08:21:47 +00:00
nobu 119d66232d process.c: expand buffer on ERANGE
* process.c (obj2uid, obj2gid): now getpwnam_r() and getgrnam_r()
  may need larger buffers than sysconf values, so retry with
  expanding the buffer when ERANGE is returned.
  [ruby-core:61325] [Bug #9600]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-08 04:30:56 +00:00
nobu 3df8fbf248 process.c: need capacity
* process.c (obj2uid, obj2gid): need capacity as buffer size, not
  length.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45289 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-08 04:30:30 +00:00
nobu 9e33b72ad1 process.c: GETPW_R_SIZE_INIT, GETGR_R_SIZE_INIT
* process.c (GETPW_R_SIZE_INIT, GETGR_R_SIZE_INIT): sysconf values
  are not maximum sizes, but initial sizes.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-08 04:08:46 +00:00
nobu b1fb57da3d process.c: tmp buffer instead of alloca
* process.c (OBJ2UID1, OBJ2GID1): separate from OBJ2UID and
  OBJ2GID respectively, need given buffers.

* process.c (OBJ2UID, OBJ2GID): no longer need PREPARE_GETPWNAM
  and PREPARE_GETGRNAM.

* process.c (obj2uid, obj2gid): use tmp buffer instead of alloca
  to get rid of potential stack overflow.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-08 03:55:01 +00:00
hsbt 511c2a1647 * process.c: [DOC] typo fix by @jkassemi [fix GH-544][ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-23 02:25:59 +00:00
akr 6f8b0e9bb0 * include/ruby/intern.h,
include/ruby/io.h,
  include/ruby/ruby.h,
  include/ruby/win32.h,
  include/ruby/backward/rubysig.h,
  bignum.c,
  gc.c,
  io.c,
  process.c,
  safe.c,
  struct.c,
  thread.c,
  ext/socket/rubysocket.h,
  ext/-test-/old_thread_select: Remove deprecated definitions
  [ruby-core:60581] [Feature #9502]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-14 15:16:31 +00:00
akr fbf4850cab * process.c (READ_FROM_CHILD): Apply the last hunk of
0001-process.c-avoid-EINTR-from-Process.spawn.patch written by
  Eric Wong in [Bug #8770].



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-28 11:54:36 +00:00
nobu 7336d8c899 process.c: avoid EINTR from Process.spawn
* process.c (send_child_error): retry write on EINTR to fix
  occasional Errno::EINTR from Process.spawn.
* process.c (recv_child_error): retry read on EINTR to fix
  occasional Errno::EINTR from Process.spawn.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-25 05:50:44 +00:00
charliesome 0a881f81b1 * process.c (recv_child_error): Fix deadlock in rb_fork_internal when a
signal is sent to the parent process while Ruby is forking in IO.popen.

  Patch by Scott Francis. Closes GH-513.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-23 05:07:48 +00:00
ko1 c702005a7b * include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
  proc.c, process.c, re.c, string.c, variable.c, vm.c,
  vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
  vm_method.c: catch up this change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 08:07:47 +00:00
naruse 2a732947a6 * process.c (make_clock_result): add :second as a unit for
Process.clock_gettime.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44230 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-16 05:04:03 +00:00
charliesome e0290c9404 * array.c (rb_ary_or): use RHASH_TBL_RAW instead of RHASH_TBL
* process.c (rb_execarg_fixup): use RHASH_TBL_RAW and insert write
  barriers where appropriate

* vm.c (kwmerge_i): use RHASH_TBL_RAW

* vm.c (HASH_ASET): use rb_hash_aset instead of calling directly into
  st_insert

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-08 00:41:01 +00:00
nobu 7566c49068 ruby/ruby.h: RB_BLOCK_CALL_FUNC_ARGLIST
* include/ruby/ruby.h (RB_BLOCK_CALL_FUNC_ARGLIST): for declaration
  argument list of rb_block_call_func.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-29 07:59:14 +00:00
nobu 9f45081627 ruby/ruby.h: add blockarg to rb_block_call_func
* include/ruby/ruby.h (rb_block_call_func): add blockarg.  block
  function can take block argument, e.g., proc {|&blockarg| ...}.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-29 02:26:48 +00:00
nobu 21f81885ab win32.c: rb_w32_dup2
* win32/win32.c (rb_w32_dup2): extract from rb_cloexec_dup2() and
  redirect_dup2().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43890 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-28 07:15:56 +00:00
ko1 c5e08b764e * add RUBY_TYPED_FREE_IMMEDIATELY to data types which only use
safe functions during garbage collection such as xfree().
  On default, T_DATA objects are freed at same points as fianlizers.
  This approach protects issues such as reported by [ruby-dev:35578].
  However, freeing T_DATA objects immediately helps heap usage.
  Most of T_DATA (in other words, most of dfree functions) are safe.
  However, we turned off RUBY_TYPED_FREE_IMMEDIATELY by default
  for safety.
* cont.c: ditto.
* dir.c: ditto.
* encoding.c: ditto.
* enumerator.c: ditto.
* error.c: ditto.
* file.c: ditto.
* gc.c: ditto.
* io.c: ditto.
* iseq.c: ditto.
* marshal.c: ditto.
* parse.y: ditto.
* proc.c: ditto.
* process.c: ditto.
* random.c: ditto.
* thread.c: ditto.
* time.c: ditto.
* transcode.c: ditto.
* variable.c: ditto.
* vm.c: ditto.
* vm_backtrace.c: ditto.
* vm_trace.c: ditto.
* ext/bigdecimal/bigdecimal.c: ditto.
* ext/objspace/objspace.c: ditto.
* ext/stringio/stringio.c: ditto.
* ext/strscan/strscan.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-29 11:16:54 +00:00
nobu d956453a98 process.c: Process::Tms
* process.c (Init_process): rename Struct::Tms as Process::Tms.  keep
  the former defined for the backward compatibility, for the time
  being.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-27 01:38:20 +00:00
akr c2bbe4b01e * process.c: Fix a typo. MacOS X don't have ENOTSUPP.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-15 08:48:33 +00:00
nobu ddef263a89 process.c: remove cloexec setting
* process.c (rb_fork_internal): remove cloexec setting on pipes
  created by rb_cloexec_pipe.  patch by normalperson (Eric Wong) at
  [ruby-core:56523].  [Bug #8769]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-21 11:11:10 +00:00
akr 888e5cbbe7 * process.c: Remove spaces between SI prefix and unit to follow
SI brochure.
  http://www.bipm.org/en/si/si_brochure/
  https://www.nmij.jp/library/units/si/

* time.c: Ditto.

* ext/socket/ancdata.c: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-09 12:33:36 +00:00
akr bc3d736f43 * process.c (rb_clock_gettime): Support times() based monotonic clock.
(rb_clock_getres): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-03 03:10:41 +00:00
akr 8a108ffc21 * process.c (get_mach_timebase_info): Extracted from rb_clock_gettime.
(rb_clock_gettime): Use get_mach_timebase_info.
  (rb_clock_getres): Support MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-01 15:09:06 +00:00
nobu cec97f40f6 process.c: suppress warning
* process.c (rb_clock_getres): move conditionally used variable to the
  proper block.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-01 09:04:10 +00:00
akr 23da5a785e * process.c (rb_clock_getres): New method.
(timetick2dblnum_reciprocal): New function.

* configure.in: Check clock_getres.

[ruby-core:56780] [Feature #8809] accepted at
DevelopersMeeting20130831Japan
https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20130831Japan



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-31 13:21:48 +00:00
kazu ae5ac37f2d fix typo
* process.c (gcd_timetick_int): Renamed from gcd_timtick_int.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-26 01:39:19 +00:00
akr cd9f60dfa5 [DOC]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-24 02:19:41 +00:00