Changeset 151098 in webkit


Ignore:
Timestamp:
Jun 3, 2013 1:34:34 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[EFL][WK2] Process launcher uses system() for wrapping the WebProcess when using WEB_PROCESS_CMD_PREFIX
https://bugs.webkit.org/show_bug.cgi?id=105156

Patch by Sergio Correia <Sergio Correia> on 2013-06-03
Reviewed by Christophe Dumez.

When using WEB_PROCESS_CMD_PREFIX - which allows us for instance to analyze
WebProcess under tools like valgrind or gdb -, the ProcessLauncher would
spawn the new process using system(), which would, among other things, keep
an extra UIProcess waiting and executing the shell.

This patch handles the normal case and the case where we have something to
prefix WebProcess (i.e., by using WEB_PROCESS_CMD_PREFIX in a debug build)
the same way, through a call to execvp().

To achieve this a function was introduced to create an array with the given
arguments to the full command to be executed, to be used by execvp(). We use
a Vector<OwnArrayPtr<char>>, so that we can take advantage of the destructor
of OwnArrayPtr to handle the memory deallocation when it goes out of scope.

  • UIProcess/Launcher/efl/ProcessLauncherEfl.cpp:

(WebKit::createArgsArray): This function creates the array to be used by
execvp(), out of the Strings given as arguments.
(WebKit::ProcessLauncher::launchProcess): Rework the logic to accomodate
both the cases with and without WEB_PROCESS_CMD_PREFIX. The execl() call
was replaced with an execvp() call, since now we should deal with having
a variable number of arguments (WEB_PROCESS_CMD_PREFIX) as well.

