mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Ignore EPERM which means already being process-leader
This commit is contained in:
parent
b4546d26f2
commit
55e540f7ab
2 changed files with 6 additions and 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("/");
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue