From ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e Mon Sep 17 00:00:00 2001
From: Jacek Antonelli
Date: Thu, 30 Apr 2009 13:04:20 -0500
Subject: Second Life viewer sources 1.23.0-RC

---
 linden/indra/llvfs/lldir_solaris.cpp | 56 +++++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 14 deletions(-)

(limited to 'linden/indra/llvfs/lldir_solaris.cpp')

diff --git a/linden/indra/llvfs/lldir_solaris.cpp b/linden/indra/llvfs/lldir_solaris.cpp
index adbe747..9553d92 100644
--- a/linden/indra/llvfs/lldir_solaris.cpp
+++ b/linden/indra/llvfs/lldir_solaris.cpp
@@ -17,7 +17,8 @@
  * There are special exceptions to the terms and conditions of the GPL as
  * it is applied to this Source Code. View the full text of the exception
  * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  * 
  * By copying, modifying or distributing this software, you acknowledge
  * that you have read and understood your obligations described above,
@@ -36,14 +37,13 @@
 #include "llrand.h"
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/param.h>
 #include <unistd.h>
 #include <glob.h>
 #include <pwd.h>
 #include <sys/utsname.h>
 #define _STRUCTURED_PROC 1
 #include <sys/procfs.h>
+#include <fcntl.h>
 
 static std::string getCurrentUserHome(char* fallback)
 {
@@ -82,7 +82,16 @@ LLDir_Solaris::LLDir_Solaris()
 	mDirp = NULL;
 
 	char tmp_str[LL_MAX_PATH];	/* Flawfinder: ignore */ 
-	getcwd(tmp_str, LL_MAX_PATH);
+	if (getcwd(tmp_str, LL_MAX_PATH) == NULL)
+	{
+		strcpy(tmp_str, "/tmp");
+		llwarns << "Could not get current directory; changing to "
+				<< tmp_str << llendl;
+		if (chdir(tmp_str) == -1)
+		{
+			llerrs << "Could not change directory to " << tmp_str << llendl;
+		}
+	}
 
 	mExecutableFilename = "";
 	mExecutablePathAndName = "";
@@ -121,20 +130,35 @@ LLDir_Solaris::LLDir_Solaris()
 		return;
 	}
 
+	char *p = execpath;			// nuke trash in link, if any exists
+	int i = 0;
+	while(*p != NULL && ++i < LL_MAX_PATH && isprint((int)(*p++)));
+	*p = NULL;
+
 	mExecutablePathAndName = strdup(execpath);
 	llinfos << "mExecutablePathAndName = [" << mExecutablePathAndName << "]" << llendl;
 
+	//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);
+	}else{
 			// plunk a null at last '/' to get exec dir
-	char *s = execpath + strlen(execpath) -1;
-	while(*s != '/' && s != execpath){
-		--s;
-	}
+		char *s = execpath + strlen(execpath) -1;
+		while(*s != '/' && s != execpath){
+			--s;
+		}
 	
-	if(s != execpath){
-		*s = (char)NULL;
+		if(s != execpath){
+			*s = (char)NULL;
 	
-		mExecutableDir = strdup(execpath);
-		llinfos << "mExecutableDir = [" << mExecutableDir << "]" << llendl;
+			mExecutableDir = strdup(execpath);
+			llinfos << "mExecutableDir = [" << mExecutableDir << "]" << llendl;
+		}
 	}
 	
 	// *TODO: don't use /tmp, use $HOME/.secondlife/tmp or something.
@@ -354,12 +378,16 @@ void LLDir_Solaris::getRandomFileInDir(const std::string &dirname, const std::st
 std::string LLDir_Solaris::getCurPath()
 {
 	char tmp_str[LL_MAX_PATH];	/* Flawfinder: ignore */ 
-	getcwd(tmp_str, LL_MAX_PATH);
+	if (getcwd(tmp_str, LL_MAX_PATH) == NULL)
+	{
+		llwarns << "Could not get current directory" << llendl;
+		tmp_str[0] = '\0';
+	}
 	return tmp_str;
 }
 
 
-BOOL LLDir_Solaris::fileExists(const std::string &filename)
+BOOL LLDir_Solaris::fileExists(const std::string &filename) const
 {
 	struct stat stat_data;
 	// Check the age of the file
-- 
cgit v1.1