Location:
trunk/Source/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r151091 r151098  
     12013-06-03  Sergio Correia  <sergio.correia@openbossa.org>
     2
     3        [EFL][WK2] Process launcher uses system() for wrapping the WebProcess when using WEB_PROCESS_CMD_PREFIX
     4        https://bugs.webkit.org/show_bug.cgi?id=105156
     5
     6        Reviewed by Christophe Dumez.
     7
     8        When using WEB_PROCESS_CMD_PREFIX - which allows us for instance to analyze
     9        WebProcess under tools like valgrind or gdb -, the ProcessLauncher would
     10        spawn the new process using system(), which would, among other things, keep
     11        an extra UIProcess waiting and executing the shell.
     12
     13        This patch handles the normal case and the case where we have something to
     14        prefix WebProcess (i.e., by using WEB_PROCESS_CMD_PREFIX in a debug build)
     15        the same way, through a call to execvp().
     16
     17        To achieve this a function was introduced to create an array with the given
     18        arguments to the full command to be executed, to be used by execvp(). We use
     19        a Vector<OwnArrayPtr<char>>, so that we can take advantage of the destructor
     20        of OwnArrayPtr to handle the memory deallocation when it goes out of scope.
     21
     22        * UIProcess/Launcher/efl/ProcessLauncherEfl.cpp:
     23        (WebKit::createArgsArray):  This function creates the array to be used by
     24        execvp(), out of the Strings given as arguments.
     25        (WebKit::ProcessLauncher::launchProcess): Rework the logic to accomodate
     26        both the cases with and without WEB_PROCESS_CMD_PREFIX. The execl() call
     27        was replaced with an execvp() call, since now we should deal with having
     28        a variable number of arguments (WEB_PROCESS_CMD_PREFIX) as well.
     29
    1302013-06-02  Arunprasad Rajkumar  <arurajku@cisco.com>
    231
  • trunk/Source/WebKit2/UIProcess/Launcher/efl/ProcessLauncherEfl.cpp

    r141275 r151098  
    11/*
    22    Copyright (C) 2012 Samsung Electronics
     3    Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
    34
    45    This library is free software; you can redistribute it and/or
     
    2829#include <WebCore/ResourceHandle.h>
    2930#include <WebCore/RunLoop.h>
     31#include <wtf/OwnArrayPtr.h>
    3032#include <wtf/text/CString.h>
    3133#include <wtf/text/WTFString.h>
     
    3436
    3537namespace WebKit {
     38
     39static Vector<OwnArrayPtr<char>> createArgsArray(const String& prefix, const String& executablePath, const String& socket, const String& pluginPath)
     40{
     41    ASSERT(!executablePath.isEmpty());
     42    ASSERT(!socket.isEmpty());
     43
     44    Vector<String> splitArgs;
     45    prefix.split(' ', splitArgs);
     46
     47    splitArgs.append(executablePath);
     48    splitArgs.append(socket);
     49    if (!pluginPath.isEmpty())
     50        splitArgs.append(pluginPath);
     51
     52    Vector<OwnArrayPtr<char>> args;
     53    args.resize(splitArgs.size() + 1); // Extra room for null.
     54
     55    size_t numArgs = splitArgs.size();
     56    for (size_t i = 0; i < numArgs; ++i) {
     57        CString param = splitArgs[i].utf8();
     58        args[i] = adoptArrayPtr(new char[param.length() + 1]); // Room for the terminating null coming from the CString.
     59        strncpy(args[i].get(), param.data(), param.length() + 1); // +1 here so that strncpy copies the ending null.
     60    }
     61    // execvp() needs the pointers' array to be null-terminated.
     62    args[numArgs] = nullptr;
     63
     64    return args;
     65}
    3666
    3767void ProcessLauncher::launchProcess()
     
    4373    }
    4474
    45     CString executablePath, pluginPath;
     75    String processCmdPrefix, executablePath, pluginPath;
    4676    switch (m_launchOptions.processType) {
    4777    case WebProcess:
    48         executablePath = executablePathOfWebProcess().utf8();
     78        executablePath = executablePathOfWebProcess();
    4979        break;
    5080#if ENABLE(PLUGIN_PROCESS)
    5181    case PluginProcess:
    52         executablePath = executablePathOfPluginProcess().utf8();
    53         pluginPath = m_launchOptions.extraInitializationData.get("plugin-path").utf8();
     82        executablePath = executablePathOfPluginProcess();
     83        pluginPath = m_launchOptions.extraInitializationData.get("plugin-path");
    5484        break;
    5585#endif
     
    5989    }
    6090
    61     char socket[5];
    62     snprintf(socket, sizeof(socket), "%d", sockets[0]);
    63 
    6491#ifndef NDEBUG
    65     CString prefixedExecutablePath;
    66     if (!m_launchOptions.processCmdPrefix.isEmpty()) {
    67         String prefixedExecutablePathStr = m_launchOptions.processCmdPrefix + ' ' +
    68             String::fromUTF8(executablePath.data()) + ' ' + socket + ' ' + String::fromUTF8(pluginPath.data());
    69         prefixedExecutablePath = prefixedExecutablePathStr.utf8();
    70     }
     92    if (!m_launchOptions.processCmdPrefix.isEmpty())
     93        processCmdPrefix = m_launchOptions.processCmdPrefix;
    7194#endif
     95    Vector<OwnArrayPtr<char>> args = createArgsArray(processCmdPrefix, executablePath, String::number(sockets[0]), pluginPath);
    7296
    7397    // Do not perform memory allocation in the middle of the fork()
     
    77101    if (!pid) { // Child process.
    78102        close(sockets[1]);
    79 #ifndef NDEBUG
    80         if (!prefixedExecutablePath.isNull()) {
    81             // FIXME: This is not correct because it invokes the shell
    82             // and keeps this process waiting. Should be changed to
    83             // something like execvp().
    84             if (system(prefixedExecutablePath.data()) == -1) {
    85                 ASSERT_NOT_REACHED();
    86                 exit(EXIT_FAILURE);
    87             } else
    88                 exit(EXIT_SUCCESS);
    89         }
    90 #endif
    91         execl(executablePath.data(), executablePath.data(), socket, pluginPath.data(), static_cast<char*>(0));
     103        execvp(args.data()[0].get(), reinterpret_cast<char* const*>(args.data()));
    92104    } else if (pid > 0) { // parent process;
    93105        close(sockets[0]);
Note: See TracChangeset for help on using the changeset viewer.