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

1078 Коммитов

Автор SHA1 Сообщение Дата
Samuel Williams 86e8a36e77
Revert "Direct access to `fptr->fd` should prefer to use the `internal/io.h`. (#11793)"
This reverts commit 6ea0dcc978 that was accidentally merged.
2024-10-04 08:25:43 +00:00
Samuel Williams 6ea0dcc978
Direct access to `fptr->fd` should prefer to use the `internal/io.h`. (#11793) 2024-10-04 07:44:23 +00:00
Nobuyoshi Nakada dc8c382266
Fix bug at fork on FreeBSD
The main thread in a forked process appears not to own the read-write
lock.
2024-09-19 18:08:12 +09:00
Nobuyoshi Nakada c193ca5218
Adjust indent [ci skip] 2024-09-19 14:33:32 +09:00
Nobuyoshi Nakada d80a81c152
Constify `struct getpwnam_r_args::login` 2024-09-13 09:28:51 +09:00
Jeremy Evans ad761ad2d0 Release GVL for get{pwnam,pwuid,grgid,grnam}_r calls in process.c
Do not release GVL around get{pwuid,pwnam,grgid,grnam} calls,
as doing so is not thread-safe.  Another C extension could have
a concurrent call, and derefencing the returned pointer from
these calls could result in a segfault.

Have rb_home_dir_of call rb_getpwdirnam_for_login if available,
so it can use getpwnam_r and release GVL in a thread-safe manner.

This is related to GVL releasing work in [Bug #20587].
2024-09-12 07:24:02 -07:00
Jean Boussier 63cbe3f6ac Proof of Concept: Allow to prevent fork from happening in known fork unsafe API
[Feature #20590]

For better of for worse, fork(2) remain the primary provider of
parallelism in Ruby programs. Even though it's frowned uppon in
many circles, and a lot of literature will simply state that only
async-signal safe APIs are safe to use after `fork()`, in practice
most APIs work well as long as you are careful about not forking
while another thread is holding a pthread mutex.

One of the APIs that is known cause fork safety issues is `getaddrinfo`.
If you fork while another thread is inside `getaddrinfo`, a mutex
may be left locked in the child, with no way to unlock it.

I think we could reduce the impact of these problem by preventing
in for the most notorious and common cases, by locking around
`fork(2)` and known unsafe APIs with a read-write lock.
2024-09-05 11:43:46 +02:00
Nobuyoshi Nakada 08e142b209 Refactor `getlogin` and `getpw*` functions
- Extract functions to check not-found conditions
- Set the length to the result of `rb_getlogin`
- Reentrant versions return an error numeber but not `errno`
- Check maybe-undefined macros with `defined`
2024-09-05 16:55:54 +09:00
Nobuyoshi Nakada 566f2eb501
Merge `rb_fork_ruby2` into `rb_fork_ruby` 2024-08-19 15:36:49 +09:00
Nobuyoshi Nakada cccffeff2f
Fix missing variable
It seems like no one has tried to compile on a platform without
`setsid` for almost a quarter of a century.
2024-04-07 21:16:26 +09:00
Nobuyoshi Nakada b5b54c19f6
Unify `ERRMSG1` and `ERRMSG2` to `ERRMSG_FMT` variadic macro 2024-04-07 16:43:52 +09:00
Joshua Young e07178d526
[DOC] Fix scope resolution operator typo in `Process#wait` docs 2024-04-01 01:06:10 +00:00
Samuel Williams a7ff264477
Don't clear pending interrupts in the parent process. (#10365) 2024-03-27 10:10:07 +13:00
Nobuyoshi Nakada 5baee82c76
[DOC] Mention about executable file and fallback to sh 2024-03-01 13:11:29 +09:00
Nobuyoshi Nakada 8bff7e996c
[DOC] Move "Execution Shell on Windows" under "Execution Shell" 2024-01-29 17:16:49 +09:00
Nobuyoshi Nakada 2defa9f4ae
[DOC] Elaborate exceptional behaviors on Windows 2024-01-24 12:44:40 +09:00
Nobuyoshi Nakada 769bb924b2
[DOC] Tips for space containing `exe_path` 2024-01-24 12:44:40 +09:00
Nobuyoshi Nakada 623058649e
[DOC] Add Argument `args` subsection 2024-01-24 12:44:40 +09:00
Nobuyoshi Nakada be6e06ef74
[DOC] Separate standard shells per platforms 2024-01-24 12:44:40 +09:00
Nobuyoshi Nakada 828f3ecfcd
[DOC] Move `exe_path` example to `Process` module document
Exchanged with `Kernel.spawn`, like as `Kernel.exec` and
`Kernel.system`.  This description should be common for these methods.
2024-01-24 12:44:39 +09:00
Burdette Lamar df5f2fab93
[DOC] Correction for Process.spawn doc 2024-01-24 12:43:52 +09:00
Nobuyoshi Nakada e2e15ddd67
[DOC] `echo` command may not be a shell built-in 2024-01-21 18:41:41 +09:00
Xavier Noria aad246feba s/SafeStringValue/StringValue/
The macro SafeStringValue() became just StringValue() in c5c05460ac,
and it is deprecated nowadays.

This patch replaces remaining macro usage. Some occurrences are left in
ext/stringio and ext/win32ole, they should be fixed upstream.

The macro itself is not deleted, because it may be used in extensions.
2024-01-12 12:24:48 -08:00
Takuya Aramaki 3e9a612d92
[DOC] Fix wrong description about Process.waitpid2 (#9401) 2024-01-01 21:31:49 +09:00
Takashi Kokubun a164a34110 Resurrect a deprecated code for fixing tests for now
Revert "Remove deprecated code to fix RUBY_DEBUG build failures"

This reverts commit 9614bea2cd.

And changed 3.4 to 3.5. To be fixed properly later.
2023-12-25 01:36:28 -08:00
Takashi Kokubun 9614bea2cd Remove deprecated code to fix RUBY_DEBUG build failures 2023-12-25 01:21:33 -08:00
JP Camara 8782e02138 KQueue support for M:N threads
* Allows macOS users to use M:N threads (and technically FreeBSD, though it has not been verified on FreeBSD)

* Include sys/event.h header check for macros, and include sys/event.h when present

* Rename epoll_fd to more generic kq_fd (Kernel event Queue) for use by both epoll and kqueue

* MAP_STACK is not available on macOS so conditionall apply it to mmap flags

* Set fd to close on exec

* Log debug messages specific to kqueue and epoll on creation

* close_invalidate raises an error for the kqueue fd on child process fork. It's unclear rn if that's a bug, or if it's kqueue specific behavior

Use kq with rb_thread_wait_for_single_fd

* Only platforms with `USE_POLL` (linux) had changes applied to take advantage of kernel event queues. It needed to be applied to the `select` so that kqueue could be properly applied

* Clean up kqueue specific code and make sure only flags that were actually set are removed (or an error is raised)

* Also handle kevent specific errnos, since most don't apply from epoll to kqueue

* Use the more platform standard close-on-exec approach of `fcntl` and `FD_CLOEXEC`. The io-event gem uses `ioctl`, but fcntl seems to be the recommended choice. It is also what Go, Bun, and Libuv use

* We're making changes in this file anyways - may as well fix a couple spelling mistakes while here

Make sure FD_CLOEXEC carries over in dup

* Otherwise the kqueue descriptor should have FD_CLOEXEC, but doesn't and fails in assert_close_on_exec
2023-12-20 16:23:38 +09:00
Victor Shepelev 570d7b2c3e
[DOC] Adjust some new features wording/examples. (#9183)
* Reword Range#overlap? docs last paragraph.

* Docs: add explanation about Queue#freeze

* Docs: Add :rescue event docs for TracePoint

* Docs: Enhance Module#set_temporary_name documentation

* Docs: Slightly expand Process::Status deprecations

* Fix MatchData#named_captures rendering glitch

* Improve Dir.fchdir examples

* Adjust Refinement#target docs
2023-12-14 23:01:48 +02:00
Jean Boussier 9ae6ee5a59 Embed exec_arg objects
They are very ephemeral, so avoiding the malloc churn
is desirable.
2023-11-22 13:04:21 +01:00
Jean Boussier 751d4b9913 Make Process::Status embedded
These are not very common, but they're very easy to convert.
2023-11-21 16:54:24 +01:00
Burdette Lamar d80009d169
[DOC] RDoc for module Process (#8847) 2023-11-08 09:26:27 -05:00
Nobuyoshi Nakada 9059d42c41
Align comment [ci skip] 2023-11-06 14:43:35 +09:00
Koichi Sasada be1bbd5b7d M:N thread scheduler for Ractors
This patch introduce M:N thread scheduler for Ractor system.

In general, M:N thread scheduler employs N native threads (OS threads)
to manage M user-level threads (Ruby threads in this case).
On the Ruby interpreter, 1 native thread is provided for 1 Ractor
and all Ruby threads are managed by the native thread.

From Ruby 1.9, the interpreter uses 1:1 thread scheduler which means
1 Ruby thread has 1 native thread. M:N scheduler change this strategy.

Because of compatibility issue (and stableness issue of the implementation)
main Ractor doesn't use M:N scheduler on default. On the other words,
threads on the main Ractor will be managed with 1:1 thread scheduler.

There are additional settings by environment variables:

`RUBY_MN_THREADS=1` enables M:N thread scheduler on the main ractor.
Note that non-main ractors use the M:N scheduler without this
configuration. With this configuration, single ractor applications
run threads on M:1 thread scheduler (green threads, user-level threads).

`RUBY_MAX_CPU=n` specifies maximum number of native threads for
M:N scheduler (default: 8).

This patch will be reverted soon if non-easy issues are found.

[Bug #19842]
2023-10-12 14:47:01 +09:00
Nobuyoshi Nakada 457971f4e2
[DOC] State the precision of `Process.times` as platform-defined
Remove the bad example that can lead to misunderstanding as if this
precision is defined in Ruby.
2023-10-03 14:42:47 +09:00
Burdette Lamar f9490110e1
[DOC] Another example for spawn (#8575) 2023-10-01 19:37:40 -04:00
BurdetteLamar 84312e688f [DOC] Fix minor inconsistencies 2023-09-27 14:42:50 -04:00
Peter Zhu 154bd04ee2 [DOC] Fix link in process.c 2023-09-26 11:28:36 -04:00
BurdetteLamar a40ab12768 [DOC] Refactor doc in process.c 2023-09-26 11:26:19 -04:00
Jean Boussier efe2822708 Process.warmup: invoke `malloc_trim` if available
Similar to releasing free GC pages, releasing free malloc pages
reduce the amount of page faults post fork.
2023-09-15 17:45:21 +02:00
Nobuyoshi Nakada 998ae7c3f3
[Bug #19868] Deprecate `Process::Status#&` and `Process::Status#>>` 2023-09-14 15:26:25 +09:00
Nobuyoshi Nakada b6de0a6c69
[Bug #19868] Suggest other Process::Status method for `&` and `>>`
`Process::Status#&` and `Process::Status#>>` are provided only for
the backward compatibility with older Ruby than 1.8 where `$?` was
a `Fixnum`, and the knowledge about internals of system dependent
macros is necessary to use them.  Modern programs and libraries
should not need these methods.
2023-09-14 14:57:57 +09:00
Nobuyoshi Nakada efe5e6e8d0
Negative value to Process::Status method for compatibility 2023-09-14 14:38:14 +09:00
Burdette Lamar 5edabd1cd5
[DOC] RDoc for Process::Status (#8416) 2023-09-12 16:31:31 -04:00
Nobuyoshi Nakada ac65fc833d
[DOC] Fix up Process::Status#>> 2023-09-07 10:05:10 +09:00
Burdette Lamar 54274b8c65
[DOC] Rdoc for Process::Status (#8386) 2023-09-06 18:26:11 -04:00
Burdette Lamar a17a1cd535
[DOC] Fix for RDoc for Process.kill (#8370) 2023-09-05 12:53:11 -04:00
Nobuyoshi Nakada 5b157997e2
[DOC] Fix up markup 2023-09-05 21:09:41 +09:00
Nobuyoshi Nakada 7c8932365f
[DOC] Fix signal list
- Signal names can be symbols, as stated above.
- Supported signals and those values are platform dependent.
- Key sequences to send signal are configurable.
- Fix description of signal 0.

Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2023-09-05 20:36:45 +09:00
Burdette Lamar c9af911489
[DOC] RDoc for process.c (#8366) 2023-09-04 21:16:48 -04:00
Burdette Lamar 40ab77eb3d
[DOC] Process doc (#8363) 2023-09-03 15:36:51 -04:00