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

949 Коммитов

Автор SHA1 Сообщение Дата
卜部昌平 735e035bf5 __GNUC__ is too lax
Ditto for 4b853932ea
2020-04-21 13:07:02 +09:00
Nobuyoshi Nakada fedc8075fe
Preserve encoding in error messages for invalid user/group name 2020-04-16 20:50:08 +09:00
Nobuyoshi Nakada f57e2d7296
Preserve encoding in error message for invalid env exec option 2020-04-16 20:50:07 +09:00
Benoit Daloze a6f7458ea8 Add a a list of cases for which clock_getres() has been observed to be inaccurate
* See [Bug #16740]
2020-04-13 18:23:39 +02:00
Nobuyoshi Nakada 8ec795400f
[DOC] Fixed POSIX clock_getres(3) link [ci skip]
It should not be linked to `Process.clock_getes`.
2020-04-10 22:46:00 +09:00
Benoit Daloze c9b3aa84be Warn about Process#clock_getres being unreliable in documentation
* [Bug #16740]
* Remove the GETTIMEOFDAY_BASED_CLOCK_REALTIME example because the
  caveat applies to all clock ids, not just the Symbol clock ids.
2020-04-10 14:42:14 +02:00
Nobuyoshi Nakada e474c189da
Suppress -Wswitch warnings 2020-04-08 15:13:37 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Nobuyoshi Nakada 985d1b9ec4
Fixed a potential memory leak
`rb_str_new_cstr` can raise a `NoMemoryError`.
2020-02-12 11:58:56 +09:00
Nobuyoshi Nakada 155ab9caa6
Removed unnecessary conversion
Paths in `rb_execarg_t` should have been converted already.
2020-02-12 11:58:34 +09:00
Nobuyoshi Nakada de3883e782
Restart timer thread even after preparation failed
If the timer thread is left stopped, memory crash or segfault can
happen.
2020-02-11 15:55:10 +09:00
卜部昌平 5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
Marcus Stollsteimer 54083fd41b [DOC] Fix grammar in Process module docs 2019-12-24 13:01:47 +01:00
Nobuyoshi Nakada db16629008
Fixed misspellings
Fixed misspellings reported at [Bug #16437], only in ruby and rubyspec.
2019-12-20 09:32:42 +09:00
Nobuyoshi Nakada d2f04d332f Kernel#abort without arguments should print error info
[Bug #16424]
2019-12-16 14:55:59 +09:00
卜部昌平 7a9b2039b7 delete unused codes
Suppress compiler warnings.
2019-11-18 18:28:03 +09:00
Jeremy Evans c5c05460ac Warn on access/modify of $SAFE, and remove effects of modifying $SAFE
This removes the security features added by $SAFE = 1, and warns for access
or modification of $SAFE from Ruby-level, as well as warning when calling
all public C functions related to $SAFE.

This modifies some internal functions that took a safe level argument
to no longer take the argument.

rb_require_safe now warns, rb_require_string has been added as a
version that takes a VALUE and does not warn.

One public C function that still takes a safe level argument and that
this doesn't warn for is rb_eval_cmd.  We may want to consider
adding an alternative method that does not take a safe level argument,
and warn for rb_eval_cmd.
2019-11-18 01:00:25 +02:00
Nobuyoshi Nakada df62d6522a
Use the dedicated function `rb_io_check_io` 2019-11-04 09:14:18 +09:00
zverok bddb31bb37 Documentation improvements for Ruby core
* Top-level `return`;
* Documentation for comments syntax;
* `rescue` inside blocks;
* Enhance `Object#to_enum` docs;
* Make `chomp:` option more obvious for `String#each_line` and
  `#lines`;
* Enhance `Proc#>>` and `#<<` docs;
* Enhance `Processs` class docs.
2019-10-26 14:58:08 +09:00
Nobuyoshi Nakada cbbe198c89
Fix potential memory leaks by `rb_imemo_tmpbuf_auto_free_pointer`
This function has been used wrongly always at first, "allocate a
buffer then wrap it with tmpbuf".  This order can cause a memory
leak, as tmpbuf creation also can raise a NoMemoryError exception.
The right order is "create a tmpbuf then allocate&wrap a buffer".
So the argument of this function is rather harmful than just
useless.

TODO:
* Rename this function to more proper name, as it is not used
  "temporary" (function local) purpose.
* Allocate and wrap at once safely, like `ALLOCV`.
2019-10-05 03:02:09 +09:00
Alan Wu 5be2af5f90 Remove call-seq for method that doesn't exist (#2521)
```
$ ruby -ve 'IO.popen("ls"){}; $?.to_int'
ruby 2.6.4p104 (2019-08-28 revision 67798) [x86_64-darwin18]
Traceback (most recent call last):
-e:1:in `<main>': undefined method `to_int' for #<Process::Status: pid 33989 SIGPIPE (signal 13)> (NoMethodError)
Did you mean?  to_i
               taint
```

Process::Status#to_int was removed at 7ba5c4e.
2019-10-04 10:15:24 +09:00
yuuji.yaginuma 0036aa3532 Add version that FreeBSD supports `CLOCK_PROCESS_CPUTIME_ID` [ci skip]
Seems FreeBSD already supported `CLOCK_PROCESS_CPUTIME_ID`.
That added by https://reviews.freebsd.org/rS239347 and the doc was updated
by https://reviews.freebsd.org/rS315694.

I confirmed `CLOCK_PROCESS_CPUTIME_ID` constant exists in 9.3.0 branch.
https://github.com/freebsd/freebsd/blob/release/9.3.0/sys/sys/time.h#L269
2019-09-05 22:09:15 +09:00
卜部昌平 0766f67168 move docs around [ci skip]
To properly generate documents.
2019-08-29 18:34:09 +09:00
卜部昌平 7bcfd9189a drop-in type check for rb_define_global_function
We can check the function pointer passed to rb_define_global_function
like we do so in rb_define_method.  It turns out that almost anybody
is misunderstanding the API.
2019-08-29 18:34:09 +09:00
卜部昌平 7b6fde4258 drop-in type check for rb_define_module_function
We can check the function pointer passed to rb_define_module_function
like how we do so in rb_define_method.  The difference is that this
changeset reveales lots of atiry mismatches.
2019-08-29 18:34:09 +09:00
卜部昌平 1663d347c9 delete `$` sign from C identifiers
They lack portability. See also
https://travis-ci.org/shyouhei/ruby/jobs/577164015
2019-08-27 15:52:26 +09:00
卜部昌平 ae2dc3f217 rb_define_hooked_variable now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit uses rb_gvar_getter_t /
rb_gvar_setter_t for rb_define_hooked_variable /
rb_define_virtual_variable which revealed lots of function prototype
inconsistencies.  Some of them were literally decades old, going back
to dda5dc00cf.
2019-08-27 15:52:26 +09:00
卜部昌平 5e86b005c0 uid_t and gid_t are narrower than VALUE.
Often uid / gid are 16 bit or 32 bit integers, while VALUE are 32
to 64 bits.  They tend to differ in size.  Because rb_ensure expects
its callbacks to take VALUE arguments, narrowing must be done by
hand, otherwise data corruption can happen depending on machine ABI.
2019-08-26 13:01:58 +09:00
Nobuyoshi Nakada fa6c1b06ad
Suppress a "clobbered" warning 2019-08-26 12:00:19 +09:00
Nobuyoshi Nakada d45d448d71
nil as the default of optional parameters 2019-07-16 21:38:25 +09:00
Nobuyoshi Nakada d8e23a67c3
nil as the default of optional parameters 2019-07-16 19:27:22 +09:00
Nobuyoshi Nakada e988048e25
Moved the check for `exception` to rb_execarg_addopt
Check for `exception` option in rb_execarg_addopt, as well as
other options.  And then raise a particular ArgumentError if it is
not allowed.
2019-07-16 18:57:08 +09:00
Yusuke Endoh b4975693ed process.c (p_sys_setregid, p_sys_setresgid): remove unused tmp buffer
To suppress Coverity Scan warning
2019-07-15 00:07:32 +09:00
nobu 721be15494 process.c: [DOC] remove extra quotes [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67386 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-30 12:37:23 +00:00
nobu fcf60d3977 process.c: [DOC] fix markups [ci skip]
* process.c (rb_f_spawn): fix markups as rdoc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-29 01:26:23 +00:00
nobu b9ad698c87 process.c: [DOC] fix markups [ci skip]
* process.c (rb_clock_getres): fix code markups, as `+` can not
  include parentheses.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-29 00:59:34 +00:00
nobu de0ef1a9df [DOC] fix markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-28 03:33:35 +00:00
akr b1cb15c4a4 new constant: Process::CLOCK_TAI.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-09 14:54:54 +00:00
stomar 1c53f86bd9 process.c: [DOC] small improvements
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66886 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-20 15:07:17 +00:00
k0kubun 56bf732aaf mjit.c: use boolean type for boolean variables
and functions to clarify the intention and make sure it's not used in a
surprising way (like using 2, 3, ... other than 0, 1 even while it seems
to be a boolean).

This is a retry of r66775. It included some typos...

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66778 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10 14:31:18 +00:00
k0kubun efd99b5331 Revert "mjit.c: use boolean type for boolean variables"
This reverts commit bb1a1aeab0.

We hit something on ci.rvm.jp, reverting until investigation is done.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10 13:29:29 +00:00
k0kubun bb1a1aeab0 mjit.c: use boolean type for boolean variables
and functions to clarify the intention and make sure it's not used in a
surprising way (like using 2, 3, ... other than 0, 1 even while it seems
to be a boolean).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10 13:21:58 +00:00
k0kubun 9f3585afad process.c: document system(..., exception: true) [ci skip]
From: Victor Shepelev <zverok.offline@gmail.com>

[Bug #15480]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66637 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-29 11:04:42 +00:00
nobu 8ef2aae2d0 Use idException
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-22 10:23:06 +00:00
nobu b0ec083a20 process.c (retry_fork_async_signal_safe): fix -Wclobbered
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-04 01:41:55 +00:00
normal 7712ffc7ee process.c (retry_fork_async_signal_safe): fix -Wclobbered on i686
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 21:00:32 +00:00
normal a226434206 process.c: fix ETXTBUSY from MJIT compiler process
This affects test/ruby/test_process.rb (test_execopt_env_path).

Since MJIT uses vfork+execve in a separate thread, there can be
small window in-between vfork and execve where tmp_script.cmd is
held open by the vforked child.  vfork only pauses the MJIT
thread, not any Ruby Threads, so our call to Process.spawn will
hit ETXTBUSY in that window unless we fork.

main thread                       | MJIT thread
----------------------------------------------------
fd = open(tmp)                    |                |
                                  | vfork for CC   |   CC running
write                             |                | ---------------
fchmod                            |                |  sees "fd" here
close(fd)                         |                |
    Process.spawn called          |                |
vfork  (spawn)|    (new process)  |                |
              | execve => TXTBUSY |                |
              |                   |                | execve (FD_CLOEXEC on fd)
              |                   | vfork returns  |

Holding the waitpid_lock whenever we intend to spawn a process
prevents the MJIT thread from spawning a process while we are
spawning in Ruby-land.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 19:49:54 +00:00
normal f8c15d0bc7 process.c (rb_execarg_init): mark as static
io.c has not used it since r36229, and we can re-export
it if we need it at another time.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 09:15:16 +00:00
normal 323ddfc168 process.c (rb_f_system): cleanup to use rb_execarg_get
TypedData_* macros hide assignments and are confusing and too
long for users of giant fonts.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 08:57:15 +00:00
k0kubun 98a2b053f8 process.c: avoid dlclose before exec
because JIT-ed code may still be on stack at this time, unlike
in ruby_cleanup().

This hopes to fix: (take 2)
http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/1480207

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26 15:12:31 +00:00
k0kubun 5b12501163 Revert "process.c: try to workaroun SEGV by r65994"
This reverts commit 0e6aba22c6.

because it didn't help, at all.
http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/1480207

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65998 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26 15:12:30 +00:00
k0kubun 0e6aba22c6 process.c: try to workaroun SEGV by r65994
http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/1480173

It tries to print C backtrace but fails. And core file on the server
seems to be stopping on the irrelevant place due to its own signal
handler for the dump.

And I failed to reproduce this SEGV on my machine.

I don't know why it's broken, so let me try this change to investigate
the reason of SEGV.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26 14:45:39 +00:00
k0kubun 08e1705eec process.c: finish MJIT prior to #exec
to prevent ruby from leaving MJIT-related files.

test_jit.rb: add a test to prevent that

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26 13:39:53 +00:00
normal 6a65f2b1e4 io + socket: make pipes and sockets nonblocking by default
All normal Ruby IO methods (IO#read, IO#gets, IO#write, ...) are
all capable of appearing to be "blocking" when presented with a
file description with the O_NONBLOCK flag set; so there is
little risk of incompatibility within Ruby-using programs.

The biggest compatibility risk is when spawning external
programs.  As a result, stdin, stdout, and stderr are now always
made blocking before exec-family calls.

This change will make an event-oriented MJIT usable if it is
waiting on pipes on POSIX_like platforms.

It is ALSO necessary to take advantage of (proposed lightweight
concurrency (aka "auto-Fiber") or any similar proposal for
network concurrency: https://bugs.ruby-lang.org/issues/13618

Named-pipe (FIFO) are NOT yet non-blocking by default since
they are rarely-used and may introduce compatibility problems
and extra syscall overhead for a common path.

Please revert this commit if there are problems and if I am afk
since I am afk a lot, lately.

[ruby-core:89950] [Bug #14968]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22 08:46:51 +00:00
k0kubun 3405411cc4 process.c: do not try to pause MJIT
while child handler is disabled.

trying to fix [Bug #15320]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20 00:04:19 +00:00
k0kubun 27322735af revert r65807
it didn't work.
http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1468677

and skips broken tests for now. But this issue should be fixed soon.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-19 22:10:12 +00:00
k0kubun e205cd80d2 process.c: do not run signal handler before fork
to prevent from proceeding one for MJIT while it's not safe yet.
By that situation, MJIT worker could be waiting for compiler process forever
http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1468033

[Bug #15320]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-19 13:33:07 +00:00
svn 57efe84b13 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-18 08:25:54 +00:00
k0kubun fe6974a8fc mjit_worker.c: support MJIT in forked Ruby process
by launching MJIT worker thread in child Ruby process.

See the comment before `mjit_child_after_fork` for details.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-18 08:25:48 +00:00
ko1 8f675cdd00 support theap for T_HASH. [Feature #14989]
* hash.c, internal.h: support theap for small Hash.
  Introduce RHASH_ARRAY (li_table) besides st_table and small Hash
  (<=8 entries) are managed by an array data structure.
  This array data can be managed by theap.
  If st_table is needed, then converting array data to st_table data.

  For st_table using code, we prepare "stlike" APIs which accepts hash value
  and are very similar to st_ APIs.

  This work is based on the GSoC achievement
  by tacinight <tacingiht@gmail.com> and refined by ko1.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 22:11:51 +00:00
normal f7c0cc3692 process.c: implement rb_f_system without toggling ruby_nocldwait
Following how mjit_worker.c currently works, rb_f_system
now ensures the VM-wide waitpid lists is locked before
creating a new process via fork/vfork.

This ensures other rb_waitpid callers cannot steal work and
there are no possible race conditions from toggling
ruby_nocldwait without the use of atomics.

This sets us up for implementing MJIT process management
logic using normal Ruby APIs prepares us for VM-wide
asynchronous/event-base waitpid which can allow MJIT to
work without worker threads.

Take 2: set waitpid_state.pid on platforms w/o fork.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65437 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 01:34:48 +00:00
normal fbee3b8f75 revert r65434
http://mswinci.japaneast.cloudapp.azure.com/vc12-x64/ruby-trunk/log/20181030T003541Z.fail.html.gz
I have no chance of getting anything to work on proprietary platforms :<

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65436 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 01:12:38 +00:00
svn 76f08cec20 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65435 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-29 23:52:45 +00:00
normal 8227c91dfe process.c: implement rb_f_system without toggling ruby_nocldwait
Following how mjit_worker.c currently works, rb_f_system
now ensures the VM-wide waitpid lists is locked before
creating a new process via fork/vfork.

This ensures other rb_waitpid callers cannot steal work and
there are no possible race conditions from toggling
ruby_nocldwait without the use of atomics.

This sets us up for implementing MJIT process management
logic using normal Ruby APIs prepares us for VM-wide
asynchronous/event-base waitpid which can allow MJIT to
work without worker threads.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65434 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-29 23:52:39 +00:00
normal 98d0ccc86a rb_sigwait_sleep: change internal API to use rb_hrtime_t
rb_hrtime_t is a more pleasant type to use and this can make
future changes around sleeping/scheduling easier.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-19 20:14:41 +00:00
stomar 580a210350 process.c: [DOC] improve docs for Process.groups
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-12 20:01:52 +00:00
svn 9d7a5a493f * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-10 04:20:21 +00:00
ko1 eed1deecba revisit `RARRAY_PTR()`.
* process.c (check_exec_redirect): use RARRAY_AREF() instead of
  using RARRAY_PTR().


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-10 04:20:17 +00:00
normal 41cf596dfd process.c (waitpid_cleanup): unconditionally remove from waiters
This is the safer option, as there seems to be cases where checking
waitpid_state.ret is insufficient in ensure.  I'm not 100% sure
why this is, but this change was required for my work-in-progress
Thread::Light patch series, too...

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-19 08:23:19 +00:00
normal e61e6ae587 process.c: fix potential missed wakeups in r64576
Oddly, all existing test cases passed multiple times
before this patch (even with --jit-wait), so this seems
like a difficult failure to prove.

Fixes: r64576 ("process.c: simplify SIGCHLD-based waitpid")

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64577 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-27 18:37:04 +00:00
normal 9d4027b503 process.c: simplify SIGCHLD-based waitpid
Introduce a new rb_thread_sleep_interruptible that does not
execute interrupts before sleeping.  Skipping the interrupt
check before sleep is required for out-of-GVL ruby_waitpid_all
to function properly when setting waitpid_state.ret

Now that ubf_select can be called by the gvl.timer thread
without recursive locking gvl.lock, we can safely use
rb_threadptr_interrupt to deal with waking up sleeping
processes,

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-27 17:17:13 +00:00
normal 84859fd2d2 process.c: remove worthless waitpid_sys macro
It is identical to do_waitpid, and the win32 version will not
be needed for MJIT (since win32 does not suffer from the
waitpid(-1, ...) conflict where waits can get stolen.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64541 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-26 04:29:11 +00:00
naruse 682a661e1c Re-Revert "Temporary revert "process.c: dead code when no SIGCHLD""
This re-reverts commit r64447.
The issue was machine side problem.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-21 13:39:24 +00:00
naruse b5b5b28c65 Temporary revert "process.c: dead code when no SIGCHLD"
This reverts commit r64407.
Maybe it breaks http://mswinci.japaneast.cloudapp.azure.com/vc12-x64/ruby-trunk/log/20180817T095734Z.fail.html.gz

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-18 12:35:28 +00:00
nobu 3bd2d01f96 process.c: dead code when no SIGCHLD
* process.c (ruby_waitpid_all): nothing to do unless SIGCHLD is
  available.

* signal.c (ruby_nocldwait): used only if SIGCHLD is available.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-17 05:59:45 +00:00
normal b53fadfd5f process.c: defaults to close_others false
Arbitrarily closing file descriptors on exec breaks use cases
where a Ruby process sets up a descriptor for non-Ruby children
to use.  For example, the "rake foo" target may spawn any number
of subprocesses (Ruby or not) which depends on parsing the "FOO"
environment variable for out_fd:99 and writing to foo.out

    FOO=out_fd:99 rake foo 99>>foo.out

Unfortunately, this introduced one incompatibility in
test/lib/test/unit.rb and it now requires explicitly setting
IO#close_on_exec=true

[ruby-core:88007] [Misc #14907]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64399 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-16 23:56:08 +00:00
normal 3872ea814c thread_pthread.c: reduce ubf_timer arming for non-signal wakeups
We do not need to rely on SIGVTALRM for non-sighandler wakeups.
This will reduce spurious wakeups in cases where sigwait_fd
is not grabbed again, soon.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-16 08:26:56 +00:00
normal 48b6bd74e2 thread_pthread.c: eliminate timer thread by restructuring GVL
This reverts commit 194a6a2c68 (r64203).

Race conditions which caused the original reversion will be fixed
in the subsequent commit.

[ruby-core:88360] [Misc #14937]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-13 21:34:20 +00:00
kazu c5aeebfed5 Fix a typo [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-10 12:36:31 +00:00
mrkn c0d1a46fc3 process.c: fix rubyspec of Process.groups
getgroups(2) may return a GID list that includes duplicated GIDs.
The behavior is totaly depends on what OS is used.

This commit fixes the example of Process.groups so that the example
is independent of this OS-dependent features.

Additonaly, this commit adds the description of such system-dependent
characteristics of Process.groups.

[ruby-dev:50603] [Bug #14969]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64265 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-10 05:18:03 +00:00
k0kubun 2e003f6c87 process.c: don't wait JIT queue flush on rb_f_exec
This wasn't intended in r64253.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64254 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-09 11:39:07 +00:00
k0kubun 212a77ed46 process.c: fix outdated mjit_pause declaration
by sharing it with vm.c in internal.h.

vm.c: ditto
internal.h: ditto
mjit.h: share more.

mjit.c: make sure the third arguemnt is not used

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-09 11:31:41 +00:00
normal 194a6a2c68 thread_pthread.c: restore timer-thread for now :<
[ruby-core:88306]

Revert "process.c: ensure th->interrupt lock is held when migrating"

This reverts commit 5ca416bdf6 (r64201)

Revert "process.c (rb_waitpid): reduce sigwait_fd bouncing"

This reverts commit 217bdd776f (r64200).

Revert "test/ruby/test_thread.rb (test_thread_timer_and_interrupt): add timeouts"

This reverts commit 9f395f1120 (r64199).

Revert "thread_pthread.c (native_sleep): reduce ppoll sleeps"

This reverts commit b3aa256c4d (r64193).

Revert "thread.c (consume_communication_pipe): do not retry after short read"

This reverts commit 291a82f748 (r64185).

Revert "test/ruby/test_io.rb (test_race_gets_and_close): timeout each thread"

This reverts commit 3dbd8d1f66 (r64184).

Revert "thread_pthread.c (gvl_acquire_common): persist timeout across calls"

This reverts commit 8c2ae6e3ed (r64165).

Revert "test/ruby/test_io.rb (test_race_gets_and_close): use SIGABRT on timeout"

This reverts commit 931cda4db8 (r64135).

Revert "thread_pthread.c (gvl_yield): do ubf wakeups when uncontended"

This reverts commit 508f00314f (r64133).

Revert "thread_pthread.h (native_thread_data): split condvars on some platforms"

This reverts commit a038bf238b (r64124).

Revert "process.c (waitpid_nogvl): prevent conflicting use of sleep_cond"

This reverts commit 7018acc946 (r64117).

Revert "thread_pthread.c (rb_sigwait_sleep): th may be 0 from MJIT"

This reverts commit 56491afc79 (r64116).

Revert "thread*.c: waiting on sigwait_fd performs periodic ubf wakeups"

This reverts commit ab47a57a46 (r64115).

Revert "thread_pthread.c (gvl_destroy): make no-op on GVL bits"

This reverts commit 95cae74817 (r64114).

Revert "thread_pthread.c (rb_sigwait_sleep): fix uninitialized poll set in UBF case"

This reverts commit 4514362948 (r64113).

Revert "thread_pthread.c (rb_sigwait_sleep): re-fix [Bug #5343] harder"

This reverts commit 26b8a70bb3 (r64111).

Revert "thread.c: move ppoll wrapper into thread_pthread.c"

This reverts commit 3dc7727d22 (r64110).

Revert "thread.c: move ppoll wrapper before thread_pthread.c"

This reverts commit 2fa1e2e3c3 (r64109).

Revert "thread_pthread.c (ubf_select): refix [Bug #5343]"

This reverts commit 4c1ab82f06 (r64108).

Revert "thread_win32.c: suppress warnings by -Wsuggest-attribute"

This reverts commit 6a9b63e390 (r64159).

Revert "thread_pthread: remove timer-thread by restructuring GVL"

This reverts commit 708bfd2115 (r64107).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-06 05:22:00 +00:00
normal 5ca416bdf6 process.c: ensure th->interrupt lock is held when migrating
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
2018-08-06 01:06:21 +00:00
normal 217bdd776f process.c (rb_waitpid): reduce sigwait_fd bouncing
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
2018-08-05 21:27:14 +00:00
normal 2ba640f359 thread_pthread: stop trying to deal with cancellation
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
2018-08-05 20:06:49 +00:00
shyouhei ab740cbb75 move #pragma out of functions
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
2018-07-30 07:53:24 +00:00
shyouhei d83536c980 reduce copy & paste
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
2018-07-30 07:07:48 +00:00
normal 7018acc946 process.c (waitpid_nogvl): prevent conflicting use of sleep_cond
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
2018-07-30 06:35:08 +00:00
normal 708bfd2115 thread_pthread: remove timer-thread by restructuring GVL
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
2018-07-29 20:47:33 +00:00
nobu d6df54cc9f process.c: conditionally used functions
* 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
2018-07-26 12:04:32 +00:00
nobu 05316c40ac fork() is deprecated on Solaris
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-26 09:32:42 +00:00
kazu 004f55212d Try to suppress warning on some CI
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
2018-07-24 09:15:58 +00:00
nobu 97e05dad7f UNREACHABLE_RETURN
* 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
2018-07-24 05:38:07 +00:00
nobu 62870d2c73 process.c: adjust indent [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-15 09:57:27 +00:00
normal eb53b0ff05 process.c (assert_close_on_exec): quiet warning about unused result
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
2018-07-13 06:05:43 +00:00
normal c6b85fcd01 timer_thread: do not close pipes around fork
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
2018-07-12 23:23:25 +00:00
normal b93dc84883 signal.c: preserve trap(:CHLD, "IGNORE") behavior with SIGCHLD
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-08 00:02:27 +00:00
normal ac41c2c132 process.c (rb_f_exec): pause MJIT before replacing process
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-07 23:59:23 +00:00
normal 44fc3d08eb unrevert r63852 but keep SIGCHLD path disabled for win32
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-05 03:02:33 +00:00