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

949 Коммитов

Автор SHA1 Сообщение Дата
Lars Kanis 7e36b91526 Add Windows as a supported OS for Process.clock_gettime [ci skip] 2021-08-28 18:26:19 +09:00
Nobuyoshi Nakada a8714b83c4
`popen()` is not available on emscripten 2021-08-16 17:00:19 +09:00
Nobuyoshi Nakada 07b12a1f48
Suppress unused-variable warnings 2021-08-16 16:02:49 +09:00
Nobuyoshi Nakada 785c70e764
[DOC] mention how the command is passed to the shell [ci skip] 2021-08-03 18:16:32 +09:00
Nobuyoshi Nakada e294beb731
[DOC] Fix Process::exec documentation [ci skip]
Shell reserved words and special built-in commands can be placed
at only the beginning of the command (except for leading white
spaces).
2021-07-31 11:38:27 +09:00
Nobuyoshi Nakada 01d9e7f26c [DOC] Fix Process::exec documentation [ci skip]
The environment variable `RUBYSHELL` is used only on Windows, as
well as `COMSPEC`.
2021-07-30 19:36:17 +09:00
S.H fc50b2eae5
Remove unneeded function declarations 2021-07-22 15:41:03 +09:00
Yusuke Endoh 645616c273 process.c: Call rb_thread_atfork in rb_fork_ruby
All occurrences of rb_fork_ruby are followed by a call rb_thread_fork in
the created child process.

