VirtualBox

Changeset 33696 in vbox


Ignore:
Timestamp:
Nov 2, 2010 3:37:54 PM (14 years ago)
Author:
vboxsync
Message:

Guest Control: Updates on guest path/environment resolving, ignore/skip not implemented guests when doing automatic Guest Additions update.

Location:
trunk/src/VBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlExec.cpp

    r33558 r33696  
    10281028
    10291029
     1030/** @todo Maybe we want to have an own IPRT function for that! */
     1031int VBoxServiceControlExecMakeFullPath(const char *pszPath, char *pszExpanded, size_t cbExpanded)
     1032{
     1033    int rc = VINF_SUCCESS;
     1034#ifdef RT_OS_WINDOWS
     1035    if (!ExpandEnvironmentStrings(pszPath, pszExpanded, cbExpanded))
     1036        rc = RTErrConvertFromWin32(GetLastError());
     1037#else
     1038    /* No expansion for non-Windows yet. */
     1039    rc = RTStrCopy(pszExpanded, cbExpanded, pszPath);
     1040#endif
     1041    return rc;
     1042}
     1043
     1044
     1045int VBoxServiceControlExecResolveExecutable(const char *pszFileName, char *pszResolved, size_t cbResolved)
     1046{
     1047    int rc = VINF_SUCCESS;
     1048
     1049    /* Search the path of our executable. */
     1050    char szVBoxService[RTPATH_MAX];
     1051    if (RTProcGetExecutableName(szVBoxService, sizeof(szVBoxService)))
     1052    {
     1053        char *pszExecResolved = NULL;
     1054        if (   (g_pszProgName && RTStrICmp(pszFileName, g_pszProgName) == 0)
     1055            || !RTStrICmp(pszFileName, VBOXSERVICE_NAME))
     1056        {
     1057            /* We just want to execute VBoxService (no toolbox). */
     1058            pszExecResolved = RTStrDup(szVBoxService);
     1059        }
    10301060#ifdef VBOXSERVICE_TOOLBOX
    1031 /**
    1032  * Constructs the argv command line of a VBoxService toolbox program
     1061        else if (RTStrStr(pszFileName, "vbox_") == pszFileName)
     1062        {
     1063            /* We want to use the internal toolbox (all internal
     1064             * tools are starting with "vbox_" (e.g. "vbox_cat"). */
     1065            pszExecResolved = RTStrDup(szVBoxService);
     1066        }
     1067#endif
     1068        else /* Nothing to resolve, copy original. */
     1069            pszExecResolved = RTStrDup(pszFileName);
     1070        AssertPtr(pszExecResolved);
     1071
     1072        rc = VBoxServiceControlExecMakeFullPath(pszExecResolved, pszResolved, cbResolved);
     1073        RTStrFree(pszExecResolved);
     1074    }
     1075    return rc;
     1076}
     1077
     1078
     1079#ifdef VBOXSERVICE_TOOLBOX
     1080/**
     1081 * Constructs the argv command line of a VBoxService program
    10331082 * by first appending the full path of VBoxService along  with the given
    10341083 * tool name (e.g. "vbox_cat") + the tool's actual command line parameters.
     
    10401089 *                          Needs to be freed with RTGetOptArgvFree.
    10411090 */
    1042 int VBoxServiceControlExecPrepareToolboxArgv(const char *pszFileName,
    1043                                              const char * const *papszArgs, char ***ppapszArgv)
     1091int VBoxServiceControlExecPrepareArgv(const char *pszFileName,
     1092                                      const char * const *papszArgs, char ***ppapszArgv)
    10441093{
    10451094    AssertPtrReturn(pszFileName, VERR_INVALID_PARAMETER);
     
    10521101    if (RT_SUCCESS(rc))
    10531102    {
    1054         char *pszNewArgs;
    10551103        /*
    10561104         * Construct the new command line by appending the actual
    10571105         * tool name to new process' command line.
    10581106         */
    1059         if (RTStrAPrintf(&pszNewArgs, "%s %s", pszFileName, pszArgs))
    1060         {
    1061             int iNumArgsIgnored;
    1062             rc = RTGetOptArgvFromString(ppapszArgv, &iNumArgsIgnored,
    1063                                         pszNewArgs, NULL /* Use standard separators. */);
    1064             RTStrFree(pszNewArgs);
     1107        char szArgsExp[RTPATH_MAX];
     1108        rc = VBoxServiceControlExecMakeFullPath(pszArgs, szArgsExp, sizeof(szArgsExp));
     1109        if (RT_SUCCESS(rc))
     1110        {
     1111            char *pszNewArgs;
     1112            if (RTStrAPrintf(&pszNewArgs, "%s %s", pszFileName, szArgsExp))
     1113            {
     1114                int iNumArgsIgnored;
     1115                rc = RTGetOptArgvFromString(ppapszArgv, &iNumArgsIgnored,
     1116                                            pszNewArgs, NULL /* Use standard separators. */);
     1117                RTStrFree(pszNewArgs);
     1118            }
    10651119        }
    10661120        RTStrFree(pszArgs);
     
    11181172    }
    11191173#endif /* RT_OS_WINDOWS */
    1120 #ifdef VBOXSERVICE_TOOLBOX
    1121     /* Search the path of our executable. */
    1122     char szVBoxService[RTPATH_MAX];
    1123     if (RTProcGetExecutableName(szVBoxService, sizeof(szVBoxService)))
    1124     {
    1125         char *pszCmdTool = NULL;
    1126         char **papszArgsTool = NULL;
    1127         if (   (g_pszProgName && RTStrICmp(pszExec, g_pszProgName) == 0)
    1128             || !RTStrICmp(pszExec, VBOXSERVICE_NAME))
    1129         {
    1130             /* We just want to execute VBoxService (no toolbox). */
    1131             pszCmdTool = RTStrDup(szVBoxService);
    1132         }
    1133         else if (RTStrStr(pszExec, "vbox_") == pszExec)
    1134         {
    1135             /* We want to use the internal toolbox (all internal
    1136              * tools are starting with "vbox_" (e.g. "vbox_cat"). */
    1137             pszCmdTool = RTStrDup(szVBoxService);
    1138             rc = VBoxServiceControlExecPrepareToolboxArgv(pszCmdTool, papszArgs, &papszArgsTool);
    1139         }
    1140 
    1141         if (RT_SUCCESS(rc) && pszCmdTool)
    1142         {
    1143             /* Disable service flag bit, because we're executing the internal
    1144              * tool with the profile which was used to start VBoxService. */
    1145             fFlags &= ~RTPROC_FLAGS_SERVICE;
    1146 
    1147             rc = RTProcCreateEx(pszCmdTool, papszArgsTool ? papszArgsTool : papszArgs,
    1148                                 hEnv, fFlags,
     1174
     1175    /*
     1176     * Do the environment variables expansion on executable and arguments.
     1177     */
     1178    char szExecExp[RTPATH_MAX];
     1179    rc = VBoxServiceControlExecResolveExecutable(pszExec, szExecExp, sizeof(szExecExp));
     1180    if (RT_SUCCESS(rc))
     1181    {
     1182        char **papszArgsExp;
     1183        rc = VBoxServiceControlExecPrepareArgv(szExecExp, papszArgs, &papszArgsExp);
     1184        if (RT_SUCCESS(rc))
     1185        {
     1186            /* If no user name specified run with current credentials.
     1187             * This is prohibited via official Main API! */
     1188            if (!strlen(pszAsUser))
     1189                fFlags &= ~RTPROC_FLAGS_SERVICE;
     1190
     1191            /* Do normal execution. */
     1192            rc = RTProcCreateEx(szExecExp, papszArgsExp, hEnv, fFlags,
    11491193                                phStdIn, phStdOut, phStdErr,
    11501194                                strlen(pszAsUser) ? pszAsUser : NULL,
    11511195                                strlen(pszPassword) ? pszPassword : NULL,
    11521196                                phProcess);
    1153             if (papszArgsTool)
    1154                 RTGetOptArgvFree(papszArgsTool);
    1155             RTStrFree(pszCmdTool);
    1156             return rc;
    1157         }
    1158     }
    1159 #endif
    1160 
    1161     /* If no user name specified run with current credentials.
    1162      * This is prohibited via official Main API! */
    1163     if (!strlen(pszAsUser))
    1164         fFlags &= ~RTPROC_FLAGS_SERVICE;
    1165 
    1166     /* Do normal execution. */
    1167     rc = RTProcCreateEx(pszExec, papszArgs, hEnv, fFlags,
    1168                         phStdIn, phStdOut, phStdErr,
    1169                         strlen(pszAsUser) ? pszAsUser : NULL,
    1170                         strlen(pszPassword) ? pszPassword : NULL,
    1171                         phProcess);
     1197        }
     1198        RTGetOptArgvFree(papszArgsExp);
     1199    }
    11721200    return rc;
    11731201}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r33558 r33696  
    361361     */
    362362    bool fDoMount = false;
    363     /*
    364      * If the already installed Guest Additions indicate a
    365      * high enough run level (at the moment this is level "Desktop",
    366      * which means that a user has to be logged in to acknowledge
    367      * WHQL popups), try an automatic Guest Additions update.
    368      */
     363
    369364    CGuest guest = session().GetConsole().GetGuest();
    370     QString osType = guest.GetOSTypeId();
    371     ULONG ulGuestAdditionsRunLevel = guest.GetAdditionsRunLevel();
    372     if (   ulGuestAdditionsRunLevel >= AdditionsRunLevelType_System // Desktop
    373 #if 1  /* Only Windows is supported at the moment! */
    374         && (   osType.contains("Microsoft", Qt::CaseInsensitive)
    375             || osType.contains("Windows", Qt::CaseInsensitive)
    376            )
    377 #endif
    378        )
    379     {
    380365#ifdef DEBUG_andy
    381         CProgress progressInstall = guest.UpdateGuestAdditions("c:\\Downloads\\VBoxGuestAdditions-r67158.iso");
     366    CProgress progressInstall = guest.UpdateGuestAdditions("c:\\Downloads\\VBoxGuestAdditions-r67158.iso");
    382367#else
    383         CProgress progressInstall = guest.UpdateGuestAdditions(strSource);
    384 #endif
    385         bool fResult = guest.isOk();
    386         if (fResult)
    387         {
    388             vboxProblem().showModalProgressDialog(progressInstall, tr("Install"),
    389                                                   mainMachineWindow(), 0 /* No delay */);
    390             if (progressInstall.GetCanceled())
    391                 return;
    392             if (!progressInstall.isOk() || progressInstall.GetResultCode() != 0)
    393             {
     368    CProgress progressInstall = guest.UpdateGuestAdditions(strSource);
     369#endif
     370    bool fResult = guest.isOk();
     371    if (fResult)
     372    {
     373        vboxProblem().showModalProgressDialog(progressInstall, tr("Install"),
     374                                              mainMachineWindow(), 0 /* No delay */);
     375        if (progressInstall.GetCanceled())
     376            return;
     377
     378        HRESULT rc = progressInstall.GetResultCode();
     379        if (!progressInstall.isOk() || rc != S_OK)
     380        {
     381            /* If we got back a VBOX_E_NOT_SUPPORTED we don't complain (guest OS
     382             * simply isn't supported yet), so silently fall back to "old" .ISO
     383             * mounting method. */
     384            if (rc != VBOX_E_NOT_SUPPORTED)
    394385                vboxProblem().cannotUpdateGuestAdditions(progressInstall, mainMachineWindow());
    395                 fDoMount = true; /* Since automatic updating failed, fall back to .ISO mounting. */
    396             }
    397         }
    398     }
    399     else
    400     {
    401         /* Running guest OS not suitable (yet) for automatic updating,
    402          * fall back to .ISO mounting. */
    403         fDoMount = true;
     386            fDoMount = true; /* Since automatic updating failed, fall back to .ISO mounting. */
     387        }
    404388    }
    405389
  • trunk/src/VBox/Main/GuestImpl.cpp

    r33595 r33696  
    163163        Guest *pGuest = aTask->pGuest;
    164164        AssertPtr(pGuest);
    165         /*Console *pConsole = pGuest->mParent;
    166         AssertPtr(pConsole);
    167         Console *pMachine = pConsole->machine();
    168         AssertPtr(pMachine);*/
    169165
    170166        if (aTask->progress)
    171167            aTask->progress->SetCurrentOperationProgress(10);
     168
     169        bool fIsWindows = false;
     170        Utf8Str osType = pGuest->mData.mOSTypeId;
     171        if (   osType.contains("Microsoft", Utf8Str::CaseInsensitive)
     172            || osType.contains("Windows", Utf8Str::CaseInsensitive))
     173        {
     174            fIsWindows = true; /* We have a Windows guest. */
     175        }
     176        else /* Everything else is not supported (yet). */
     177            throw setError(VBOX_E_NOT_SUPPORTED, tr("Guest OS not supported for automatic Guest Additions updating"));
    172178
    173179        /*
     
    176182         */
    177183        Utf8Str installerImage;
    178         Utf8Str osType = pGuest->mData.mOSTypeId;
    179         if (   osType.contains("Microsoft", Utf8Str::CaseInsensitive)
    180             || osType.contains("Windows", Utf8Str::CaseInsensitive))
     184        if (fIsWindows)
    181185        {
    182186            if (osType.contains("64", Utf8Str::CaseInsensitive))
     
    187191             * no further path processing needs to be done (yet). */
    188192        }
    189 
    190         /* No (suited) installer found? Bail out. */
    191         if (installerImage.isEmpty())
    192             throw setError(VBOX_E_FILE_ERROR, tr("Guest OS not supported for automatic Guest Additions updating yet"));
     193        Assert(!installerImage.isEmpty());
    193194
    194195        /*
     
    197198        RTISOFSFILE iso;
    198199        int vrc = RTIsoFsOpen(&iso, aTask->strSource.c_str());
    199         if (RT_SUCCESS(vrc))
     200        if (RT_FAILURE(vrc))
     201        {
     202            rc = setError(VBOX_E_FILE_ERROR, tr("Invalid installation medium detected"));
     203        }
     204        else
    200205        {
    201206            uint32_t cbOffset;
     
    209214            }
    210215
    211             /** @todo Only Windows! Don't use percent (like %TEMP%) env vars -- Windows
    212              *        will quote it like "%TEMP%" which results in a *not* working command
    213              *        line! */
    214             Utf8Str strInstallerPath = "C:\\Windows\\VBoxWindowsAdditions.exe";
     216            /* Specify the ouput path on the guest side. */
     217            Utf8Str strInstallerPath = "%TEMP%\\VBoxWindowsAdditions.exe";
    215218
    216219            if (RT_FAILURE(vrc))
     
    219222                {
    220223                    case VERR_FILE_NOT_FOUND:
    221                         rc = setError(VBOX_E_IPRT_ERROR, tr("Installer file was not found on medium"));
     224                        rc = setError(VBOX_E_IPRT_ERROR, tr("Setup file was not found on installation medium"));
    222225                        break;
    223226
     
    237240                com::SafeArray<IN_BSTR> env;
    238241
    239                 char szOutput[RTPATH_MAX];
    240                 if (RTStrPrintf(szOutput, sizeof(szOutput), "--output=%s", strInstallerPath.c_str()))
    241                 {
    242                     args.push_back(Bstr(VBOXSERVICE_TOOL_CAT).raw()); /* The actual (internal) tool to use (as argv[0]). */
    243                     args.push_back(Bstr(szOutput).raw());             /* We want to write a file ... */
    244                 }
    245                 else
    246                     rc = setError(VBOX_E_IPRT_ERROR, tr("Error preparing command line fopr copy operation"));
     242                args.push_back(Bstr(VBOXSERVICE_TOOL_CAT).raw());     /* The actual (internal) tool to use (as argv[0]). */
     243                args.push_back(Bstr("--output").raw());               /* We want to write a file ... */
     244                args.push_back(Bstr(strInstallerPath.c_str()).raw()); /* ... with this path. */
    247245
    248246                if (SUCCEEDED(rc))
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