Ignore EPERM which means already being process-leader
This commit is contained in:
parent
b4546d26f2
commit
55e540f7ab
@ -7115,7 +7115,8 @@ rb_daemon(int nochdir, int noclose)
|
|||||||
default: _exit(EXIT_SUCCESS);
|
default: _exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsid() < 0) return -1;
|
/* ignore EPERM which means already being process-leader */
|
||||||
|
if (setsid() < 0) (void)0;
|
||||||
|
|
||||||
if (!nochdir)
|
if (!nochdir)
|
||||||
err = chdir("/");
|
err = chdir("/");
|
||||||
|
@ -1881,17 +1881,19 @@ class TestProcess < Test::Unit::TestCase
|
|||||||
if f
|
if f
|
||||||
assert_equal(f.pid, Process.wait(f.pid))
|
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"
|
message = "daemon #{dpid} should be detached"
|
||||||
assert_not_equal($$, ppid, message) # would be 1 almost always
|
assert_not_equal($$, ppid, message) # would be 1 almost always
|
||||||
assert_raise(Errno::ECHILD, message) {Process.wait(dpid)}
|
assert_raise(Errno::ECHILD, message) {Process.wait(dpid)}
|
||||||
assert_kind_of(Integer, Process.kill(0, dpid), message)
|
assert_kind_of(Integer, Process.kill(0, dpid), message)
|
||||||
|
assert_equal(dpid, dsid)
|
||||||
|
|
||||||
break # close f, and let the daemon resume and exit
|
break # close f, and let the daemon resume and exit
|
||||||
end
|
end
|
||||||
|
Process.setsid rescue nil
|
||||||
Process.daemon(false, true)
|
Process.daemon(false, true)
|
||||||
puts $$, Process.ppid
|
puts $$, Process.ppid, Process.getsid
|
||||||
$stdin.gets # wait for the above assertions using signals
|
$stdin.gets # wait for the above assertions using signals
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user