Skip to content

Commit dd4e885

Browse files
committed
[GR-40333] Add Process._fork
PullRequest: truffleruby/3691
2 parents 2e5db17 + 69f6139 commit dd4e885

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Compatibility:
8989
* Add optional `Hash` argument to `Enumerable#tally` (#2733, @andrykonchin).
9090
* Update `$LOAD_PATH.resolve_feature_path` to return `nil` instead of raising `LoadError` when feature isn't found (#2733, @andrykonchin).
9191
* Add `objspace/trace` file (#2733, @andrykonchin).
92+
* Add `Process._fork` (#2733, @horakivo).
9293

9394
Performance:
9495

spec/tags/core/process/_fork_tags.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main/ruby/truffleruby/core/io.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ def self.popen(*args)
753753
pipe.set_encoding(external, internal)
754754

755755
if cmd == '-'
756-
Kernel.fork # will throw an error
756+
Process._fork # will throw an error
757757
raise 'unreachable'
758758
else
759759
options = {}

src/main/ruby/truffleruby/core/kernel.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ def at_exit(&block)
767767
module_function :at_exit
768768

769769
def fork
770-
raise NotImplementedError, 'fork is not available'
770+
Process._fork
771771
end
772772
module_function :fork
773773
Primitive.method_unimplement method(:fork)

src/main/ruby/truffleruby/core/process.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,20 @@ def setsid
241241
end
242242

243243
def self.fork
244-
raise NotImplementedError, 'fork is not available'
244+
_fork
245245
end
246246
Primitive.method_unimplement method(:fork)
247247

248+
# An internal API for fork. Do not call this method directly.
249+
# Currently, this is called via Kernel.#fork, Process.fork, and IO.popen("-").
250+
# This method is not for casual code but for application monitoring
251+
# libraries. You can add custom code before and after fork events
252+
# by overriding this method.
253+
def self._fork
254+
raise NotImplementedError, 'fork is not available'
255+
end
256+
Primitive.method_unimplement method(:_fork)
257+
248258
def times
249259
Truffle::FFI::MemoryPointer.new(:double, 4) do |ptr|
250260
ret = Truffle::POSIX.truffleposix_getrusage(ptr)

0 commit comments

Comments
 (0)