OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium 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 // A mini-zygote specifically for Native Client. | 5 // A mini-zygote specifically for Native Client. |
6 | 6 |
7 #include "chrome/common/nacl_helper_linux.h" | 7 #include "chrome/common/nacl_helper_linux.h" |
8 | 8 |
9 #include <errno.h> | 9 #include <errno.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
(...skipping 29 matching lines...) Expand all Loading... |
40 LOG(ERROR) << "close(kNaClZygoteDescriptor) failed."; | 40 LOG(ERROR) << "close(kNaClZygoteDescriptor) failed."; |
41 // Set up browser descriptor as expected by Chrome on fd 3 | 41 // Set up browser descriptor as expected by Chrome on fd 3 |
42 // The zygote takes care of putting the sandbox IPC channel on fd 5 | 42 // The zygote takes care of putting the sandbox IPC channel on fd 5 |
43 int zfd = dup2(child_fds[kNaClBrowserFDIndex], kNaClBrowserDescriptor); | 43 int zfd = dup2(child_fds[kNaClBrowserFDIndex], kNaClBrowserDescriptor); |
44 if (zfd != kNaClBrowserDescriptor) { | 44 if (zfd != kNaClBrowserDescriptor) { |
45 LOG(ERROR) << "Could not initialize kNaClBrowserDescriptor"; | 45 LOG(ERROR) << "Could not initialize kNaClBrowserDescriptor"; |
46 _exit(-1); | 46 _exit(-1); |
47 } | 47 } |
48 | 48 |
49 MessageLoopForIO main_message_loop; | 49 MessageLoopForIO main_message_loop; |
50 NaClListener *listener = new NaClListener(); | 50 NaClListener listener; |
51 listener->Listen(); | 51 listener.Listen(); |
52 _exit(0); | 52 _exit(0); |
53 } | 53 } |
54 | 54 |
55 // Some of this code was lifted from | 55 // Some of this code was lifted from |
56 // content/browser/zygote_main_linux.cc:ForkWithRealPid() | 56 // content/browser/zygote_main_linux.cc:ForkWithRealPid() |
57 void HandleForkRequest(const std::vector<int>& child_fds) { | 57 void HandleForkRequest(const std::vector<int>& child_fds) { |
58 VLOG(1) << "nacl_helper: forking"; | 58 VLOG(1) << "nacl_helper: forking"; |
59 pid_t childpid = fork(); | 59 pid_t childpid = fork(); |
60 if (childpid < 0) { | 60 if (childpid < 0) { |
61 perror("fork"); | 61 perror("fork"); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 165 } |
166 } | 166 } |
167 // if fork fails, send PID=-1 to zygote | 167 // if fork fails, send PID=-1 to zygote |
168 if (!UnixDomainSocket::SendMsg(kNaClZygoteDescriptor, &badpid, | 168 if (!UnixDomainSocket::SendMsg(kNaClZygoteDescriptor, &badpid, |
169 sizeof(badpid), empty)) { | 169 sizeof(badpid), empty)) { |
170 LOG(ERROR) << "*** send() to zygote failed"; | 170 LOG(ERROR) << "*** send() to zygote failed"; |
171 } | 171 } |
172 } | 172 } |
173 CHECK(false); // This routine must not return | 173 CHECK(false); // This routine must not return |
174 } | 174 } |
OLD | NEW |