summaryrefslogtreecommitdiff
path: root/nacl
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-22 00:32:03 (GMT)
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-22 00:32:03 (GMT)
commit04e356b002bec740b3f4799606c5c581a1013b06 (patch)
treea663665c7f3a7e8c37d088a40c70423679ec67a1 /nacl
parent2f438d60106789a8628617ab41bc1c750ecae62b (diff)
* nacl/pepper_main.c (Instance_DidCreate): mount devfs and rebind fd 0
.. 2 so that stderr goes to the console of the browser. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'nacl')
-rw-r--r--nacl/pepper_main.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/nacl/pepper_main.c b/nacl/pepper_main.c
index bcb128d..168e8f9 100644
--- a/nacl/pepper_main.c
+++ b/nacl/pepper_main.c
@@ -405,6 +405,24 @@ init_libraries_if_necessary(void)
}
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
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")) {