OLD | NEW |
---|---|
1 // Copyright (c) 2014 The Native Client Authors. All rights reserved. | 1 // Copyright (c) 2014 The Native Client Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Emulates spawning/waiting process by asking JavaScript to do so. | 5 // Emulates spawning/waiting process by asking JavaScript to do so. |
6 | 6 |
7 // Include quoted spawn.h first so we can build in the presence of an installed | 7 // Include quoted spawn.h first so we can build in the presence of an installed |
8 // copy of nacl-spawn. | 8 // copy of nacl-spawn. |
9 #define IN_NACL_SPAWN_CC | 9 #define IN_NACL_SPAWN_CC |
10 #include "spawn.h" | 10 #include "spawn.h" |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 } else if (S_ISDIR(st.st_mode)) { | 347 } else if (S_ISDIR(st.st_mode)) { |
348 // TODO(bradnelson): Land nacl_io ioctl to support this. | 348 // TODO(bradnelson): Land nacl_io ioctl to support this. |
349 } else if (S_ISCHR(st.st_mode)) { | 349 } else if (S_ISCHR(st.st_mode)) { |
350 // Unsupported. | 350 // Unsupported. |
351 } else if (S_ISBLK(st.st_mode)) { | 351 } else if (S_ISBLK(st.st_mode)) { |
352 // Unsupported. | 352 // Unsupported. |
353 } else if (S_ISFIFO(st.st_mode)) { | 353 } else if (S_ISFIFO(st.st_mode)) { |
354 char entry[100]; | 354 char entry[100]; |
355 snprintf(entry, sizeof entry, | 355 snprintf(entry, sizeof entry, |
356 "NACL_SPAWN_FD_SETUP_%d=pipe:%d:%d:%d", count++, fd, | 356 "NACL_SPAWN_FD_SETUP_%d=pipe:%d:%d:%d", count++, fd, |
357 static_cast<int>(st.st_ino), st.st_rdev == O_WRONLY); | 357 static_cast<int>(st.st_ino), |
358 (st.st_rdev & O_WRONLY) == O_WRONLY); | |
358 nspawn_array_appendstring(envs_var, entry); | 359 nspawn_array_appendstring(envs_var, entry); |
359 } else if (S_ISLNK(st.st_mode)) { | 360 } else if (S_ISLNK(st.st_mode)) { |
360 // Unsupported. | 361 // Unsupported. |
361 } else if (S_ISSOCK(st.st_mode)) { | 362 } else if (S_ISSOCK(st.st_mode)) { |
362 // Unsupported. | 363 // Unsupported. |
363 } | 364 } |
364 } | 365 } |
365 return 0; | 366 return 0; |
366 } | 367 } |
367 | 368 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 memcpy(*data, result, result_len); | 683 memcpy(*data, result, result_len); |
683 (*data)[result_len] = '\0'; | 684 (*data)[result_len] = '\0'; |
684 } | 685 } |
685 nspawn_var_release(result_var); | 686 nspawn_var_release(result_var); |
686 nspawn_var_release(result_dict_var); | 687 nspawn_var_release(result_dict_var); |
687 } | 688 } |
688 | 689 |
689 // Create a javascript pipe. pipefd[0] will be the read end of the pipe | 690 // Create a javascript pipe. pipefd[0] will be the read end of the pipe |
690 // and pipefd[1] the write end of the pipe. | 691 // and pipefd[1] the write end of the pipe. |
691 int nacl_spawn_pipe(int pipefd[2]) { | 692 int nacl_spawn_pipe(int pipefd[2]) { |
693 return nacl_spawn_pipe_flags(0, pipefd); | |
694 } | |
695 | |
696 // Same as above with flags. | |
697 int nacl_spawn_pipe_flags(int flags, int pipefd[2]) { | |
692 if (pipefd == NULL) { | 698 if (pipefd == NULL) { |
693 errno = EFAULT; | 699 errno = EFAULT; |
694 return -1; | 700 return -1; |
695 } | 701 } |
696 | 702 |
697 struct PP_Var req_var = nspawn_dict_create(); | 703 struct PP_Var req_var = nspawn_dict_create(); |
698 nspawn_dict_setstring(req_var, "command", "nacl_apipe"); | 704 nspawn_dict_setstring(req_var, "command", "nacl_apipe"); |
699 | 705 |
700 struct PP_Var result_var = nspawn_send_request(req_var); | 706 struct PP_Var result_var = nspawn_send_request(req_var); |
701 int id = nspawn_dict_getint(result_var, "pipe_id"); | 707 int id = nspawn_dict_getint(result_var, "pipe_id"); |
702 nspawn_var_release(result_var); | 708 nspawn_var_release(result_var); |
703 | 709 |
704 int read_fd; | 710 int read_fd; |
705 int write_fd; | 711 int write_fd; |
706 char path[100]; | 712 char path[100]; |
707 sprintf(path, "/apipe/%d", id); | 713 sprintf(path, "/apipe/%d", id); |
708 read_fd = open(path, O_RDONLY); | 714 // Filter out O_RDONLY + O_WRONLY |
bsy_cr
2016/03/03 18:43:33
sorry about the drive-by.
filtering out should be
bradn
2016/03/03 19:11:40
Thanks, that actually caught a mistake!
Good to k
| |
709 write_fd = open(path, O_WRONLY); | 715 flags &= O_RDONLY | O_WRONLY; |
716 read_fd = open(path, O_RDONLY | flags); | |
717 write_fd = open(path, O_WRONLY | flags); | |
710 if (read_fd < 0 || write_fd < 0) { | 718 if (read_fd < 0 || write_fd < 0) { |
711 if (read_fd >= 0) { | 719 if (read_fd >= 0) { |
712 close(read_fd); | 720 close(read_fd); |
713 } | 721 } |
714 if (write_fd >= 0) { | 722 if (write_fd >= 0) { |
715 close(write_fd); | 723 close(write_fd); |
716 } | 724 } |
717 return -1; | 725 return -1; |
718 } | 726 } |
719 pipefd[0] = read_fd; | 727 pipefd[0] = read_fd; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
825 } | 833 } |
826 | 834 |
827 int execlpe(const char *path, const char *arg, ...) { /* char* const envp[] */ | 835 int execlpe(const char *path, const char *arg, ...) { /* char* const envp[] */ |
828 NSPAWN_LOG("execlpe: %s", path); | 836 NSPAWN_LOG("execlpe: %s", path); |
829 VARG_TO_ARGV_ENVP; | 837 VARG_TO_ARGV_ENVP; |
830 // TODO(bradnelson): Limit path resolution to 'p' variants. | 838 // TODO(bradnelson): Limit path resolution to 'p' variants. |
831 return spawnve_impl(P_OVERLAY, path, argv, envp); | 839 return spawnve_impl(P_OVERLAY, path, argv, envp); |
832 } | 840 } |
833 | 841 |
834 }; // extern "C" | 842 }; // extern "C" |
OLD | NEW |