VirtualBox

Changeset 25942 in vbox for trunk/src/VBox/Additions


Ignore:
Timestamp:
Jan 20, 2010 5:26:22 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56784
Message:

*: RTEnv usage cleanup - avoid RTEnvGet() as it doesn't necessarily return UTF-8 encoded strings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/main.cpp

    r25873 r25942  
    3434#include <iprt/initterm.h>
    3535#include <iprt/path.h>
     36#include <iprt/param.h>
    3637#include <iprt/stream.h>
    3738#include <iprt/string.h>
     
    5051/** The name of our pidfile.  It is global for the benefit of the cleanup
    5152 * routine. */
    52 static char *g_pszPidFile;
     53static char g_szPidFile[RTPATH_MAX];
    5354/** The file handle of our pidfile.  It is global for the benefit of the
    5455 * cleanup routine. */
     
    6465        delete g_pService;
    6566    }
    66     if (g_pszPidFile && g_hPidFile)
    67         VbglR3ClosePidFile(g_pszPidFile, g_hPidFile);
     67    if (g_szPidFile && g_hPidFile)
     68        VbglR3ClosePidFile(g_szPidFile, g_hPidFile);
    6869    VbglR3Term();
    6970    exit(0);
     
    230231        }
    231232    }
    232     const char *pszHome = RTEnvGet("HOME");
    233     if (pszHome == NULL)
    234     {
    235         RTPrintf("VBoxClient: failed to get home directory.  Exiting.\n");
    236         Log(("VBoxClient: failed to get home directory.  Exiting.\n"));
    237         return 1;
    238     }
    239     if (RTStrAPrintf(&g_pszPidFile, "%s/%s", pszHome, g_pService->getPidFilePath()) == -1)
    240     if (pszHome == NULL)
    241     {
    242         RTPrintf("VBoxClient: out of memory.  Exiting.\n");
    243         Log(("VBoxClient: out of memory.  Exiting.\n"));
    244         return 1;
    245     }
     233    /** @todo explain why we aren't using RTPathUserHome here so it doesn't get
     234     *        changed accidentally during some cleanup effort. */
     235    rc = RTEnvGetEx(RTENV_DEFAULT, "HOME", g_szPidFile, sizeof(g_szPidFile), NULL);
     236    if (RT_FAILURE(rc))
     237    {
     238        RTPrintf("VBoxClient: failed to get home directory, rc=%Rrc.  Exiting.\n", rc);
     239        Log(("VBoxClient: failed to get home directory, rc=%Rrc.  Exiting.\n", rc));
     240        return 1;
     241    }
     242    rc = RTPathAppend(g_szPidFile, sizeof(g_szPidFile), g_pService->getPidFilePath());
     243    if (RT_FAILURE(rc))
     244    {
     245        RTPrintf("VBoxClient: RTPathAppend failed with rc=%Rrc.  Exiting.\n", rc);
     246        Log(("VBoxClient: RTPathAppend failed with rc=%Rrc.  Exiting.\n", rc));
     247        return 1;
     248    }
     249
    246250    /* Initialise the guest library. */
    247251    if (RT_FAILURE(VbglR3InitUser()))
     
    251255        return 1;
    252256    }
    253     if (g_pszPidFile && RT_FAILURE(VbglR3PidFile(g_pszPidFile, &g_hPidFile)))
     257    if (g_szPidFile && RT_FAILURE(VbglR3PidFile(g_szPidFile, &g_hPidFile)))
    254258    {
    255259        RTPrintf("Failed to create a pidfile.  Exiting.\n");
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