ProcessExecutablePathEfl.cpp [plain text]
#include "config.h"
#include "ProcessExecutablePath.h"
#include "FileSystem.h"
#include <libgen.h>
#include <unistd.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/StdLibExtras.h>
#include <wtf/text/CString.h>
namespace WebKit {
static String findProcessPath(const char* processName)
{
#if ENABLE(DEVELOPER_MODE)
String executablePath;
static const char* execDirectory = getenv("WEBKIT_EXEC_PATH");
if (execDirectory) {
executablePath = WebCore::pathByAppendingComponent(String::fromUTF8(execDirectory), processName);
if (WebCore::fileExists(executablePath))
return executablePath;
}
#if OS(UNIX)
char readLinkBuffer[PATH_MAX] = {0};
#if OS(LINUX)
ssize_t result = readlink("/proc/self/exe", readLinkBuffer, PATH_MAX);
#else
ssize_t result = readlink("/proc/curproc/file", readLinkBuffer, PATH_MAX);
#endif
if (result > 0) {
char* executablePathPtr = dirname(readLinkBuffer);
executablePath = WebCore::pathByAppendingComponent(String::fromUTF8(executablePathPtr), processName);
if (WebCore::fileExists(executablePath))
return executablePath;
}
#endif
#endif
return WebCore::pathByAppendingComponent(String::fromUTF8(LIBEXECDIR), processName);
}
String executablePathOfWebProcess()
{
static NeverDestroyed<const String> webKitWebProcessName(findProcessPath(WEBPROCESSNAME));
return webKitWebProcessName;
}
String executablePathOfPluginProcess()
{
static NeverDestroyed<const String> webKitPluginProcessName(findProcessPath(PLUGINPROCESSNAME));
return webKitPluginProcessName;
}
String executablePathOfNetworkProcess()
{
static NeverDestroyed<const String> webKitNetworkProcessName(findProcessPath(NETWORKPROCESSNAME));
return webKitNetworkProcessName;
}
#if ENABLE(DATABASE_PROCESS)
String executablePathOfDatabaseProcess()
{
static NeverDestroyed<const String> webkitDatabaseProcessName(findProcessPath(DATABASEPROCESSNAME));
return webkitDatabaseProcessName;
}
#endif
}