summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-01 23:25:10 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-01 23:25:10 +0000
commit4dcaa9e5aae6cc9fa3b5bfb1dc7b0d9365e10e13 (patch)
treef138cc63259c874d4189b665acec83643a5e6140 /process.c
parent893c123bfb229e3f6079a521a858bec50cf43248 (diff)
* process.c (ruby_setsid): split from proc_setsid.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27170 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/process.c b/process.c
index 00f8aa38e0..e566e9b753 100644
--- a/process.c
+++ b/process.c
@@ -3389,6 +3389,10 @@ proc_setpgid(VALUE obj, VALUE pid, VALUE pgrp)
#if defined(HAVE_SETSID) || (defined(HAVE_SETPGRP) && defined(TIOCNOTTY))
+#if !defined(HAVE_SETSID)
+static rb_pid_t ruby_setsid(void);
+#define setsid() ruby_setsid()
+#endif
/*
* call-seq:
* Process.setsid => fixnum
@@ -3403,18 +3407,22 @@ proc_setpgid(VALUE obj, VALUE pid, VALUE pgrp)
static VALUE
proc_setsid(void)
{
-#if defined(HAVE_SETSID)
rb_pid_t pid;
rb_secure(2);
pid = setsid();
if (pid < 0) rb_sys_fail(0);
return PIDT2NUM(pid);
-#elif defined(HAVE_SETPGRP) && defined(TIOCNOTTY)
+}
+
+#if !defined(HAVE_SETSID)
+#define HAVE_SETSID 1
+static rb_pid_t
+ruby_setsid(void)
+{
rb_pid_t pid;
int ret;
- rb_secure(2);
pid = getpid();
#if defined(SETPGRP_VOID)
ret = setpgrp();
@@ -3424,15 +3432,15 @@ proc_setsid(void)
#else
ret = setpgrp(0, pid);
#endif
- if (ret == -1) rb_sys_fail(0);
+ if (ret == -1) return -1;
if ((fd = open("/dev/tty", O_RDWR)) >= 0) {
ioctl(fd, TIOCNOTTY, NULL);
close(fd);
}
- return PIDT2NUM(pid);
-#endif
+ return pid;
}
+#endif
#else
#define proc_setsid rb_f_notimplement
#endif
@@ -4531,7 +4539,7 @@ proc_setmaxgroups(VALUE obj, VALUE val)
return INT2FIX(maxgroups);
}
-#if defined(HAVE_DAEMON) || defined(HAVE_FORK)
+#if defined(HAVE_DAEMON) || (defined(HAVE_FORK) && defined(HAVE_SETSID))
/*
* call-seq:
* Process.daemon() => 0