summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-13 12:31:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-13 12:31:17 +0000
commitafbd5661a0ca041ac818c9e5732911c5db21c9f9 (patch)
tree5b570c1e050c6c76a51def84c14ed77107f32ffe /process.c
parent52aa6ab21dcf2e0c6cb0190fbc4f8276248ade6b (diff)
downloadruby-afbd5661a0ca041ac818c9e5732911c5db21c9f9.tar.gz
* 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
Diffstat (limited to 'process.c')
-rw-r--r--process.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/process.c b/process.c
index 8e601ba850..84fed6053c 100644
--- a/process.c
+++ b/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