|
Line 0
WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp_sec1
|
|
|
1 |
/* |
| 2 |
* Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 |
* Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved. |
| 4 |
* |
| 5 |
* Redistribution and use in source and binary forms, with or without |
| 6 |
* modification, are permitted provided that the following conditions |
| 7 |
* are met: |
| 8 |
* 1. Redistributions of source code must retain the above copyright |
| 9 |
* notice, this list of conditions and the following disclaimer. |
| 10 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 11 |
* notice, this list of conditions and the following disclaimer in the |
| 12 |
* documentation and/or other materials provided with the distribution. |
| 13 |
* |
| 14 |
* THIS SOFTWARE IS PROVIDED BY MOTOROLA INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 15 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 16 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MOTOROLA INC. OR ITS CONTRIBUTORS |
| 18 |
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 19 |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 20 |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 21 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 22 |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 23 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 24 |
* THE POSSIBILITY OF SUCH DAMAGE. |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "ProcessLauncher.h" |
| 28 |
|
| 29 |
#include "Connection.h" |
| 30 |
#include "NotImplemented.h" |
| 31 |
#include "RunLoop.h" |
| 32 |
#include "WebProcess.h" |
| 33 |
|
| 34 |
#include <WebCore/PlatformString.h> |
| 35 |
#include <WebCore/ResourceHandle.h> |
| 36 |
#include <runtime/InitializeThreading.h> |
| 37 |
#include <wtf/Threading.h> |
| 38 |
#include <wtf/text/CString.h> |
| 39 |
|
| 40 |
using namespace WebCore; |
| 41 |
|
| 42 |
namespace WebKit { |
| 43 |
|
| 44 |
#define WEBKIT_WEB_PROCESS_NAME "WebKitWebProcess" |
| 45 |
#define WEBKIT_WEB_PROCESS_PATH "/usr/local/bin/WebKitWebProcess" |
| 46 |
|
| 47 |
void ProcessLauncher::launchProcess() |
| 48 |
{ |
| 49 |
pid_t pid = 0; |
| 50 |
|
| 51 |
int sockets[2]; |
| 52 |
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) < 0) |
| 53 |
return; |
| 54 |
|
| 55 |
String commandLine(WEBKIT_WEB_PROCESS_PATH); |
| 56 |
pid = fork(); |
| 57 |
if (!pid) { // child process |
| 58 |
close(sockets[1]); |
| 59 |
String socket = String::format("%d", sockets[0]); |
| 60 |
execl(commandLine.utf8().data(), WEBKIT_WEB_PROCESS_NAME, socket.utf8().data(), (char*)0); |
| 61 |
} else if (pid > 0) { // parent process |
| 62 |
close(sockets[0]); |
| 63 |
m_processIdentifier = pid; |
| 64 |
// We've finished launching the process, message back to the main run loop. |
| 65 |
RunLoop::main()->scheduleWork(WorkItem::create(this, &ProcessLauncher::didFinishLaunchingProcess, pid, sockets[1])); |
| 66 |
} else { |
| 67 |
ASSERT_NOT_REACHED(); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
void ProcessLauncher::terminateProcess() |
| 72 |
{ |
| 73 |
if (!m_processIdentifier) |
| 74 |
return; |
| 75 |
|
| 76 |
kill(m_processIdentifier, SIGKILL); |
| 77 |
} |
| 78 |
|
| 79 |
void ProcessLauncher::platformInvalidate() |
| 80 |
{ |
| 81 |
notImplemented(); |
| 82 |
} |
| 83 |
|
| 84 |
} // namespace WebKit |