* process.c (forked_child): new variable.
(before_exec): don't call rb_thread_stop_timer_thread if forked_child. (after_exec): reset forked_child after rb_thread_start_timer_thread. (rb_fork): set forked_child just after fork in child. * ext/pty/pty.c (chfunc): extracted from establishShell. (establishShell): use rb_fork. [ruby-dev:37418] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f3634e5dc8
commit
6e03277db0
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
|||||||
|
Sun Dec 14 01:35:48 2008 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* process.c (forked_child): new variable.
|
||||||
|
(before_exec): don't call rb_thread_stop_timer_thread if
|
||||||
|
forked_child.
|
||||||
|
(after_exec): reset forked_child after rb_thread_start_timer_thread.
|
||||||
|
(rb_fork): set forked_child just after fork in child.
|
||||||
|
|
||||||
|
* ext/pty/pty.c (chfunc): extracted from establishShell.
|
||||||
|
(establishShell): use rb_fork.
|
||||||
|
|
||||||
|
[ruby-dev:37418]
|
||||||
|
|
||||||
Sat Dec 13 22:17:30 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
Sat Dec 13 22:17:30 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
||||||
|
|
||||||
* common.mk (help): describes more targets.
|
* common.mk (help): describes more targets.
|
||||||
|
@ -143,44 +143,23 @@ pty_exec(VALUE v)
|
|||||||
return rb_f_exec(arg->argc, arg->argv);
|
return rb_f_exec(arg->argc, arg->argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
struct child_info {
|
||||||
establishShell(int argc, VALUE *argv, struct pty_info *info,
|
|
||||||
char SlaveName[DEVICELEN])
|
|
||||||
{
|
|
||||||
int master, slave;
|
int master, slave;
|
||||||
rb_pid_t pid;
|
int argc;
|
||||||
char *p, tmp, *getenv();
|
VALUE *argv;
|
||||||
struct passwd *pwent;
|
};
|
||||||
VALUE v;
|
|
||||||
|
int chfunc(void *data)
|
||||||
|
{
|
||||||
|
struct child_info *carg = data;
|
||||||
|
int master = carg->master;
|
||||||
|
int slave = carg->slave;
|
||||||
|
int argc = carg->argc;
|
||||||
|
VALUE *argv = carg->argv;
|
||||||
|
|
||||||
struct exec_info arg;
|
struct exec_info arg;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (argc == 0) {
|
|
||||||
const char *shellname;
|
|
||||||
|
|
||||||
if ((p = getenv("SHELL")) != NULL) {
|
|
||||||
shellname = p;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
pwent = getpwuid(getuid());
|
|
||||||
if (pwent && pwent->pw_shell)
|
|
||||||
shellname = pwent->pw_shell;
|
|
||||||
else
|
|
||||||
shellname = "/bin/sh";
|
|
||||||
}
|
|
||||||
v = rb_str_new2(shellname);
|
|
||||||
argc = 1;
|
|
||||||
argv = &v;
|
|
||||||
}
|
|
||||||
getDevice(&master, &slave, SlaveName);
|
|
||||||
|
|
||||||
if ((pid = fork()) < 0) {
|
|
||||||
close(master);
|
|
||||||
close(slave);
|
|
||||||
rb_sys_fail("fork failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pid == 0) { /* child */
|
|
||||||
/*
|
/*
|
||||||
* Set free from process group and controlling terminal
|
* Set free from process group and controlling terminal
|
||||||
*/
|
*/
|
||||||
@ -237,6 +216,49 @@ establishShell(int argc, VALUE *argv, struct pty_info *info,
|
|||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
establishShell(int argc, VALUE *argv, struct pty_info *info,
|
||||||
|
char SlaveName[DEVICELEN])
|
||||||
|
{
|
||||||
|
int master,slave;
|
||||||
|
rb_pid_t pid;
|
||||||
|
char *p, tmp, *getenv();
|
||||||
|
struct passwd *pwent;
|
||||||
|
VALUE v;
|
||||||
|
struct child_info carg;
|
||||||
|
|
||||||
|
if (argc == 0) {
|
||||||
|
const char *shellname;
|
||||||
|
|
||||||
|
if ((p = getenv("SHELL")) != NULL) {
|
||||||
|
shellname = p;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pwent = getpwuid(getuid());
|
||||||
|
if (pwent && pwent->pw_shell)
|
||||||
|
shellname = pwent->pw_shell;
|
||||||
|
else
|
||||||
|
shellname = "/bin/sh";
|
||||||
|
}
|
||||||
|
v = rb_str_new2(shellname);
|
||||||
|
argc = 1;
|
||||||
|
argv = &v;
|
||||||
|
}
|
||||||
|
|
||||||
|
getDevice(&master, &slave, SlaveName);
|
||||||
|
|
||||||
|
carg.master = master;
|
||||||
|
carg.slave = slave;
|
||||||
|
carg.argc = argc;
|
||||||
|
carg.argv = argv;
|
||||||
|
pid = rb_fork(0, chfunc, &carg, Qnil);
|
||||||
|
|
||||||
|
if (pid < 0) {
|
||||||
|
close(master);
|
||||||
|
close(slave);
|
||||||
|
rb_sys_fail("fork failed");
|
||||||
|
}
|
||||||
|
|
||||||
read(master, &tmp, 1);
|
read(master, &tmp, 1);
|
||||||
close(slave);
|
close(slave);
|
||||||
|
|
||||||
|
@ -971,10 +971,12 @@ void rb_thread_stop_timer_thread(void);
|
|||||||
void rb_thread_start_timer_thread(void);
|
void rb_thread_start_timer_thread(void);
|
||||||
void rb_thread_reset_timer_thread(void);
|
void rb_thread_reset_timer_thread(void);
|
||||||
|
|
||||||
|
static int forked_child = 0;
|
||||||
|
|
||||||
#define before_exec() \
|
#define before_exec() \
|
||||||
(rb_enable_interrupt(), rb_thread_stop_timer_thread())
|
(rb_enable_interrupt(), forked_child ? 0 : rb_thread_stop_timer_thread())
|
||||||
#define after_exec() \
|
#define after_exec() \
|
||||||
(rb_thread_start_timer_thread(), rb_disable_interrupt())
|
(rb_thread_start_timer_thread(), forked_child = 0, rb_disable_interrupt())
|
||||||
#define before_fork() before_exec()
|
#define before_fork() before_exec()
|
||||||
#define after_fork() after_exec()
|
#define after_fork() after_exec()
|
||||||
|
|
||||||
@ -2415,6 +2417,7 @@ rb_fork(int *status, int (*chfunc)(void*), void *charg, VALUE fds)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
|
forked_child = 1;
|
||||||
if (chfunc) {
|
if (chfunc) {
|
||||||
#ifdef FD_CLOEXEC
|
#ifdef FD_CLOEXEC
|
||||||
close(ep[0]);
|
close(ep[0]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user