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

ruby-changes:35995

From: yugui <ko1@a...>
Date: Wed, 22 Oct 2014 09:32:29 +0900 (JST)
Subject: [ruby-changes:35995] yugui:r48083 (trunk): * nacl/pepper_main.c (Instance_DidCreate): mount devfs and rebind fd 0

yugui	2014-10-22 09:32:03 +0900 (Wed, 22 Oct 2014)

  New Revision: 48083

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

  Log:
    * nacl/pepper_main.c (Instance_DidCreate): mount devfs and rebind fd 0
      .. 2 so that stderr goes to the console of the browser.

  Modified files:
    trunk/ChangeLog
    trunk/nacl/pepper_main.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48082)
+++ ChangeLog	(revision 48083)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Oct 22 08:21:09 2014  Yuki Yugui Sonoda  <yugui@y...>
+
+	* nacl/pepper_main.c (Instance_DidCreate): mount devfs and rebind fd 0
+	  .. 2 so that stderr goes to the console of the browser.
+
 Wed Oct 22 03:47:43 2014  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* ext/etc/etc.c (etc_nprocessors_affin): maximum "n" should be 16384.
Index: nacl/pepper_main.c
===================================================================
--- nacl/pepper_main.c	(revision 48082)
+++ nacl/pepper_main.c	(revision 48083)
@@ -405,6 +405,24 @@ init_libraries_if_necessary(void) https://github.com/ruby/ruby/blob/trunk/nacl/pepper_main.c#L405
 }
 
 static int
+reopen_fd(int fd, const char* path, int flags) {
+  int fd2 = open(path, flags);
+  if (fd2 < 0) {
+    perror("open fd");
+    return -1;
+  }
+  if (dup2(fd2, fd) < 0) {
+    perror("dup2 fd");
+    return -1;
+  }
+  if (close(fd2)) {
+    perror("close old fd");
+    return -1;
+  }
+  return fd;
+}
+
+static int
 pruby_init(void)
 {
   RUBY_INIT_STACK;
@@ -490,13 +508,29 @@ static PP_Bool https://github.com/ruby/ruby/blob/trunk/nacl/pepper_main.c#L508
 Instance_DidCreate(PP_Instance instance,
                    uint32_t argc, const char* argn[], const char* argv[])
 {
-  int ret;
   struct PepperInstance* data = pruby_register_instance(instance);
   current_instance = instance;
 
   nacl_io_init_ppapi(instance, get_browser_interface);
 
-  // TODO(yugui) Mount devfs
+  if (mount("", "/dev2", "dev", 0, "")) {
+    perror("mount dev");
+    return PP_FALSE;
+  }
+  if (reopen_fd(0, "/dev2/stdin", O_RDONLY) < 0) {
+    perror("reopen stdin");
+    return PP_FALSE;
+  }
+  if (reopen_fd(1, "/dev2/stdout", O_WRONLY) < 0) {
+    perror("reopen stdout");
+    return PP_FALSE;
+  }
+  if (reopen_fd(2, "/dev2/console1", O_WRONLY) < 0) {
+    perror("reopen stderr");
+    return PP_FALSE;
+  }
+
+  /* TODO(yugui) Unmount original /dev */
 
   if (mount("/lib", "/lib", "httpfs",
         0, "allow_cross_origin_requests=false")) {

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

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