summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-07-26 09:15:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-07-26 09:15:31 +0000
commit0cd59e5b59750989ead8bf5c52f34c6cd16eccc9 (patch)
tree15692c43391cd20255be314f3e6771a37bb3d0cb /ext
parent544789bd79bc3d63d52c69fa820e1ae768a9057e (diff)
* ext/pty/pty.c (getDevice): retry once after GC on failure.
[ruby-core:08282] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/pty/pty.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/ext/pty/pty.c b/ext/pty/pty.c
index 5f73d286f7..ae5ee0b68a 100644
--- a/ext/pty/pty.c
+++ b/ext/pty/pty.c
@@ -295,37 +295,34 @@ pty_finalize_syswait(struct pty_info *info)
return Qnil;
}
-#ifdef HAVE_OPENPTY
+static int
+get_device_once(int *master, int *slave, int fail)
+{
+#if defined HAVE_OPENPTY
/*
* Use openpty(3) of 4.3BSD Reno and later,
* or the same interface function.
*/
-static void
-getDevice(int *master, int *slave)
-{
if (openpty(master, slave, SlaveName,
(struct termios *)0, (struct winsize *)0) == -1) {
+ if (!fail) return -1;
rb_raise(rb_eRuntimeError, "openpty() failed");
}
-}
-#else /* HAVE_OPENPTY */
-#ifdef HAVE__GETPTY
-static void
-getDevice(int *master, int *slave)
-{
+
+ return 0;
+#elif defined HAVE__GETPTY
char *name;
if (!(name = _getpty(master, O_RDWR, 0622, 0))) {
+ if (!fail) return -1;
rb_raise(rb_eRuntimeError, "_getpty() failed");
}
*slave = open(name, O_RDWR);
strcpy(SlaveName, name);
-}
+
+ return 0;
#else /* HAVE__GETPTY */
-static void
-getDevice(int *master, int *slave)
-{
int i,j;
#ifdef HAVE_PTSNAME
@@ -350,7 +347,7 @@ getDevice(int *master, int *slave)
*master = i;
*slave = j;
strcpy(SlaveName, pn);
- return;
+ return 0;
#if defined I_PUSH && !defined linux
}
}
@@ -361,7 +358,8 @@ getDevice(int *master, int *slave)
}
close(i);
}
- rb_raise(rb_eRuntimeError, "can't get Master/Slave device");
+ if (!fail) rb_raise(rb_eRuntimeError, "can't get Master/Slave device");
+ return -1;
#else
char **p;
char MasterName[DEVICELEN];
@@ -375,16 +373,25 @@ getDevice(int *master, int *slave)
*slave = j;
chown(SlaveName, getuid(), getgid());
chmod(SlaveName, 0622);
- return;
+ return 0;
}
close(i);
}
}
- rb_raise(rb_eRuntimeError, "can't get %s", SlaveName);
+ if (fail) rb_raise(rb_eRuntimeError, "can't get %s", SlaveName);
+ return -1;
#endif
+#endif
+}
+
+static void
+getDevice(int *master, int *slave)
+{
+ if (get_device_once(master, slave, 0)) {
+ rb_gc();
+ get_device_once(master, slave, 1);
+ }
}
-#endif /* HAVE__GETPTY */
-#endif /* HAVE_OPENPTY */
static void
freeDevice()