VirtualBox

Changeset 80612 in vbox


Ignore:
Timestamp:
Sep 5, 2019 10:12:07 PM (5 years ago)
Author:
vboxsync
Message:

Main/MachineLaunchVMCommonWorker: Simplified darwin specific code for kicking off VirtualVM or override. Was making too many unnecessary string copies. bugref:9341

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-all/MachineLaunchVMCommonWorker.cpp

    r80611 r80612  
    2020*   Header Files                                                                                                                 *
    2121*********************************************************************************************************************************/
    22 #include <iprt/process.h>
     22#include <iprt/dir.h>
     23#include <iprt/env.h>
     24#include <iprt/err.h>
     25#include <iprt/file.h>
    2326#include <iprt/log.h>
    2427#include <iprt/path.h>
    25 #include <iprt/env.h>
    26 #include <iprt/file.h>
    27 #include <iprt/dir.h>
     28#include <iprt/process.h>
    2829#include "MachineLaunchVMCommonWorker.h"
    2930
     
    8889    NOREF(aFilename);
    8990
    90     /* Get the path to the executable directory: */
     91    /* Get the path to the executable directory w/ trailing slash: */
    9192    char szPath[RTPATH_MAX];
    92     RTPathAppPrivateArch(szPath, sizeof(szPath) - 1);
     93    int vrc = RTPathAppPrivateArch(szPath, sizeof(szPath));
     94    AssertRCReturn(vrc, vrc);
     95    vrc = RTPathEnsureTrailingSeparator(szPath, sizeof(szPath));
     96    AssertRCReturn(vrc, vrc);
    9397    size_t cbBufLeft = strlen(szPath);
    94     szPath[cbBufLeft++] = RTPATH_DELIMITER;
    95     szPath[cbBufLeft] = '\0';
    9698    char *pszNamePart = &szPath[cbBufLeft]; NOREF(pszNamePart);
    9799    cbBufLeft = sizeof(szPath) - cbBufLeft;
     
    104106
    105107    RTENV hEnv = RTENV_DEFAULT;
    106     int vrc = VINF_SUCCESS;
    107108    if (!aEnvironment.isEmpty())
    108109    {
     
    164165    {
    165166# ifdef RT_OS_DARWIN /* Avoid Launch Services confusing this with the selector by using a helper app. */
     167
     168#  define OSX_APP_NAME           "VirtualBoxVM"
     169#  define OSX_APP_PATH_FMT       "/Resources/%s.app/Contents/MacOS/VirtualBoxVM"
     170#  define OSX_APP_PATH_WITH_NAME "/Resources/VirtualBoxVM.app/Contents/MacOS/VirtualBoxVM"
     171
    166172        /* Modify the base path so that we don't need to use ".." below. */
    167173        RTPathStripTrailingSlash(szPath);
    168174        RTPathStripFilename(szPath);
    169175        cbBufLeft = strlen(szPath);
    170         pszNamePart = szPath + cbBufLeft;
     176        pszNamePart = &szPath[cbBufLeft]; Assert(!*pszNamePart);
    171177        cbBufLeft = sizeof(szPath) - cbBufLeft;
    172178
    173 #  define OSX_APP_NAME "VirtualBoxVM"
    174 #  define OSX_APP_PATH_FMT "/Resources/%s.app/Contents/MacOS/VirtualBoxVM"
    175 
    176         Utf8Str strAppOverride = aFilename;
    177         if (   strAppOverride.contains(".")
    178             || strAppOverride.contains("/")
    179             || strAppOverride.contains("\\")
    180             || strAppOverride.contains(":"))
    181             strAppOverride.setNull();
    182         Utf8Str strAppPath;
    183         if (!strAppOverride.isEmpty())
    184         {
    185             strAppPath = Utf8StrFmt(OSX_APP_PATH_FMT, strAppOverride.c_str());
    186             Utf8Str strFullPath(szPath);
    187             strFullPath.append(strAppPath);
     179        if (aFilename.isNotEmpty() && strpbrk(aFilename.c_str(), "./\\:") == NULL)
     180        {
     181            ssize_t cch = RTStrPrintf2(pszNamePart, cbBufLeft, OSX_APP_PATH_FMT, aFilename.c_str());
     182            AssertReturn(cch > 0, VERR_FILENAME_TOO_LONG);
    188183            /* there is a race, but people using this deserve the failure */
    189             if (!RTFileExists(strFullPath.c_str()))
    190                 strAppOverride.setNull();
     184            if (!RTFileExists(szPath))
     185                *pszNamePart = '\0';
    191186        }
    192         if (strAppOverride.isEmpty())
    193             strAppPath = Utf8StrFmt(OSX_APP_PATH_FMT, OSX_APP_NAME);
    194         vrc = RTStrCopy(pszNamePart, cbBufLeft, strAppPath.c_str());
    195         AssertRCReturn(vrc, vrc);
     187        if (!*pszNamePart)
     188        {
     189            vrc = RTStrCopy(pszNamePart, cbBufLeft, OSX_APP_PATH_WITH_NAME);
     190            AssertRCReturn(vrc, vrc);
     191        }
    196192# else
    197193        static const char s_szVirtualBox_exe[] = "VirtualBoxVM" HOSTSUFF_EXE;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette