summaryrefslogtreecommitdiff
path: root/indra/llvfs
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2018-12-14 15:38:13 -0500
committerNat Goodspeed <nat@lindenlab.com>2018-12-14 15:38:13 -0500
commitc4096f670c7b3d43f8a5c1f65ef7e02033b0329d (patch)
tree29f3f8cae0dc5bfc983a25ec6e4e9afb245d4925 /indra/llvfs
parent132e708fec50fd756b822925313456c70a4ff27f (diff)
SL-10153: Review and rationalize fetching paths from environment.
Use LLStringUtil::getenv() or getoptenv() whenever we fetch a string that will be used as a pathname. Use LLFile::tmpdir() instead of getenv("TEMP"). As an added extra-special bonus, finally clean up $TMP/llcontrol-test-zzzzzz directories that have been accumulating every time we run a local build!
Diffstat (limited to 'indra/llvfs')
-rw-r--r--indra/llvfs/lldir_linux.cpp33
-rw-r--r--indra/llvfs/lldir_solaris.cpp60
-rw-r--r--indra/llvfs/lldir_win32.cpp26
3 files changed, 51 insertions, 68 deletions
diff --git a/indra/llvfs/lldir_linux.cpp b/indra/llvfs/lldir_linux.cpp
index 2cd06b81f8..80ad05345a 100644
--- a/indra/llvfs/lldir_linux.cpp
+++ b/indra/llvfs/lldir_linux.cpp
@@ -29,6 +29,7 @@
#include "lldir_linux.h"
#include "llerror.h"
#include "llrand.h"
+#include "llstring.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -40,28 +41,24 @@ static std::string getCurrentUserHome(char* fallback)
{
const uid_t uid = getuid();
struct passwd *pw;
- char *result_cstr = fallback;
-
+
pw = getpwuid(uid);
if ((pw != NULL) && (pw->pw_dir != NULL))
{
- result_cstr = (char*) pw->pw_dir;
+ return pw->pw_dir;
+ }
+
+ LL_INFOS() << "Couldn't detect home directory from passwd - trying $HOME" << LL_ENDL;
+ auto home_env = LLStringUtil::getoptenv("HOME");
+ if (home_env)
+ {
+ return *home_env;
}
else
{
- LL_INFOS() << "Couldn't detect home directory from passwd - trying $HOME" << LL_ENDL;
- const char *const home_env = getenv("HOME"); /* Flawfinder: ignore */
- if (home_env)
- {
- result_cstr = (char*) home_env;
- }
- else
- {
- LL_WARNS() << "Couldn't detect home directory! Falling back to " << fallback << LL_ENDL;
- }
+ LL_WARNS() << "Couldn't detect home directory! Falling back to " << fallback << LL_ENDL;
+ return fallback;
}
-
- return std::string(result_cstr);
}
@@ -156,18 +153,18 @@ void LLDir_Linux::initAppDirs(const std::string &app_name,
if (!app_read_only_data_dir.empty())
{
mAppRODataDir = app_read_only_data_dir;
- mSkinBaseDir = mAppRODataDir + mDirDelimiter + "skins";
+ mSkinBaseDir = add(mAppRODataDir, "skins");
}
mAppName = app_name;
std::string upper_app_name(app_name);
LLStringUtil::toUpper(upper_app_name);
- char* app_home_env = getenv((upper_app_name + "_USER_DIR").c_str()); /* Flawfinder: ignore */
+ auto app_home_env(LLStringUtil::getoptenv(upper_app_name + "_USER_DIR"));
if (app_home_env)
{
// user has specified own userappdir i.e. $SECONDLIFE_USER_DIR
- mOSUserAppDir = app_home_env;
+ mOSUserAppDir = *app_home_env;
}
else
{
diff --git a/indra/llvfs/lldir_solaris.cpp b/indra/llvfs/lldir_solaris.cpp
index d3536a12ee..f18560ff20 100644
--- a/indra/llvfs/lldir_solaris.cpp
+++ b/indra/llvfs/lldir_solaris.cpp
@@ -29,6 +29,7 @@
#include "lldir_solaris.h"
#include "llerror.h"
#include "llrand.h"
+#include "llstring.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -41,30 +42,28 @@
static std::string getCurrentUserHome(char* fallback)
{
+ // fwiw this exactly duplicates getCurrentUserHome() in lldir_linux.cpp...
+ // we should either derive both from LLDir_Posix or just axe Solaris.
const uid_t uid = getuid();
struct passwd *pw;
- char *result_cstr = fallback;
-
+
pw = getpwuid(uid);
if ((pw != NULL) && (pw->pw_dir != NULL))
{
- result_cstr = (char*) pw->pw_dir;
+ return pw->pw_dir;
+ }
+
+ LL_INFOS() << "Couldn't detect home directory from passwd - trying $HOME" << LL_ENDL;
+ auto home_env = LLStringUtil::getoptenv("HOME");
+ if (home_env)
+ {
+ return *home_env;
}
else
{
- LL_INFOS() << "Couldn't detect home directory from passwd - trying $HOME" << LL_ENDL;
- const char *const home_env = getenv("HOME"); /* Flawfinder: ignore */
- if (home_env)
- {
- result_cstr = (char*) home_env;
- }
- else
- {
- LL_WARNS() << "Couldn't detect home directory! Falling back to " << fallback << LL_ENDL;
- }
+ LL_WARNS() << "Couldn't detect home directory! Falling back to " << fallback << LL_ENDL;
+ return fallback;
}
-
- return std::string(result_cstr);
}
@@ -135,27 +134,15 @@ LLDir_Solaris::LLDir_Solaris()
//NOTE: Why force people to cd into the package directory?
// Look for SECONDLIFE env variable and use it, if set.
- char *dcf = getenv("SECONDLIFE");
- if(dcf != NULL){
- (void)strcpy(path, dcf);
- (void)strcat(path, "/bin"); //NOTE: make sure we point at the bin
- mExecutableDir = strdup(path);
+ auto SECONDLIFE(LLDirUtil::getoptenv("SECONDLIFE"));
+ if(SECONDLIFE){
+ mExecutableDir = add(*SECONDLIFE, "bin"); //NOTE: make sure we point at the bin
}else{
- // plunk a null at last '/' to get exec dir
- char *s = execpath + strlen(execpath) -1;
- while(*s != '/' && s != execpath){
- --s;
- }
-
- if(s != execpath){
- *s = (char)NULL;
-
- mExecutableDir = strdup(execpath);
- LL_INFOS() << "mExecutableDir = [" << mExecutableDir << "]" << LL_ENDL;
- }
+ mExecutableDir = getDirName(execpath);
+ LL_INFOS() << "mExecutableDir = [" << mExecutableDir << "]" << LL_ENDL;
}
-
- mLLPluginDir = mExecutableDir + mDirDelimiter + "llplugin";
+
+ mLLPluginDir = add(mExecutableDir, "llplugin");
// *TODO: don't use /tmp, use $HOME/.secondlife/tmp or something.
mTempDir = "/tmp";
@@ -175,17 +162,18 @@ void LLDir_Solaris::initAppDirs(const std::string &app_name,
if (!app_read_only_data_dir.empty())
{
mAppRODataDir = app_read_only_data_dir;
+ mSkinBaseDir = add(mAppRODataDir, "skins");
}
mAppName = app_name;
std::string upper_app_name(app_name);
LLStringUtil::toUpper(upper_app_name);
- char* app_home_env = getenv((upper_app_name + "_USER_DIR").c_str()); /* Flawfinder: ignore */
+ auto app_home_env(LLStringUtil::getoptenv(upper_app_name + "_USER_DIR"));
if (app_home_env)
{
// user has specified own userappdir i.e. $SECONDLIFE_USER_DIR
- mOSUserAppDir = app_home_env;
+ mOSUserAppDir = *app_home_env;
}
else
{
diff --git a/indra/llvfs/lldir_win32.cpp b/indra/llvfs/lldir_win32.cpp
index fc4680bbfb..acf734f16b 100644
--- a/indra/llvfs/lldir_win32.cpp
+++ b/indra/llvfs/lldir_win32.cpp
@@ -30,6 +30,7 @@
#include "lldir_win32.h"
#include "llerror.h"
+#include "llstring.h"
#include "stringize.h"
#include "llfile.h"
#include <shlobj.h>
@@ -55,17 +56,17 @@ namespace
{
switch (state)
{
+ boost::optional<std::string> prelog_name;
+
case prst::INIT:
// assume we failed, until we succeed
state = prst::SKIP;
- // can't initialize within one case of a switch statement
- const char* prelog_name;
- prelog_name = getenv("PRELOG");
+ prelog_name = LLDirUtil::getoptenv("PRELOG");
if (! prelog_name)
// no PRELOG variable set, carry on
return;
- prelogf = new std::ofstream(prelog_name, std::ios_base::app);
+ prelogf = new llofstream(*prelog_name, std::ios_base::app);
if (! (prelogf && prelogf->is_open()))
// can't complain to anybody; how?
return;
@@ -95,13 +96,11 @@ LLDir_Win32::LLDir_Win32()
WCHAR w_str[MAX_PATH];
// Application Data is where user settings go. We rely on $APPDATA being
- // correct; in fact the VMP makes a point of setting it properly, since
- // Windows itself botches the job for non-ASCII usernames (MAINT-8087).
- // Try using wide-character getenv()??
- wchar_t *APPDATA = _wgetenv(L"APPDATA");
+ // correct.
+ auto APPDATA = LLStringUtil::getoptenv("APPDATA");
if (APPDATA)
{
- mOSUserDir = ll_convert_wide_to_string(APPDATA, CP_UTF8);
+ mOSUserDir = *APPDATA;
}
PRELOG("APPDATA='" << mOSUserDir << "'");
// On Windows, we could have received a plain-ASCII pathname in which
@@ -118,7 +117,7 @@ LLDir_Win32::LLDir_Win32()
if (SUCCEEDED(okay) && pwstr)
{
// But of course, only update mOSUserDir if SHGetKnownFolderPath() works.
- mOSUserDir = ll_convert_wide_to_string(pwstr, CP_UTF8);
+ mOSUserDir = ll_convert_wide_to_string(pwstr);
// Not only that: update our environment so that child processes
// will see a reasonable value as well.
_wputenv_s(L"APPDATA", pwstr);
@@ -136,11 +135,10 @@ LLDir_Win32::LLDir_Win32()
//
// We used to store the cache in AppData\Roaming, and the installer
// cleans up that version on upgrade. JC
- // Again, try using wide-character getenv().
- wchar_t *LOCALAPPDATA = _wgetenv(L"LOCALAPPDATA");
+ auto LOCALAPPDATA = LLStringUtil::getoptenv("LOCALAPPDATA");
if (LOCALAPPDATA)
{
- mOSCacheDir = ll_convert_wide_to_string(LOCALAPPDATA, CP_UTF8);
+ mOSCacheDir = *LOCALAPPDATA;
}
PRELOG("LOCALAPPDATA='" << mOSCacheDir << "'");
// Windows really does not deal well with pathnames containing non-ASCII
@@ -155,7 +153,7 @@ LLDir_Win32::LLDir_Win32()
if (SUCCEEDED(okay) && pwstr)
{
// But of course, only update mOSCacheDir if SHGetKnownFolderPath() works.
- mOSCacheDir = ll_convert_wide_to_string(pwstr, CP_UTF8);
+ mOSCacheDir = ll_convert_wide_to_string(pwstr);
// Update our environment so that child processes will see a
// reasonable value as well.
_wputenv_s(L"LOCALAPPDATA", pwstr);