Changeset 83277 in webkit


Ignore:
Timestamp:
Apr 8, 2011 3:06:24 AM (13 years ago)
Author:
Carlos Garcia Campos
Message:

2011-04-08 Carlos Garcia Campos <cgarcia@igalia.com>

Reviewed by Martin Robinson.

[GTK] Use glib API instead of fork + execl in ProcessLauncherGtk
https://bugs.webkit.org/show_bug.cgi?id=57234

  • UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp: (WebKit::childSetupFunction): close the socket and use prctl() when platform is Linux to kill the child process when the parent finishes. (WebKit::ProcessLauncher::launchProcess): Use g_spawn_async() to launch the web process.
Location:
trunk/Source/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r83259 r83277  
     12011-04-08  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Use glib API instead of fork + execl in ProcessLauncherGtk
     6        https://bugs.webkit.org/show_bug.cgi?id=57234
     7
     8        * UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp:
     9        (WebKit::childSetupFunction): close the socket and use prctl()
     10        when platform is Linux to kill the child process when the parent
     11        finishes.
     12        (WebKit::ProcessLauncher::launchProcess): Use g_spawn_async() to
     13        launch the web process.
     14
    1152011-04-07  Geoffrey Garen  <ggaren@apple.com>
    216
  • trunk/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp

    r83215 r83277  
    3333#include <WebCore/ResourceHandle.h>
    3434#include <errno.h>
    35 #include <stdio.h>
    36 #include <unistd.h>
     35#if OS(LINUX)
     36#include <sys/prctl.h>
     37#endif
    3738#include <wtf/text/CString.h>
    3839#include <wtf/text/WTFString.h>
     
    4546const char* gWebKitWebProcessName = "WebKitWebProcess";
    4647
     48static void childSetupFunction(gpointer userData)
     49{
     50    int socket = GPOINTER_TO_INT(userData);
     51    close(socket);
     52
     53#if OS(LINUX)
     54    // Kill child process when parent dies.
     55    prctl(PR_SET_PDEATHSIG, SIGKILL);
     56#endif
     57}
     58
    4759void ProcessLauncher::launchProcess()
    4860{
    49     pid_t pid = 0;
     61    GPid pid = 0;
    5062
    5163    int sockets[2];
    5264    if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sockets) < 0) {
    53         fprintf(stderr, "Creation of socket failed with errno %d.\n", errno);
     65        g_printerr("Creation of socket failed: %s.\n", g_strerror(errno));
    5466        ASSERT_NOT_REACHED();
    5567        return;
    5668    }
    5769
    58     pid = fork();
    59     if (!pid) { // child process
    60         close(sockets[1]);
    61         String socket = String::format("%d", sockets[0]);
    62         GOwnPtr<gchar> binaryPath(g_build_filename(applicationDirectoryPath().data(), gWebKitWebProcessName, NULL));
    63         execl(binaryPath.get(), gWebKitWebProcessName, socket.utf8().data(), NULL);
    64     } else if (pid > 0) { // parent process
    65         close(sockets[0]);
    66         m_processIdentifier = pid;
    67         // We've finished launching the process, message back to the main run loop.
    68         RunLoop::main()->scheduleWork(WorkItem::create(this, &ProcessLauncher::didFinishLaunchingProcess, pid, sockets[1]));
    69     } else {
    70         fprintf(stderr, "Unable to fork a new WebProcess with errno: %d.\n", errno);
     70    GOwnPtr<gchar> binaryPath(g_build_filename(applicationDirectoryPath().data(), gWebKitWebProcessName, NULL));
     71    GOwnPtr<gchar> socket(g_strdup_printf("%d", sockets[0]));
     72    char* argv[3];
     73    argv[0] = binaryPath.get();
     74    argv[1] = socket.get();
     75    argv[2] = 0;
     76
     77    GOwnPtr<GError> error;
     78    int spawnFlags = G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_DO_NOT_REAP_CHILD;
     79    if (!g_spawn_async(0, argv, 0, static_cast<GSpawnFlags>(spawnFlags), childSetupFunction, GINT_TO_POINTER(sockets[1]), &pid, &error.outPtr())) {
     80        g_printerr("Unable to fork a new WebProcess: %s.\n", error->message);
    7181        ASSERT_NOT_REACHED();
    7282    }
     83
     84    close(sockets[0]);
     85    m_processIdentifier = static_cast<pid_t>(pid);
     86    // We've finished launching the process, message back to the main run loop.
     87    RunLoop::main()->scheduleWork(WorkItem::create(this, &ProcessLauncher::didFinishLaunchingProcess, m_processIdentifier, sockets[1]));
    7388}
    7489
Note: See TracChangeset for help on using the changeset viewer.