This is refactoring and a potential preparation for [Feature #17795].
(rb_fork_ruby may be wrapped by Process._fork_.)
2021-07-15 16:46:08 +09:00
Samuel Williams 42130a64f0
Replace copy coroutine with pthread implementation. 2021-07-01 11:23:03 +12:00
Samuel Williams 5f69a7f604
Expose scheduler as public interface & bug fixes. (#3945)
* Rename `rb_scheduler` to `rb_fiber_scheduler`.

* Use public interface if available.

* Use `rb_check_funcall` where possible.

* Don't use `unblock` unless the fiber was non-blocking.
2021-02-09 19:39:56 +13:00
Nobuyoshi Nakada 81562f943e
Updated access to Process::Status attributes
pst_pid() no longer returns Qnil even if the receiver is not
initialized.
2020-12-24 23:35:18 +09:00
Nobuyoshi Nakada bdbbfd1fa5 Store errno in struct rb_process_status
To propagate errno in the fiber thread scheduler hook.
Returns nil when no terminated process.
2020-12-24 22:59:37 +09:00
卜部昌平 fee2913d0a Struct::Tms: delete
Has been deprecated since 44c53ee473.
2020-12-22 13:52:18 +09:00
Nobuyoshi Nakada fb8f011422
Fixed indefinite articles before "Integer" [ci skip] 2020-12-21 01:19:55 +09:00
Radosław Bułat ed5c09f384 Remove unused variable 2020-12-19 00:04:19 +09:00
Yusuke Endoh 982443e6e3 Revert "Better cooperation between public/protected/private with attr* and alias_method"
This reverts commit 81739ad4fd.
2020-12-18 16:08:55 +09:00
Radosław Bułat 81739ad4fd Better cooperation between public/protected/private with attr* and alias_method 2020-12-17 12:46:02 -05:00
Nobuyoshi Nakada ad8e82f708
Fixed marshal compatibility of Process::Status 2020-12-16 12:31:40 +09:00
Nobuyoshi Nakada 4e5156621e
[DOC] Process::Status.wait return nil if no child processes [ci skip] 2020-12-12 11:44:25 +09:00
Nobuyoshi Nakada ed343c76fb
RDoc states that Process::Status.wait returns nil if cannot wait 2020-12-11 20:21:03 +09:00
Nobuyoshi Nakada 1728eba48a
[DOC] Fixed the RDoc location of Process::Status.wait [ci skip] 2020-12-11 19:40:25 +09:00
Nobuyoshi Nakada bca57b911a
[DOC] Moved RDoc of abort [ci skip] 2020-12-11 14:09:34 +09:00
Nobuyoshi Nakada b419f90a8b
Tweaked `Process::Status.wait`
* revert `rb_last_status_set`
* renamed the new function as `rb_process_status_new`
* `rb_process_status_new` always freezes the return value
* marked `Process::Status.wait` as EXPERIMENTAL, as it has not
  been discussed totally yet.
2020-12-09 11:51:57 +09:00
Samuel Williams 2553c5f94a Add support for non-blocking `Process.wait`. 2020-12-09 08:55:35 +13:00
Masaki Matsushita 5d8bcc4870 Revert getaddrinfo_a()
getaddrinfo_a() gets stuck after fork().
To avoid this, we need 1 second sleep to wait for internal
worker threads of getaddrinfo_a() to be finished, but that is unacceptable.

[Bug #17220] [Feature #17134] [Feature #17187]
2020-12-07 13:33:53 +09:00
Masaki Matsushita 76439eee68 Call cleanup function for getaddrinfo_a(3) only before fork()
Previously, rb_getaddrinfo_a_before_exec() is called from before_exec().
However, the function needs to be called only before fork().
The change moves it to before_fork().
2020-12-06 01:32:43 +09:00
Masaki Matsushita 94d49ed31c Add a hook before fork() for getaddrinfo_a()
We need stop worker threads in getaddrinfo_a() before fork().
This change adds a hook before fork() that cancel all outstanding requests
and wait for all ongoing requests. Then, it waits for all worker
threads to be finished.

Fixes [Bug #17220]
2020-12-04 23:31:51 +09:00
Takashi Kokubun 01f38693aa
Remove obsoleted internal/mjit.h inclusion
🙇
2020-11-22 20:28:34 -08:00
Koichi Sasada 5e3259ea74 fix public interface
To make some kind of Ractor related extensions, some functions
should be exposed.

* include/ruby/thread_native.h
  * rb_native_mutex_*
  * rb_native_cond_*
* include/ruby/ractor.h
  * RB_OBJ_SHAREABLE_P(obj)
  * rb_ractor_shareable_p(obj)
  * rb_ractor_std*()
  * rb_cRactor

and rm ractor_pub.h
and rename srcdir/ractor.h to srcdir/ractor_core.h
    (to avoid conflict with include/ruby/ractor.h)
2020-11-18 03:52:41 +09:00
Samuel Williams a08ee8330d Rename to `Fiber#set_scheduler`. 2020-11-07 23:39:50 +13:00
Koichi Sasada 1c6ebe14fb freeze Process::Status
It seems immutable information.
2020-10-27 01:37:24 +09:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
Koichi Sasada 99310e3eb5 Some global variables can be accessed from ractors
Some global variables should be used from non-main Ractors.
[Bug #17268]

```ruby
     # ractor-local (derived from created ractor): debug
     '$DEBUG' => $DEBUG,
     '$-d' => $-d,

     # ractor-local (derived from created ractor): verbose
     '$VERBOSE' => $VERBOSE,
     '$-w' => $-w,
     '$-W' => $-W,
     '$-v' => $-v,

     # process-local (readonly): other commandline parameters
     '$-p' => $-p,
     '$-l' => $-l,
     '$-a' => $-a,

     # process-local (readonly): getpid
     '$$'  => $$,

     # thread local: process result
     '$?'  => $?,

     # scope local: match
     '$~'  => $~.inspect,
     '$&'  => $&,
     '$`'  => $`,
     '$\''  => $',
     '$+'  => $+,
     '$1'  => $1,

     # scope local: last line
     '$_' => $_,

     # scope local: last backtrace
     '$@' => $@,
     '$!' => $!,

     # ractor local: stdin, out, err
     '$stdin'  => $stdin.inspect,
     '$stdout' => $stdout.inspect,
     '$stderr' => $stderr.inspect,
```
2020-10-20 15:38:54 +09:00
Samuel Williams 9e0a48c7a3 Prefer `rb_thread_current_scheduler`. 2020-09-14 16:44:09 +12:00
Samuel Williams d387029f39 Standardised scheduler interface. 2020-09-14 16:44:09 +12:00
Koichi Sasada 79df14c04b Introduce Ractor mechanism for parallel execution
This commit introduces Ractor mechanism to run Ruby program in
parallel. See doc/ractor.md for more details about Ractor.
See ticket [Feature #17100] to see the implementation details
and discussions.

[Feature #17100]

This commit does not complete the implementation. You can find
many bugs on using Ractor. Also the specification will be changed
so that this feature is experimental. You will see a warning when
you make the first Ractor with `Ractor.new`.

I hope this feature can help programmers from thread-safety issues.
2020-09-03 21:11:06 +09:00
Kazuhiro NISHIYAMA 1ab6034529
Fix type of getlogin_r's 2nd argument
https://rubyci.org/logs/rubyci.s3.amazonaws.com/freebsd12/ruby-master/log/20200821T223002Z.fail.html.gz
```
process.c:5593:37: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
    while ((gle = getlogin_r(login, loginsize)) != 0) {
                  ~~~~~~~~~~        ^~~~~~~~~
```

type of getlogin_r's 2nd argument is
- int on FreeBSD
  - https://www.freebsd.org/cgi/man.cgi?query=getlogin_r&apropos=0&sektion=0&manpath=FreeBSD+12.1-RELEASE+and+Ports&arch=default&format=html
- size_t on Linux, NetBSD
  - https://man7.org/linux/man-pages/man3/getlogin_r.3.html
  - https://www.freebsd.org/cgi/man.cgi?query=getlogin_r&apropos=0&sektion=0&manpath=NetBSD+9.0&arch=default&format=html
2020-08-22 09:39:24 +09:00
Samuel Williams f3462d99a3 Rename `rb_current_thread_scheduler` to `rb_thread_scheduler_if_nonblocking`.
Correctly capture thread before releasing GVL and pass as argument to
`rb_thread_scheduler_if_nonblocking`.
2020-07-20 13:20:58 +12:00
卜部昌平 de3e931df7 add UNREACHABLE_RETURN
Not every compilers understand that rb_raise does not return.  When a
function does not end with a return statement, such compilers can issue
warnings.  We would better tell them about reachabilities.
2020-06-29 11:05:41 +09:00
卜部昌平 08202d1f0e check_exec_redirect: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 9298631316 check_exec_redirect_fd: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
Nobuyoshi Nakada cbb9935fc4
Use the dedicated conversion macro 2020-06-09 22:25:46 +09:00
nicholas a. evans b6bae0ec44 Return seconds slept after Thread.scheduler wait_sleep
Kernel#sleep should still return seconds slept, even when using a
Thread.scheduler. The return value of Scheduler#wait_sleep can be
ignored.
2020-06-09 18:57:17 +09:00
Alan D. Salewski c15cddd1d5 Allow Dir.home to work for non-login procs when $HOME not set
Allow the 'Dir.home' method to reliably locate the user's home directory when
all three of the following are true at the same time:

    1. Ruby is running on a Unix-like OS
    2. The $HOME environment variable is not set
    3. The process is not a descendant of login(1) (or a work-alike)

The prior behavior was that the lookup could only work for login-descended
processes.

This is accomplished by looking up the user's record in the password database
by uid (getpwuid_r(3)) as a fallback to the lookup by name (getpwname_r(3))
which is still attempted first (based on the name, if any, returned by
getlogin_r(3)).

If getlogin_r(3), getpwnam_r(3), and/or getpwuid_r(3) is not available at
compile time, will fallback on using their respective non-*_r() variants:
getlogin(3), getpwnam(3), and/or getpwuid(3).

The rationale for attempting to do the lookup by name prior to doing it by uid
is to accommodate the possibility of multiple login names (each with its own
record in the password database, so each with a potentially different home
directory) being mapped to the same uid (as is explicitly allowed for by
POSIX; see getlogin(3posix)).

Preserves the existing behavior for login-descended processes, and adds the
new capability of having Dir.home being able to find the user's home directory
for non-login-descended processes.

Fixes [Bug #16787]

Related discussion:
    https://bugs.ruby-lang.org/issues/16787
    https://github.com/ruby/ruby/pull/3034
2020-05-23 23:16:28 +09:00
Samuel Williams 0e3b0fcdba
Thread scheduler for light weight concurrency. 2020-05-14 22:10:55 +12:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
Nobuyoshi Nakada 5d430c1b34
Added more NORETURN declarations 2020-05-11 00:40:14 +09:00
Takashi Kokubun 967ae6278f
Run rb_syswait on exec failure
not only when !w but also when w == WAITPID_LOCK_ONLY.
See also: f7c0cc3692 and a226434206.
We thought this change was an oversight in the latter commit.

Without this change, the test fails like:

$ make test-all TESTS="../test/ruby/test_process.rb -n test_exec_failure_leaves_no_child" RUN_OPTS="--jit"
...
  1) Failure:
TestProcess#test_exec_failure_leaves_no_child [/home/k0kubun/src/github.com/ruby/ruby/test/ruby/test_process.rb:2493]:
Expected [[26799, #<Process::Status: pid 26799 exit 127>]] to be empty.

Co-Authored-By: Yusuke Endoh <mame@ruby-lang.org>
2020-05-10 00:59:55 -07:00
Yusuke Endoh 91e4e2403e internal/process.h: add a no-warning simple wrapper for fork(2)
As fork(2) is deprecated, its calls must be guarded by
`COMPILER_WARNING_IGNORED(-Wdeprecated-declarations)`.
All usages of fork(2) in process have been alread guarded.  A new call
to fork(2) was added in ruby.c with f22c4ff359.
This caused a build failure on Solaris 11.

It may hide a bug to guard big code unnecessarily, so this change
introduces a simple wrapper "rb_fork" whose definition is guarded, and
replaces all calls to fork(2) with the wrapper function.
2020-05-02 21:34:10 +09:00