* process.c (rb_daemon): split from proc_daemon.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-07-13 12:31:17 +00:00
Родитель 52aa6ab21d
Коммит afbd5661a0
2 изменённых файлов: 22 добавлений и 9 удалений

Просмотреть файл

@ -1,4 +1,6 @@
Tue Jul 13 21:28:35 2010 Nobuyoshi Nakada <nobu@ruby-lang.org> Tue Jul 13 21:31:15 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* process.c (rb_daemon): split from proc_daemon.
* process.c (rb_fork_err): suppress gcc 4.4 warnings. * process.c (rb_fork_err): suppress gcc 4.4 warnings.

Просмотреть файл

@ -4554,6 +4554,11 @@ proc_setmaxgroups(VALUE obj, VALUE val)
} }
#if defined(HAVE_DAEMON) || (defined(HAVE_FORK) && defined(HAVE_SETSID)) #if defined(HAVE_DAEMON) || (defined(HAVE_FORK) && defined(HAVE_SETSID))
#ifndef HAVE_DAEMON
static int rb_daemon(int nochdir, int noclose);
#define daemon(nochdir, noclose) rb_daemon(nochdir, noclose)
#endif
/* /*
* call-seq: * call-seq:
* Process.daemon() -> 0 * Process.daemon() -> 0
@ -4577,14 +4582,20 @@ proc_daemon(int argc, VALUE *argv)
rb_secure(2); rb_secure(2);
rb_scan_args(argc, argv, "02", &nochdir, &noclose); rb_scan_args(argc, argv, "02", &nochdir, &noclose);
#if defined(HAVE_DAEMON)
prefork(); prefork();
before_fork(); before_fork();
n = daemon(RTEST(nochdir), RTEST(noclose)); n = daemon(RTEST(nochdir), RTEST(noclose));
after_fork(); after_fork();
if (n < 0) rb_sys_fail("daemon"); if (n < 0) rb_sys_fail("daemon");
return INT2FIX(n); return INT2FIX(n);
#elif defined(HAVE_FORK) }
#ifndef HAVE_DAEMON
static int
rb_daemon(int nochdir, int noclose)
{
int n, err = 0;
switch (rb_fork(0, 0, 0, Qnil)) { switch (rb_fork(0, 0, 0, Qnil)) {
case -1: case -1:
rb_sys_fail("daemon"); rb_sys_fail("daemon");
@ -4599,26 +4610,26 @@ proc_daemon(int argc, VALUE *argv)
/* must not be process-leader */ /* must not be process-leader */
switch (rb_fork(0, 0, 0, Qnil)) { switch (rb_fork(0, 0, 0, Qnil)) {
case -1: case -1:
rb_sys_fail("daemon"); return -1;
case 0: case 0:
break; break;
default: default:
_exit(EXIT_SUCCESS); _exit(EXIT_SUCCESS);
} }
if (!RTEST(nochdir)) if (!nochdir)
(void)chdir("/"); err = chdir("/");
if (!RTEST(noclose) && (n = open("/dev/null", O_RDWR, 0)) != -1) { if (!noclose && (n = open("/dev/null", O_RDWR, 0)) != -1) {
(void)dup2(n, 0); (void)dup2(n, 0);
(void)dup2(n, 1); (void)dup2(n, 1);
(void)dup2(n, 2); (void)dup2(n, 2);
if (n > 2) if (n > 2)
(void)close (n); (void)close (n);
} }
return INT2FIX(0); return err;
#endif
} }
#endif
#else #else
#define proc_daemon rb_f_notimplement #define proc_daemon rb_f_notimplement
#endif #endif