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

1078 Коммитов

Автор SHA1 Сообщение Дата
BurdetteLamar 3602e253e7 [DOC] RDoc for process.c 2023-09-02 19:46:35 -04:00
Burdette Lamar ef4dab6983
[DOC] RDoc for process.c (#8358) 2023-09-02 11:43:10 -04:00
Burdette Lamar cfcb4a4e26
[DOC] RDoc for process.c (#8353) 2023-09-02 09:04:04 -04:00
Burdette Lamar 84fa8ae84e
[DOC] RDoc for #spawn (#8342) 2023-08-31 14:02:09 -04:00
Burdette Lamar eb3d94f4ba
[DOC] RDoc for Kernel#system (#8309) 2023-08-31 09:06:11 -04:00
Samuel Williams e46e48d690
Expose `rb_process_status_wait` and hide `rb_process_status_waitv`. (#8316) 2023-08-29 22:24:55 +12:00
Samuel Williams 901b6d9c50
Validate the typed data before dereferencing the internal struct. (#8315) 2023-08-29 20:04:14 +12:00
Burdette Lamar 1cc700907d
[DOC] More on method exec (#8302) 2023-08-27 13:39:18 -04:00
Peter Zhu b7237e3bbd Free all empty heap pages in Process.warmup
This commit adds `free_empty_pages` which frees all empty heap pages and
moves the number of pages freed to the allocatable pages counter. This
is used in Process.warmup to improve performance because page
invalidation from copy-on-write is slower than allocating a new page.
2023-08-27 09:39:29 -04:00
Burdette Lamar f9aea75747
[DOC] RDoc for Process (#8282) 2023-08-24 17:41:43 -04:00
Burdette Lamar 75c9c2c431
[DOC] Process doc (#8279) 2023-08-24 13:46:14 -04:00
Bo Anderson 84a12d6578 Fix compile error on older systems without clock_get* 2023-08-24 19:09:06 +09:00
Burdette Lamar 7e0d2c6143
[DOC] RDoc for Process (#8253) 2023-08-23 23:21:44 -04:00
Burdette Lamar 589c01c411
[DOC] RDoc for Process (#8179) 2023-08-07 09:51:03 -04:00
Burdette Lamar 533dcb8e52
RDoc for module Process (#8141) 2023-07-31 21:44:56 -04:00
Nobuyoshi Nakada 8b390a456c
[DOC] Update description of `Process.daemon` arguments
These arguments can only be `true` or `false` now.  Also add markups.
2023-08-01 01:47:19 +09:00
Jean Boussier 9b405a18be Process.warmup: precompute strings coderange
This both save time for when it will be eventually needed,
and avoid mutating heap pages after a potential fork.

Instrumenting some large Rails app, I've witnessed up to
58% of String instances having their coderange still unknown.
2023-07-26 11:41:23 +02:00
Jean Boussier fa30b99c34 Implement Process.warmup
[Feature #18885]

For now, the optimizations performed are:

  - Run a major GC
  - Compact the heap
  - Promote all surviving objects to oldgen

Other optimizations may follow.
2023-07-17 11:20:15 +02:00
Nobuyoshi Nakada c8d0470bb0
Use `File::NULL` instead of hard coded null device names 2023-07-10 19:21:47 +09:00
Samuel Williams a218ed5692
Hide the usage of `rb_io_t` where possible. (#7880)
This retries the compatible parts of the previously reverted PR so we can continue to update related code without breaking backwards compatibility.
2023-06-01 14:23:30 +09:00
NARUSE, Yui 85dcc4866d Revert "Hide most of the implementation of `struct rb_io`. (#6511)"
This reverts commit 18e55fc1e1.

fix [Bug #19704]
https://bugs.ruby-lang.org/issues/19704
This breaks compatibility for extension libraries. Such changes
need a discussion.
2023-06-01 08:43:22 +09:00
Samuel Williams 18e55fc1e1
Hide most of the implementation of `struct rb_io`. (#6511)
* Add rb_io_path and rb_io_open_descriptor.

* Use rb_io_open_descriptor to create PTY objects

* Rename FMODE_PREP -> FMODE_EXTERNAL and expose it

FMODE_PREP I believe refers to the concept of a "pre-prepared" file, but
FMODE_EXTERNAL is clearer about what the file descriptor represents and
aligns with language in the IO::Buffer module.

* Ensure that rb_io_open_descriptor closes the FD if it fails

If FMODE_EXTERNAL is not set, then it's guaranteed that Ruby will be
responsible for closing your file, eventually, if you pass it to
rb_io_open_descriptor, even if it raises an exception.

* Rename IS_EXTERNAL_FD -> RUBY_IO_EXTERNAL_P

* Expose `rb_io_closed_p`.

* Add `rb_io_mode` to get IO mode.

---------

Co-authored-by: KJ Tsanaktsidis <ktsanaktsidis@zendesk.com>
2023-05-30 10:02:40 +09:00
Nobuyoshi Nakada 7f7a8fa555
Put `rb_fork` back into process.c
Now, calling `rb_fork` directly breaks the PID cache and the timer
thread, so must use `rb_fork_ruby` or similar instead.
2023-05-21 23:00:27 +09:00
Nobuyoshi Nakada 3612b1bed8 [Feature #19590] Show the invalid clock argument
Include the failed clock argument in the error message from
`Process.clock_gettime` and `Process.clock_getres`.
2023-04-13 14:07:27 +09:00
Daniel DeLorme 4b100f75d2 [DOC] Clarify behavior of abort() with no argument
Since Ruby 2.7 it prints the message and backtrace of $!

Fixes [Bug #19578]
2023-04-05 07:37:07 -07:00
Aaron Patterson 8525603c72
Revert "Fix transient heap mode"
This reverts commit 87253d047c.

Revert "Implement `Process.warmup`"

This reverts commit ba6ccd8714.
2023-04-04 12:59:14 -07:00
Jean Boussier ba6ccd8714 Implement `Process.warmup`
[Feature #18885]

For now, the optimizations performed are:

  - Run a major GC
  - Compact the heap
  - Promote all surviving objects to oldgen

Other optimizations may follow.
2023-04-04 19:49:08 +02:00
Nobuyoshi Nakada 1d529f382c
PID cache is never cleared where `fork` is not used 2023-04-04 11:29:57 +09:00
Nobuyoshi Nakada 3e7d1cbceb Cache pid itself instead of converted VALUE 2023-03-24 14:22:02 +09:00
Jean Boussier 3563e1383f thread_pthread.c: Use a `fork_gen` to protect against fork instead of getpid()
[Feature #19443]

Until recently most libc would cache `getpid()` so this was a cheap check to make.

However as of glibc version 2.25 the PID cache is removed and calls to getpid() always
invoke the actual system call which significantly degrades the performance of existing applications.

The reason glibc removed the cache is that some libraries were bypassing fork(2)
by issuing system calls themselves, causing stale cache issues.

That isn't a concern for Ruby as bypassing MRI's primitive for forking would
render the VM unusable, so we can safely cache the PID.
2023-03-23 09:08:19 +00:00
Peter Zhu 3210130993 Suppress a compiler warning on GCC in process.c
rb_pid_t is 32 bits on some platforms, which will cause a warning on GCC
due to POSFIXABLE always returning true.

    include/ruby/internal/arithmetic/fixnum.h:43:31: warning: comparison is always true due to limited range of data type [-Wtype-limits]
2023-03-22 17:25:18 -04:00
Nobuyoshi Nakada 758e4db551
Mark cached pid if necessary 2023-03-20 18:08:05 +09:00
Jean Boussier 1db8951d3a Cache `Process.pid`
[Feature #19443]

It's not uncommon for database client and similar network libraries
to protect themselves from Process.fork by regularly checking Process.pid

Until recently most libc would cache `getpid()` so this was a cheap
check to make.

However as of glibc version 2.25 the PID cache is removed and calls to
`getpid()` always invoke the actual system call which significantly degrades
the performance of existing applications.

The reason glibc removed the cache is that some libraries were bypassing
`fork(2)` by issuing system calls themselves, causing stale cache issues.

That isn't a concern for Ruby as bypassing MRI's primitive for forking
would render the VM unusable, so we can safely cache the PID.
2023-03-20 08:21:23 +00:00
Samuel Williams 7fd53eeb46
Remove SIGCHLD `waidpid`. (#7527)
* Remove `waitpid_lock` and related code.

* Remove un-necessary test.

* Remove `rb_thread_sleep_interruptible` dead code.
2023-03-15 19:48:27 +13:00
Samuel Williams ac65ce16e9
Revert SIGCHLD changes to diagnose CI failures. (#7517)
* Revert "Remove special handling of `SIGCHLD`. (#7482)"

This reverts commit 44a0711eab.

* Revert "Remove prototypes for functions that are no longer used. (#7497)"

This reverts commit 4dce12bead.

* Revert "Remove SIGCHLD `waidpid`. (#7476)"

This reverts commit 1658e7d966.

* Fix change to rjit variable name.
2023-03-14 20:07:59 +13:00
Samuel Williams 4dce12bead
Remove prototypes for functions that are no longer used. (#7497) 2023-03-10 23:38:09 +13:00
Samuel Williams 86d38b4520
Accept `sleep(nil)` as sleep forever. (#7484) 2023-03-10 16:40:05 +13:00
Samuel Williams 1658e7d966
Remove SIGCHLD `waidpid`. (#7476)
* Remove `waitpid_lock` and related code.

* Remove un-necessary test.

* Remove `rb_thread_sleep_interruptible` dead code.
2023-03-09 16:05:47 +13:00
Takashi Kokubun 9ad19069f9 Remove obsoleted functions in rjit.c 2023-03-07 23:59:50 -08:00
Takashi Kokubun b67f07fa2c Get rid of MJIT's special fork 2023-03-07 23:08:57 -08:00
Takashi Kokubun 23ec248e48 s/mjit/rjit/ 2023-03-06 23:44:01 -08:00
Takashi Kokubun 2e875549a9 s/MJIT/RJIT/ 2023-03-06 23:44:01 -08:00
zverok 01509f344a [DOC] Restore Process module doc lost due to RDoc update 2023-02-19 22:32:52 +02:00
Maciek Rząsa 50c6cabadc
[DOC] Change formatting in the exec docs
The last part of the sentence was accidentally put in enumeration, It
made an impression that it's one of the rules, not the result of
applying the rules.
2022-11-19 11:38:16 +09:00
S-H-GAMELINKS 1f4f6c9832 Using UNDEF_P macro 2022-11-16 18:58:33 +09:00
Hiroshi SHIBATA 6b0b326ef2 Followed up 796069b288 2022-09-22 11:35:28 +09:00
David Carlier 796069b288 getrlimit adding RLIMIT_NPTS constant. 2022-09-21 18:07:59 +09:00
Koichi ITO e3b178066b [DOC] Tweak the doc for `Process.kill` signature
Replacing `...` with `*pids` seems to clarify the expected variadic arguments.

Note that the expected arguments are two or more with a signal and pids.
That is, the method must have at least one pid, which cannot be omitted:

```console
% ruby -e 'Process.kill(0)'
-e:1:in `kill': wrong number of arguments (given 1, expected 2+) (ArgumentError)
        from -e:1:in `<main>'
```
2022-09-21 15:21:27 +09:00
Nobuyoshi Nakada 55e540f7ab
Ignore EPERM which means already being process-leader 2022-09-20 11:12:11 +09:00
Nobuyoshi Nakada ae07336529 Reduce fork calls in daemon
The forked child process is a grandchild process from the viewpoint of
the process which invoked the caller process.  That means the child is
detached at that point, and it does not need to fork twice.
2022-09-19 15:34:16 +09:00
Takashi Kokubun aa8a3b2358
MJIT: Do not hang after forking with threads
First, rb_mjit_fork should call rb_thread_atfork to stop threads after
fork in the child process. Unfortunately, we cannot use rb_fork_ruby to
prevent this kind of mistakes because MJIT needs special handling of
waiting_pid and mjit_pause/resume.

Second, mjit_waitpid_finished should be checked regardless of
trap_interrupt. It doesn't seem like the flag is not set when SIGCHLD is
handled for an MJIT child process.
2022-09-11 09:09:05 +09:00
Takashi Kokubun f6d569b7c0
Call appropriate hooks on MJIT's fork
This takes care of signal_self_pipe and other things.
2022-09-04 18:22:25 -07:00
Nobuyoshi Nakada b2205cd45c Short-circuit `Process._fork` 2022-08-12 16:57:56 +09:00
Nobuyoshi Nakada e545cfad20
Stop using casted `rb_syswait` as `proc_syswait`
The argument of `rb_syswait` is now `rb_pid_t` which may differ from
`int`.  Also it is an undefined behavior to take the result of casted
void function (in `rb_protect`).
2022-08-07 00:02:38 +09:00
Nobuyoshi Nakada f245b425af
Fix the sizes comparison
`proc_syswait` will be called with a `VALUE` argument.
2022-08-06 23:56:44 +09:00
Ivo Anjo 74817f3d37
[DOC] Process._fork does not get called by Process.daemon
As discussed in [Bug #18911], I'm adding some documentation to
`Process._fork` to clarify that it is not expected to cover
calls to `Process.daemon`.

[Bug #18911]: https://bugs.ruby-lang.org/issues/18911

Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
2022-08-05 18:40:48 +09:00
Takashi Kokubun 5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Nobuyoshi Nakada 5e66525e41
[DOC] Document `Process::Tms` 2022-06-28 20:19:05 +09:00
Nobuyoshi Nakada a58611dfb1 Allow to just warn as bool expected, without an exception 2022-06-20 19:35:12 +09:00
Takashi Kokubun 1162523bae
Remove MJIT worker thread (#6006)
[Misc #18830]
2022-06-15 09:40:54 -07:00
Peter Zhu 54b53e2c8f [ci skip] Fix docs 2022-04-13 10:43:23 -04:00
Burdette Lamar 70415071e8
Fix some RDoc links (#5778) 2022-04-08 14:25:38 -05:00
Nobuyoshi Nakada 42a0bed351
Prefix ccan headers (#4568)
* Prefixed ccan headers

* Remove unprefixed names in ccan/build_assert

* Remove unprefixed names in ccan/check_type

* Remove unprefixed names in ccan/container_of

* Remove unprefixed names in ccan/list

Co-authored-by: Samuel Williams <samuel.williams@oriontransfer.co.nz>
2022-03-30 20:36:31 +13:00
Thierry Joyal 9cbebdcb74 [DOC] Fix documentation typo for Process#clock_gettime
Fixes [Misc #18610]
2022-03-07 13:02:01 +01:00
Nobuyoshi Nakada 4641abf0a2 Use symbols for clock IDs if `clockid_t` is not numeric 2022-02-19 15:33:15 +09:00
Nobuyoshi Nakada b3de25dfee Set static IDs to same name variables 2022-02-19 15:33:15 +09:00
Burdette Lamar e9a2b30744
Enhanced RDoc concerning command injection (#5537)
Clarifies security vulnerabilities for commands.

Treats:

    Kernel.system
    Kernel.` (backtick)
    IO.popen
    IO.read
    IO.write
    IO.binread
    IO.binwrite
    IO.readlines
    IO.foreach
2022-02-18 06:46:04 -06:00
Kevin Newton fc6fd4c31e Accurately report VM memsize
Currently the calculation only counts the size of the struct. This commit adds the size of the associated st tables, id tables, and linked lists.

Still missing is the size of the ractors and (potentially) the size of the object space.
2022-01-21 14:34:53 -08:00
Nobuyoshi Nakada 2f0f56bdca
[DOC] Enhanced Process.groups related
* On some platforms (e.g., macOS), the user's default group access
  list may exceed `NGROUPS_MAX`.
* Use upcase "GID" instead of "gid" for other than variable names.
2022-01-19 12:04:08 +09:00
Peter Zhu ffda21b7ba [Feature #18491] Drop support for HP-UX
IA64 support was dropped in ticket #15894, so we can drop support for
HP-UX.
2022-01-18 09:52:15 -05:00
S-H-GAMELINKS 804a714971 Replace to RBOOL macro 2022-01-17 13:49:37 +09:00
Matheus Richard b563f12297
[DOC] Fix docs rendering for Process._fork [ci skip]
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2021-12-15 07:15:02 +09:00
S.H 75aae66c4f
Some codes replace to `RBOOL` macro (#5023)
* Some code replace and using RBOOL macro

* Fix indent

* Using RBOOL in syserr_eqq function
2021-11-09 17:09:29 +09:00
Yusuke Endoh 13068ebe32
process.c: Add Process._fork (#5017)
* process.c: Add Process._fork

This API is supposed for application monitoring libraries to hook fork
event.

[Feature #17795]

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2021-10-25 20:47:19 +09:00
Nobuyoshi Nakada 1d9e129255
Fill pid and error in the status 2021-10-19 16:41:09 +09:00
Samuel Williams bf3e314852 Rework order of operations to better handle last_status. 2021-09-22 18:50:26 +12:00
Samuel Williams 7db021f83b Add support for non-blocking `Kernel.system`. 2021-09-22 18:50:26 +12:00
Jeremy Evans 57d315c937 Handle overwriting Object::ENV in spawn
Instead of looking for Object::ENV (which can be overwritten),
directly look for the envtbl variable.  As that is static in hash.c,
and the lookup code is in process.c, add a couple non-static
functions that will return envtbl (or envtbl#to_hash).

Fixes [Bug #18164]
2021-09-14 05:55:14 -09:00
S-H-GAMELINKS bdd6d8746f Replace RBOOL macro 2021-09-05 23:01:27 +09:00
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