VirtualBox

Changeset 17003 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Feb 23, 2009 11:04:55 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
43198
Message:

iprt: Reading the exe link doesn't work on root processes. So use the content of the cmdline file instead.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/linux/RTProcIsRunningByName-linux.cpp

    r16999 r17003  
    3737#include <iprt/dir.h>
    3838#include <iprt/path.h>
     39#include <iprt/stream.h>
    3940#include <iprt/param.h>
    4041#include <iprt/assert.h>
     
    6667            {
    6768                /*
    68                  * Build the path to the proc exec file of this process.
     69                 * Build the path to the proc cmdline file of this process.
    6970                 */
    7071                char *pszPath;
    71                 RTStrAPrintf(&pszPath, "/proc/%s/exe", DirEntry.szName);
    72                 /*
    73                  * Read the file name of the link pointing at.
    74                  */
    75                 char szExe[RTPATH_MAX];
    76                 size_t cchExe = sizeof(szExe)-1;
    77                 int cchLink = readlink(pszPath, szExe, cchExe);
    78                 if (cchLink > 0 && (size_t)cchLink <= cchExe)
     72                RTStrAPrintf(&pszPath, "/proc/%s/cmdline", DirEntry.szName);
     73                PRTSTREAM pStream;
     74                rc = RTStrmOpen(pszPath, "r", &pStream);
     75                if(RT_SUCCESS(rc))
    7976                {
    80                     szExe[cchLink] = '\0';
     77                    char szLine[RTPATH_MAX];
     78                    /*
     79                     * The fist line should be the application path always.
     80                     */
     81                    RTStrmGetLine(pStream, szLine, sizeof(szLine));
    8182                    /*
    8283                     * We are interested on the file name part only.
    8384                     */
    84                     char *pszFilename = RTPathFilename(szExe);
     85                    char *pszFilename = RTPathFilename(szLine);
    8586                    if (RTStrCmp(pszFilename, pszName) == 0)
    8687                    {
     
    8889                         * Clean up
    8990                         */
     91                        RTStrmClose(pStream);
    9092                        RTStrFree(pszPath);
    9193                        RTDirClose(pDir);
    9294                        return true;
    9395                    }
     96                    RTStrmClose(pStream);
    9497                }
    9598                RTStrFree(pszPath);
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