[前][次][番号順一覧][スレッド一覧]

ruby-changes:16633

From: nobu <ko1@a...>
Date: Tue, 13 Jul 2010 21:03:46 +0900 (JST)
Subject: [ruby-changes:16633] Ruby:r28627 (trunk): * ext/pty/pty.c (establishShell): chfunc must not raise any

nobu	2010-07-13 21:01:45 +0900 (Tue, 13 Jul 2010)

  New Revision: 28627

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28627

  Log:
    * ext/pty/pty.c (establishShell): chfunc must not raise any
      exceptions.

  Modified files:
    trunk/ChangeLog
    trunk/ext/pty/pty.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 28626)
+++ ChangeLog	(revision 28627)
@@ -1,3 +1,8 @@
+Tue Jul 13 21:01:44 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/pty/pty.c (establishShell): chfunc must not raise any
+	  exceptions.
+
 Tue Jul 13 20:58:57 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (RUBY_DEFAULT_ARCH): adjust for target
Index: ext/pty/pty.c
===================================================================
--- ext/pty/pty.c	(revision 28626)
+++ ext/pty/pty.c	(revision 28627)
@@ -155,7 +155,7 @@
 };
 
 static int
-chfunc(void *data)
+chfunc(void *data, char *errbuf, size_t errbuf_len)
 {
     struct child_info *carg = data;
     int master = carg->master;
@@ -165,6 +165,10 @@
 
     struct exec_info arg;
     int status;
+#define ERROR_EXIT(str) do { \
+	strlcpy(errbuf, str, errbuf_len); \
+	return -1; \
+    } while (0)
 
     /*
      * Set free from process group and controlling terminal
@@ -175,15 +179,15 @@
 # ifdef HAVE_SETPGRP
 #  ifdef SETGRP_VOID
     if (setpgrp() == -1)
-        perror("setpgrp()");
+        ERROR_EXIT("setpgrp()");
 #  else /* SETGRP_VOID */
     if (setpgrp(0, getpid()) == -1)
-        rb_sys_fail("setpgrp()");
+        ERROR_EXIT("setpgrp()");
     {
         int i = open("/dev/tty", O_RDONLY);
-        if (i < 0) rb_sys_fail("/dev/tty");
+        if (i < 0) ERROR_EXIT("/dev/tty");
         if (ioctl(i, TIOCNOTTY, (char *)0))
-            perror("ioctl(TIOCNOTTY)");
+            ERROR_EXIT("ioctl(TIOCNOTTY)");
         close(i);
     }
 #  endif /* SETGRP_VOID */
@@ -201,12 +205,10 @@
     close(slave);
     slave = open(carg->slavename, O_RDWR);
     if (slave < 0) {
-        perror("open: pty slave");
-        _exit(1);
+        ERROR_EXIT("open: pty slave");
     }
     close(master);
 #endif
-    write(slave, "", 1);
     dup2(slave,0);
     dup2(slave,1);
     dup2(slave,2);
@@ -219,7 +221,8 @@
     arg.argv = argv;
     rb_protect(pty_exec, (VALUE)&arg, &status);
     sleep(1);
-    _exit(1);
+    return -1;
+#undef ERROR_EXIT
 }
 
 static void
@@ -228,10 +231,11 @@
 {
     int 		master,slave;
     rb_pid_t		pid;
-    char		*p, tmp, *getenv();
+    char		*p, *getenv();
     struct passwd	*pwent;
     VALUE		v;
     struct child_info   carg;
+    char		errbuf[32];
 
     if (argc == 0) {
 	const char *shellname;
@@ -258,15 +262,17 @@
     carg.slavename = SlaveName;
     carg.argc = argc;
     carg.argv = argv;
-    pid = rb_fork(0, chfunc, &carg, Qnil);
+    errbuf[0] = '\0';
+    pid = rb_fork_err(0, chfunc, &carg, Qnil, errbuf, sizeof(errbuf));
 
     if (pid < 0) {
+	int e = errno;
 	close(master);
 	close(slave);
-	rb_sys_fail("fork failed");
+	errno = e;
+	rb_sys_fail(errbuf[0] ? errbuf : "fork failed");
     }
 
-    read(master, &tmp, 1);
     close(slave);
 
     info->child_pid = pid;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]