VirtualBox

Changeset 34172 in vbox


Ignore:
Timestamp:
Nov 18, 2010 1:41:41 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
67896
Message:

Main/GuestImpl: Improved error/cancel handling for automatic Guest Additions updates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/GuestImpl.cpp

    r34155 r34172  
    158158
    159159    HRESULT rc = S_OK;
     160    BOOL fCompleted;
     161    BOOL fCanceled;
    160162
    161163    try
     
    164166        AssertPtr(pGuest);
    165167
    166         if (aTask->progress)
    167             aTask->progress->SetCurrentOperationProgress(10);
     168        aTask->progress->SetCurrentOperationProgress(10);
    168169
    169170        bool fIsWindows = false;
     
    233234            {
    234235                /* Okay, we're ready to start our copy routine on the guest! */
    235                 if (aTask->progress)
    236                     aTask->progress->SetCurrentOperationProgress(15);
    237 
    238236                LogRel(("Automatic update of Guest Additions started\n"));
     237                aTask->progress->SetCurrentOperationProgress(15);
    239238
    240239                /* Prepare command line args. */
     
    248247                if (SUCCEEDED(rc))
    249248                {
    250                     ComPtr<IProgress> progressCopy;
     249                    ComPtr<IProgress> progressCat;
    251250                    ULONG uPID;
    252251
     
    263262                                                        Bstr("").raw() /* Password */,
    264263                                                        5 * 1000 /* Wait 5s for getting the process started. */,
    265                                                         &uPID, progressCopy.asOutParam(), &vrc);
    266                     if (RT_FAILURE(vrc))
     264                                                        &uPID, progressCat.asOutParam(), &vrc);
     265                    if (   RT_FAILURE(vrc)
     266                        || FAILED(rc))
    267267                    {
    268268                        switch (vrc)
     
    271271                             * (< 4.0) which does not support automatic updating and/or has not the internal tool "vbox_cat". */
    272272                            case VERR_INVALID_PARAMETER:
    273                                 rc = setError(VBOX_E_NOT_SUPPORTED,
     273                                rc = setError(VBOX_E_IPRT_ERROR,
    274274                                              tr("Currently installed Guest Additions don't support automatic updating, please update them manually"));
    275275                                break;
     
    277277                             * no Guest Additions (on a supported automatic updating OS) are installed at all. */
    278278                            case VERR_TIMEOUT:
    279                                 rc = setError(VBOX_E_NOT_SUPPORTED,
     279                                rc = setError(VBOX_E_IPRT_ERROR,
    280280                                              tr("Guest Additions seem not to be installed on the guest or are not responding, please update them manually"));
    281281                                break;
    282282
    283283                            default:
     284                                rc = setError(E_FAIL,
     285                                              tr("Error copying Guest Additions installer (%Rrc)"), vrc);
    284286                                break;
    285287                        }
     
    288290                    {
    289291                        LogRel(("Copying Guest Additions installer to guest ...\n"));
    290 
    291                         if (aTask->progress)
    292                             aTask->progress->SetCurrentOperationProgress(20);
     292                        aTask->progress->SetCurrentOperationProgress(20);
    293293
    294294                        /* Wait for process to exit ... */
    295                         BOOL fCompleted = FALSE;
    296                         BOOL fCanceled = FALSE;
    297 
    298                         size_t cbRead;
    299                         size_t cbToRead;
    300295                        SafeArray<BYTE> aInputData(_64K);
    301                         while (   SUCCEEDED(progressCopy->COMGETTER(Completed(&fCompleted)))
     296                        while (   SUCCEEDED(progressCat->COMGETTER(Completed(&fCompleted)))
    302297                               && !fCompleted)
    303298                        {
     299                            size_t cbRead;
    304300                            /* cbLength contains remaining bytes of our installer file
    305301                             * opened above to read. */
    306                             cbToRead = RT_MIN(cbLength, _64K);
     302                            size_t cbToRead = RT_MIN(cbLength, _64K);
    307303                            if (cbToRead)
    308304                            {
     
    321317                                    }
    322318
     319                                    /*
     320                                     * Task canceled by caller?
     321                                     * Then let the started process (cat) know by specifying end-of-file
     322                                     * for the netxt input event that hopefully leads to a graceful exit ...
     323                                     */
     324                                    if (   SUCCEEDED(aTask->progress->COMGETTER(Canceled(&fCanceled)))
     325                                        && fCanceled)
     326                                    {
     327                                        uFlags |= ProcessInputFlag_EndOfFile;
     328                                    }
     329
    323330                                    /* Transfer the current chunk ... */
     331                                #ifdef DEBUG_andy
     332                                    LogRel(("Copying Guest Additions (%u bytes left) ...\n", cbLength));
     333                                #endif
    324334                                    ULONG uBytesWritten;
    325                                     rc = SetProcessInput(uPID, uFlags,
    326                                                          ComSafeArrayAsInParam(aInputData), &uBytesWritten);
     335                                    rc = pGuest->SetProcessInput(uPID, uFlags,
     336                                                                 ComSafeArrayAsInParam(aInputData), &uBytesWritten);
    327337                                    if (FAILED(rc))
    328338                                        break;
    329339
     340                                    /* If task was canceled above also cancel the process execution. */
     341                                    if (fCanceled)
     342                                        progressCat->Cancel();
     343
     344                                #ifdef DEBUG_andy
     345                                    LogRel(("Copying Guest Additions (%u bytes written) ...\n", uBytesWritten));
     346                                #endif
    330347                                    Assert(cbLength >= uBytesWritten);
    331348                                    cbLength -= uBytesWritten;
    332 
    333                                     /* Progress canceled by Main API? */
    334                                     if (   SUCCEEDED(progressCopy->COMGETTER(Canceled(&fCanceled)))
    335                                         && fCanceled)
    336                                     {
    337                                         break;
    338                                     }
    339                                     if (aTask->progress)
    340                                     {
    341                                         if (SUCCEEDED(aTask->progress->COMGETTER(Canceled(&fCanceled)))
    342                                             && fCanceled)
    343                                             break;
    344                                     }
    345349                                }
     350                            }
     351
     352                            /* Internal progress canceled? */
     353                            if (   SUCCEEDED(progressCat->COMGETTER(Canceled(&fCanceled)))
     354                                && fCanceled)
     355                            {
     356                                aTask->progress->Cancel();
     357                                break;
    346358                            }
    347359                        }
     
    351363            RTIsoFsClose(&iso);
    352364
    353             if (SUCCEEDED(rc))
     365            if (   SUCCEEDED(rc)
     366                && (   SUCCEEDED(aTask->progress->COMGETTER(Canceled(&fCanceled)))
     367                    && !fCanceled
     368                   )
     369               )
    354370            {
    355371                /*
     
    357373                 * (with system rights).
    358374                 */
    359                 if (aTask->progress)
    360                     aTask->progress->SetCurrentOperationProgress(66);
     375                LogRel(("Preparing to execute Guest Additions update ...\n"));
     376                aTask->progress->SetCurrentOperationProgress(66);
    361377
    362378                /* Prepare command line args for installer. */
     
    400416        }
    401417    }
    402     catch(HRESULT aRC)
     418    catch (HRESULT aRC)
    403419    {
    404420        rc = aRC;
     
    406422
    407423    /* Clean up */
    408     if (aTask->progress)
    409         aTask->progress->SetCurrentOperationProgress(99);
    410 
    411     /* Assign data. */
    412     if (rc == S_OK)
    413     {
    414     }
    415 
    416424    aTask->rc = rc;
    417 
    418     if (!aTask->progress.isNull())
     425    aTask->progress->SetCurrentOperationProgress(99);
     426
     427    if (   SUCCEEDED(aTask->progress->COMGETTER(Canceled(&fCanceled)))
     428        && !fCanceled)
     429    {
     430        /* Task completed, regardless whether successful/failed. */
     431
     432        /* Assign data. */
     433        if (rc == S_OK)
     434        {
     435            /* No data to assign yet. */
     436        }
     437
    419438        aTask->progress->notifyComplete(rc);
     439    }
     440    else /* The task was canceled, set error code to prevent assertions. */
     441    {
     442        LogRel(("Automatic Guest Additions update was canceled\n"));
     443        aTask->progress->notifyComplete(VBOX_E_IPRT_ERROR,
     444                                        COM_IIDOF(IGuest),
     445                                        Guest::getStaticComponentName(),
     446                                        "Automatic Guest Additions update was canceled");
     447    }
    420448
    421449    LogFlowFunc(("rc=%Rhrc\n", rc));
     
    25772605
    25782606        /* Initialize our worker task. */
    2579         std::auto_ptr<TaskGuest> task(new TaskGuest(TaskGuest::UpdateGuestAdditions, this, progress));
     2607        TaskGuest *pTask = new TaskGuest(TaskGuest::UpdateGuestAdditions, this, progress);
     2608        AssertPtr(pTask);
     2609        std::auto_ptr<TaskGuest> task(pTask);
    25802610
    25812611        /* Assign data - in that case aSource is the full path
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