VirtualBox

Changeset 21432 in vbox for trunk


Ignore:
Timestamp:
Jul 9, 2009 11:34:26 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
49820
Message:

Main: fix some exception handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/linux/HostHardwareLinux.cpp

    r19094 r21432  
    143143            // this is a good guess usually
    144144            if (validateDevice("/dev/cdrom", true))
    145                 try
    146                 {
    147                     mDVDList.push_back (DriveInfo ("/dev/cdrom"));
    148                 }
    149                 catch (std::bad_alloc)
    150                 {
    151                     rc = VERR_NO_MEMORY;
    152                 }
     145                mDVDList.push_back(DriveInfo ("/dev/cdrom"));
    153146
    154147            // check the mounted drives
     
    161154#endif
    162155    }
    163     catch (std::bad_alloc)
     156    catch(std::bad_alloc &e)
    164157    {
    165158        rc = VERR_NO_MEMORY;
     
    200193                RTStrPrintf(devName, sizeof(devName), "/dev/fd%d", i);
    201194                if (validateDevice(devName, false))
    202                     try
    203                     {
    204                         mFloppyList.push_back (DriveInfo (devName));
    205                     }
    206                     catch (std::bad_alloc)
    207                     {
    208                         rc = VERR_NO_MEMORY;
    209                     }
     195                    mFloppyList.push_back (DriveInfo (devName));
    210196            }
    211197        }
    212198#endif
    213199    }
    214     catch (std::bad_alloc)
     200    catch(std::bad_alloc &e)
    215201    {
    216202        rc = VERR_NO_MEMORY;
     
    244230#endif /* RT_OS_LINUX */
    245231    }
    246     catch (std::bad_alloc)
     232    catch(std::bad_alloc &e)
    247233    {
    248234        rc = VERR_NO_MEMORY;
     
    442428    int rc = VINF_SUCCESS;
    443429    bool success = false;
    444     RTMemAutoPtr<char, RTStrFree> drive;
    445     const char *pszValue = RTEnvGet (pszVar);
    446     if (pszValue != NULL)
    447     {
    448         drive = RTStrDup (pszValue);
    449         if (!drive)
    450             rc = VERR_NO_MEMORY;
    451     }
    452     if (pszValue != NULL && RT_SUCCESS (rc))
    453     {
    454         char *pDrive = drive.get();
    455         char *pDriveNext = strchr (pDrive, ':');
    456         while (pDrive != NULL && *pDrive != '\0')
    457         {
    458             if (pDriveNext != NULL)
    459                 *pDriveNext = '\0';
    460             if (validateDevice(pDrive, isDVD))
     430
     431    try
     432    {
     433        RTMemAutoPtr<char, RTStrFree> drive;
     434        const char *pszValue = RTEnvGet (pszVar);
     435        if (pszValue != NULL)
     436        {
     437            drive = RTStrDup (pszValue);
     438            if (!drive)
     439                rc = VERR_NO_MEMORY;
     440        }
     441        if (pszValue != NULL && RT_SUCCESS (rc))
     442        {
     443            char *pDrive = drive.get();
     444            char *pDriveNext = strchr (pDrive, ':');
     445            while (pDrive != NULL && *pDrive != '\0')
    461446            {
    462                 try
     447                if (pDriveNext != NULL)
     448                    *pDriveNext = '\0';
     449                if (validateDevice(pDrive, isDVD))
    463450                {
    464451                    pList->push_back (DriveInfo (pDrive));
     452                    success = true;
    465453                }
    466                 catch (std::bad_alloc)
     454                if (pDriveNext != NULL)
    467455                {
    468                     rc = VERR_NO_MEMORY;
     456                    pDrive = pDriveNext + 1;
     457                    pDriveNext = strchr (pDrive, ':');
    469458                }
    470                 success = true;
     459                else
     460                    pDrive = NULL;
    471461            }
    472             if (pDriveNext != NULL)
    473             {
    474                 pDrive = pDriveNext + 1;
    475                 pDriveNext = strchr (pDrive, ':');
    476             }
    477             else
    478                 pDrive = NULL;
    479462        }
    480     }
    481     if (pfSuccess != NULL)
    482         *pfSuccess = success;
     463        if (pfSuccess != NULL)
     464            *pfSuccess = success;
     465    }
     466    catch(std::bad_alloc &e)
     467    {
     468        rc = VERR_NO_MEMORY;
     469    }
    483470    LogFlowFunc (("rc=%Rrc, success=%d\n", rc, success));
    484471    return rc;
     
    500487    if (mtab)
    501488    {
    502         struct mntent *mntent;
    503         RTMemAutoPtr <char, RTStrFree> mnt_type, mnt_dev;
    504         char *tmp;
    505         while (RT_SUCCESS (rc) && (mntent = getmntent(mtab)))
    506         {
    507             mnt_type = RTStrDup (mntent->mnt_type);
    508             mnt_dev = RTStrDup (mntent->mnt_fsname);
    509             if (!mnt_type || !mnt_dev)
    510                 rc = VERR_NO_MEMORY;
    511             // supermount fs case
    512             if (RT_SUCCESS (rc) && strcmp(mnt_type.get(), "supermount") == 0)
     489        try
     490        {
     491            struct mntent *mntent;
     492            RTMemAutoPtr <char, RTStrFree> mnt_type, mnt_dev;
     493            char *tmp;
     494            while (RT_SUCCESS (rc) && (mntent = getmntent(mtab)))
    513495            {
    514                 tmp = strstr(mntent->mnt_opts, "fs=");
    515                 if (tmp)
     496                mnt_type = RTStrDup (mntent->mnt_type);
     497                mnt_dev = RTStrDup (mntent->mnt_fsname);
     498                if (!mnt_type || !mnt_dev)
     499                    rc = VERR_NO_MEMORY;
     500                // supermount fs case
     501                if (RT_SUCCESS (rc) && strcmp(mnt_type.get(), "supermount") == 0)
    516502                {
    517                     mnt_type = RTStrDup(tmp + strlen("fs="));
    518                     if (!mnt_type)
    519                         rc = VERR_NO_MEMORY;
    520                     else
     503                    tmp = strstr(mntent->mnt_opts, "fs=");
     504                    if (tmp)
    521505                    {
    522                         tmp = strchr(mnt_type.get(), ',');
    523                         if (tmp)
    524                             *tmp = '\0';
     506                        mnt_type = RTStrDup(tmp + strlen("fs="));
     507                        if (!mnt_type)
     508                            rc = VERR_NO_MEMORY;
     509                        else
     510                        {
     511                            tmp = strchr(mnt_type.get(), ',');
     512                            if (tmp)
     513                                *tmp = '\0';
     514                        }
     515                    }
     516                    tmp = strstr(mntent->mnt_opts, "dev=");
     517                    if (tmp)
     518                    {
     519                        mnt_dev = RTStrDup(tmp + strlen("dev="));
     520                        if (!mnt_dev)
     521                            rc = VERR_NO_MEMORY;
     522                        else
     523                        {
     524                            tmp = strchr(mnt_dev.get(), ',');
     525                            if (tmp)
     526                                *tmp = '\0';
     527                        }
    525528                    }
    526529                }
    527                 tmp = strstr(mntent->mnt_opts, "dev=");
    528                 if (tmp)
     530                // use strstr here to cover things fs types like "udf,iso9660"
     531                if (RT_SUCCESS (rc) && strstr(mnt_type.get(), "iso9660") == 0)
    529532                {
    530                     mnt_dev = RTStrDup(tmp + strlen("dev="));
    531                     if (!mnt_dev)
    532                         rc = VERR_NO_MEMORY;
    533                     else
     533                    if (validateDevice(mnt_dev.get(), true))
    534534                    {
    535                         tmp = strchr(mnt_dev.get(), ',');
    536                         if (tmp)
    537                             *tmp = '\0';
     535                        bool insert = true;
     536                        struct stat srcInfo;
     537                        if (stat (mnt_dev.get(), &srcInfo) < 0)
     538                            insert = false;
     539                        for (DriveInfoList::const_iterator it = pList->begin();
     540                            insert && it != pList->end(); ++it)
     541                        {
     542                            struct stat destInfo;
     543                            if (   (stat (it->mDevice.c_str(), &destInfo) == 0)
     544                                && (srcInfo.st_rdev == destInfo.st_rdev))
     545                                insert = false;
     546                        }
     547                        if (insert)
     548                            pList->push_back (DriveInfo (mnt_dev.get()));
    538549                    }
    539550                }
    540551            }
    541             // use strstr here to cover things fs types like "udf,iso9660"
    542             if (RT_SUCCESS (rc) && strstr(mnt_type.get(), "iso9660") == 0)
    543             {
    544                 if (validateDevice(mnt_dev.get(), true))
    545                 {
    546                     bool insert = true;
    547                     struct stat srcInfo;
    548                     if (stat (mnt_dev.get(), &srcInfo) < 0)
    549                         insert = false;
    550                     for (DriveInfoList::const_iterator it = pList->begin();
    551                          insert && it != pList->end(); ++it)
    552                     {
    553                         struct stat destInfo;
    554                         if (   (stat (it->mDevice.c_str(), &destInfo) == 0)
    555                             && (srcInfo.st_rdev == destInfo.st_rdev))
    556                             insert = false;
    557                     }
    558                     if (insert)
    559                         try
    560                         {
    561                             pList->push_back (DriveInfo (mnt_dev.get()));
    562                         }
    563                         catch (std::bad_alloc)
    564                         {
    565                             rc = VERR_NO_MEMORY;
    566                         }
    567                 }
    568             }
     552        }
     553        catch(std::bad_alloc &e)
     554        {
     555            rc = VERR_NO_MEMORY;
    569556        }
    570557        endmntent(mtab);
     
    882869            pMatches->push_back(pszUdi);
    883870        }
    884         catch (std::bad_alloc)
     871        catch(std::bad_alloc &e)
    885872        {
    886873            rc = VERR_NO_MEMORY;
     
    10401027            pMatches->push_back(fMatches ? values[i] : "");
    10411028        }
    1042         catch (std::bad_alloc)
     1029        catch(std::bad_alloc &e)
    10431030        {
    10441031            rc = VERR_NO_MEMORY;
     
    11281115                pList->push_back (DriveInfo (pszDevice, pszUdi, description));
    11291116            }
    1130             catch (std::bad_alloc)
     1117            catch(std::bad_alloc &e)
    11311118            {
    11321119                rc = VERR_NO_MEMORY;
     
    12131200                    pList->push_back (info);
    12141201                }
    1215                 catch (std::bad_alloc)
     1202                catch(std::bad_alloc &e)
    12161203                {
    12171204                    rc = VERR_NO_MEMORY;
     
    12991286                    pList->push_back (info);
    13001287                }
    1301                 catch (std::bad_alloc)
     1288                catch(std::bad_alloc &e)
    13021289                {
    13031290                    rc = VERR_NO_MEMORY;
     
    13881375                pList->push_back (pszSysfsPath);
    13891376            }
    1390             catch (std::bad_alloc)
     1377            catch(std::bad_alloc &e)
    13911378            {
    13921379               rc = VERR_NO_MEMORY;
Note: See TracChangeset for help on using the changeset viewer.

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