~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Additions/common/VBoxService/VBoxServiceCpuHotPlug.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: VBoxServiceCpuHotPlug.cpp $ */
 
1
/* $Id: VBoxServiceCpuHotPlug.cpp 33468 2010-10-26 12:49:59Z vboxsync $ */
2
2
/** @file
3
3
 * VBoxService - Guest Additions CPU Hot Plugging Service.
4
4
 */
22
22
#include <iprt/dir.h>
23
23
#include <iprt/file.h>
24
24
#include <iprt/mem.h>
 
25
#include <iprt/path.h>
25
26
#include <iprt/string.h>
26
27
#include <iprt/thread.h>
27
28
#include <VBox/VBoxGuestLib.h>
153
154
            for (unsigned iCompCurr = 0; iCompCurr < pAcpiCpuPathLvl->cComponents; iCompCurr++)
154
155
            {
155
156
                PCSYSFSCPUPATHCOMP pPathComponent = &pAcpiCpuPathLvl->aComponentsPossible[iCompCurr];
 
157
 
 
158
                /* Open the directory */
156
159
                PRTDIR pDirCurr = NULL;
157
 
                char *pszPathTmp = NULL;
158
 
                bool fFound = false;
159
 
 
160
 
                rc = RTStrAPrintf(&pszPathTmp, "%s/%s*", pszPath, pPathComponent->pcszName);
161
 
                if (RT_FAILURE(rc))
162
 
                    break;
163
 
 
164
 
                /* Open the directory */
165
 
                rc = RTDirOpenFiltered(&pDirCurr, pszPathTmp, RTDIRFILTER_WINNT);
166
 
                if (RT_FAILURE(rc))
 
160
                char *pszPathTmp = RTPathJoinA(pszPath, pPathComponent->pcszName);
 
161
                if (pszPathTmp)
167
162
                {
 
163
                    rc = RTDirOpenFiltered(&pDirCurr, pszPathTmp, RTDIRFILTER_WINNT);
168
164
                    RTStrFree(pszPathTmp);
 
165
                }
 
166
                else
 
167
                    rc = VERR_NO_STR_MEMORY;
 
168
                if (RT_FAILURE(rc))
169
169
                    break;
170
 
                }
171
170
 
172
171
                /* Search if the current directory contains one of the possible parts. */
 
172
                size_t cchName = strlen(pPathComponent->pcszName);
173
173
                RTDIRENTRY DirFolderContent;
 
174
                bool fFound = false;
174
175
                while (RT_SUCCESS(RTDirRead(pDirCurr, &DirFolderContent, NULL))) /* Assumption that szName has always enough space */
175
176
                {
176
 
                    if (!strncmp(DirFolderContent.szName, pPathComponent->pcszName, strlen(pPathComponent->pcszName)))
 
177
                    if (   DirFolderContent.cbName >= cchName
 
178
                        && !strncmp(DirFolderContent.szName, pPathComponent->pcszName, cchName))
177
179
                    {
178
 
                        char *pszPathLvl = NULL;
179
 
 
180
180
                        /* Found, use the complete name to dig deeper. */
181
181
                        fFound = true;
182
182
                        pAcpiCpuPathLvl->uId = iCompCurr;
183
 
                        rc = RTStrAPrintf(&pszPathLvl, "%s/%s", pszPath, DirFolderContent.szName);
184
 
 
185
 
                        if (RT_SUCCESS(rc))
 
183
                        char *pszPathLvl = RTPathJoinA(pszPath, DirFolderContent.szName);
 
184
                        if (pszPathLvl)
186
185
                        {
187
186
                            RTStrFree(pszPath);
188
187
                            pszPath = pszPathLvl;
189
188
                        }
 
189
                        else
 
190
                            rc = VERR_NO_STR_MEMORY;
190
191
                        break;
191
192
                    }
192
193
                }
234
235
 
235
236
        /* Init everything. */
236
237
        Assert(pAcpiCpuPathLvl->uId != ACPI_CPU_PATH_NOT_PROBED);
237
 
        rc = RTStrAPrintf(&pszPath,
238
 
                          "%s/%s*", SYSFS_ACPI_CPU_PATH,
239
 
                          pAcpiCpuPathLvl->aComponentsPossible[pAcpiCpuPathLvl->uId].pcszName);
240
 
        if (RT_FAILURE(rc))
241
 
            return rc;
 
238
        pszPath = RTPathJoinA(SYSFS_ACPI_CPU_PATH, pAcpiCpuPathLvl->aComponentsPossible[pAcpiCpuPathLvl->uId].pcszName);
 
239
        if (!pszPath)
 
240
            return VERR_NO_STR_MEMORY;
242
241
 
243
242
        pAcpiCpuPathLvl->pszPath = RTStrDup(SYSFS_ACPI_CPU_PATH);
244
243
        if (!pAcpiCpuPathLvl->pszPath)
245
 
            return VERR_NO_MEMORY;
 
244
        {
 
245
            RTStrFree(pszPath);
 
246
            return VERR_NO_STR_MEMORY;
 
247
        }
246
248
 
247
249
        /* Open the directory */
248
250
        rc = RTDirOpenFiltered(&pAcpiCpuPathLvl->pDir, pszPath, RTDIRFILTER_WINNT);
258
260
                rc = RTDirRead(pAcpiCpuPathLvl->pDir, &DirFolderContent, NULL);
259
261
                if (RT_SUCCESS(rc))
260
262
                {
261
 
                    char *pszPathCurr;
262
 
 
263
263
                    /* Create the new path. */
264
 
                    rc = RTStrAPrintf(&pszPathCurr, "%s/%s", pAcpiCpuPathLvl->pszPath, DirFolderContent.szName);
265
 
                    if (RT_FAILURE(rc))
 
264
                    char *pszPathCurr = RTPathJoinA(pAcpiCpuPathLvl->pszPath, DirFolderContent.szName);
 
265
                    if (!pszPathCurr)
 
266
                    {
 
267
                        rc = VERR_NO_STR_MEMORY;
266
268
                        break;
 
269
                    }
267
270
 
268
271
                    /* If this is the last level check for the given core and package id. */
269
272
                    if (iLvlCurr == RT_ELEMENTS(g_aAcpiCpuPath) - 1)
305
308
 
306
309
                        Assert(pAcpiCpuPathLvl->uId != ACPI_CPU_PATH_NOT_PROBED);
307
310
 
308
 
                        rc = RTStrAPrintf(&pszPathDir, "%s/%s*", pszPathCurr, pPathComponent->pcszName);
309
 
                        if (RT_FAILURE(rc))
 
311
                        pszPathDir = RTPathJoinA(pszPathCurr, pPathComponent->pcszName);
 
312
                        if (!pszPathDir)
 
313
                        {
 
314
                            rc = VERR_NO_STR_MEMORY;
310
315
                            break;
 
316
                        }
311
317
 
312
318
                        VBoxServiceVerbose(3, "New path %s\n", pszPathDir);
313
319