[前][次][番号順一覧][スレッド一覧]

ruby-changes:73622

From: Nobuyoshi <ko1@a...>
Date: Tue, 20 Sep 2022 11:25:12 +0900 (JST)
Subject: [ruby-changes:73622] 55e540f7ab (master): Ignore EPERM which means already being process-leader

https://git.ruby-lang.org/ruby.git/commit/?id=55e540f7ab

From 55e540f7ab6adb3ea0de16912dfde8e0bf94cc6e Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 20 Sep 2022 11:12:11 +0900
Subject: Ignore EPERM which means already being process-leader

---
 process.c                 | 3 ++-
 test/ruby/test_process.rb | 6 ++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/process.c b/process.c
index a3d3bcbb78..735dd2d855 100644
--- a/process.c
+++ b/process.c
@@ -7115,7 +7115,8 @@ rb_daemon(int nochdir, int noclose) https://github.com/ruby/ruby/blob/trunk/process.c#L7115
       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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1881
         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
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]