From ea2c9da96fc364f7b6a8f41e3304ae53d63d5cad Mon Sep 17 00:00:00 2001 From: nagachika Date: Fri, 4 Oct 2013 16:25:39 +0000 Subject: merge revision(s) 40534,41886,41903,41910: [Backport #8616] process.c: rb_daemon should not raise * process.c (rb_daemon): should not raise exceptions, since proc_daemon() will deal with errors. * process.c (fork_daemon): kill the other threads all and abandon the kept mutexes. * process.c (fork_daemon): kill the other threads all and abandon the kept mutexes. * process.c (rb_daemon): daemon(3) is implemented with fork(2). Therefore it needs rb_thread_atfork(). (and revert r41903) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@43142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- process.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'process.c') diff --git a/process.c b/process.c index 34a38cb18e..c03fc1dfaa 100644 --- a/process.c +++ b/process.c @@ -5667,29 +5667,23 @@ rb_daemon(int nochdir, int noclose) before_fork(); err = daemon(nochdir, noclose); after_fork(); + rb_thread_atfork(); #else int n; - switch (rb_fork_ruby(NULL)) { - case -1: - rb_sys_fail("daemon"); - case 0: - break; - default: - _exit(EXIT_SUCCESS); +#define fork_daemon() \ + switch (rb_fork_ruby(NULL)) { \ + case -1: return -1; \ + case 0: rb_thread_atfork(); break; \ + default: _exit(EXIT_SUCCESS); \ } - proc_setsid(); + fork_daemon(); + + if (setsid() < 0) return -1; /* must not be process-leader */ - switch (rb_fork_ruby(NULL)) { - case -1: - return -1; - case 0: - break; - default: - _exit(EXIT_SUCCESS); - } + fork_daemon(); if (!nochdir) err = chdir("/"); -- cgit v1.2.3