diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-09-20 11:12:11 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-09-20 11:12:11 +0900 |
commit | 55e540f7ab6adb3ea0de16912dfde8e0bf94cc6e (patch) | |
tree | dc5a68bc34e620f06102f5735f6e254889004d67 | |
parent | b4546d26f297d25c0e03f5f09864e7b371d65fa8 (diff) | |
download | ruby-55e540f7ab6adb3ea0de16912dfde8e0bf94cc6e.tar.gz |
Ignore EPERM which means already being process-leader
-rw-r--r-- | process.c | 3 | ||||
-rw-r--r-- | test/ruby/test_process.rb | 6 |
2 files changed, 6 insertions, 3 deletions
@@ -7115,7 +7115,8 @@ rb_daemon(int nochdir, int noclose) default: _exit(EXIT_SUCCESS); } - if (setsid() < 0) return -1; + /* ignore EPERM which means already being process-leader */ + if (setsid() < 0) (void)0; if (!nochdir) err = chdir("/"); diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 6340f622fc..10c4aadadf 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -1881,17 +1881,19 @@ class TestProcess < Test::Unit::TestCase if f assert_equal(f.pid, Process.wait(f.pid)) - dpid, ppid = Integer(f.gets), Integer(f.gets) + dpid, ppid, dsid = 3.times.map {Integer(f.gets)} message = "daemon #{dpid} should be detached" assert_not_equal($$, ppid, message) # would be 1 almost always assert_raise(Errno::ECHILD, message) {Process.wait(dpid)} assert_kind_of(Integer, Process.kill(0, dpid), message) + assert_equal(dpid, dsid) break # close f, and let the daemon resume and exit end + Process.setsid rescue nil Process.daemon(false, true) - puts $$, Process.ppid + puts $$, Process.ppid, Process.getsid $stdin.gets # wait for the above assertions using signals end end |