зеркало из https://github.com/github/ruby.git
* 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:
Родитель
52aa6ab21d
Коммит
afbd5661a0
|
@ -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.
|
||||
|
||||
|
|
27
process.c
27
process.c
|
@ -4554,6 +4554,11 @@ proc_setmaxgroups(VALUE obj, VALUE val)
|
|||
}
|
||||
|
||||
#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:
|
||||
* Process.daemon() -> 0
|
||||
|
@ -4577,14 +4582,20 @@ proc_daemon(int argc, VALUE *argv)
|
|||
rb_secure(2);
|
||||
rb_scan_args(argc, argv, "02", &nochdir, &noclose);
|
||||
|
||||
#if defined(HAVE_DAEMON)
|
||||
prefork();
|
||||
before_fork();
|
||||
n = daemon(RTEST(nochdir), RTEST(noclose));
|
||||
after_fork();
|
||||
if (n < 0) rb_sys_fail("daemon");
|
||||
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)) {
|
||||
case -1:
|
||||
rb_sys_fail("daemon");
|
||||
|
@ -4599,26 +4610,26 @@ proc_daemon(int argc, VALUE *argv)
|
|||
/* must not be process-leader */
|
||||
switch (rb_fork(0, 0, 0, Qnil)) {
|
||||
case -1:
|
||||
rb_sys_fail("daemon");
|
||||
return -1;
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
if (!RTEST(nochdir))
|
||||
(void)chdir("/");
|
||||
if (!nochdir)
|
||||
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, 1);
|
||||
(void)dup2(n, 2);
|
||||
if (n > 2)
|
||||
(void)close (n);
|
||||
}
|
||||
return INT2FIX(0);
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
#define proc_daemon rb_f_notimplement
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче