2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/types.h>
41 #include <sys/param.h>
44 #include "native_client/nonnacl_util/sel_ldr_launcher.h"
48 SelLdrLauncher::~SelLdrLauncher() {
50 // When used with the browser's invalidate functionality this
51 // causes occasional deadlocks in nacl modules that have threads that have
52 // not terminated when the main thread is being terminated.
53 // TODO: Implement a whole-module shutdown RPC.
55 if (child_
!= kInvalidHandle
) {
57 waitpid(child_
, &status
, 0);
62 bool SelLdrLauncher::Start(const char* application_name
,
65 const char* sel_ldr_argv
[],
67 const char* application_argv
[]) {
69 const char* const kNaclSelLdrBasename
= "sel_ldr";
70 const char* plugin_dirname
= GetPluginDirname();
71 char sel_ldr_path
[MAXPATHLEN
+ 1];
73 application_name_
= application_name
;
75 if (NULL
== plugin_dirname
) {
76 printf("GetPluginDirname returned NULL -- load failed\n");
79 // Uncomment to turn on the sandbox, or set this in your environment
80 // TODO: Turn this on by default.
82 // setenv("NACL_ENABLE_OUTER_SANDBOX");
83 snprintf(sel_ldr_path
,
88 printf("starting: %s %s\n", sel_ldr_path
, application_name
);
90 if (SocketPair(pair
) == -1) {
94 // Set environment variable to keep the Mac sel_ldr from stealing the focus.
95 // TODO: change this to use a command line parameter rather than env.
96 setenv("NACL_LAUNCHED_FROM_BROWSER", "1", 0);
97 // Fork the sel_ldr process.
100 printf("fork failed\n");
108 BuildArgv(sel_ldr_path
,
116 execv(sel_ldr_path
, const_cast<char **>(argv_
));
118 printf("exec failed\n");
124 int flags
= fcntl(channel_
, F_GETFD
);
127 fcntl(channel_
, F_SETFD
, flags
);