Ejemplo n.º 1
0
/**
 * @brief copy a given file to the current user home
 * @param path The file path
 * @return The resulting file path
 */
std::string
vishnu::copyFileToUserHome(const std::string& path)
{
  std::string result;
  try {
    bfs::path from(path);
    bfs::path to(boost::str(boost::format("%1%/%2%") % getCurrentUserHome() % bfs::basename(from)));
    bfs::copy_file(from, to, bfs::copy_option::overwrite_if_exists);
    result = to.native();
  } catch (const boost::filesystem::filesystem_error ex) {
    throw TMSVishnuException(ERRCODE_SYSTEM, ex.what());
  }

  return result;
}
Ejemplo n.º 2
0
LLDir_Solaris::LLDir_Solaris()
{
	mDirDelimiter = "/";
	mCurrentDirIndex = -1;
	mCurrentDirCount = -1;
	mDirp = NULL;

	char tmp_str[LL_MAX_PATH];	/* Flawfinder: ignore */ 
	getcwd(tmp_str, LL_MAX_PATH);

	mExecutableFilename = "";
	mExecutablePathAndName = "";
	mExecutableDir = strdup(tmp_str);
	mWorkingDir = strdup(tmp_str);
	mAppRODataDir = strdup(tmp_str);
	mOSUserDir = getCurrentUserHome(tmp_str);
	mOSUserAppDir = "";
	mLindenUserDir = tmp_str;

	char path [LL_MAX_PATH];	/* Flawfinder: ignore */ 

	sprintf(path, "/proc/%d/psinfo", (int)getpid());
	int proc_fd = -1;
	if((proc_fd = open(path, O_RDONLY)) == -1){
		llwarns << "unable to open " << path << llendl;
		return;
	}
	psinfo_t proc_psinfo;
	if(read(proc_fd, &proc_psinfo, sizeof(psinfo_t)) != sizeof(psinfo_t)){
		llwarns << "Unable to read " << path << llendl;
		close(proc_fd);
		return;
	}

	close(proc_fd);

	mExecutableFilename = strdup(proc_psinfo.pr_fname);
	llinfos << "mExecutableFilename = [" << mExecutableFilename << "]" << llendl;

	sprintf(path, "/proc/%d/path/a.out", (int)getpid());

	char execpath[LL_MAX_PATH];
	if(readlink(path, execpath, LL_MAX_PATH) == -1){
		llwarns << "Unable to read link from " << path << llendl;
		return;
	}

	mExecutablePathAndName = strdup(execpath);
	llinfos << "mExecutablePathAndName = [" << mExecutablePathAndName << "]" << llendl;

			// 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);
		llinfos << "mExecutableDir = [" << mExecutableDir << "]" << llendl;
	}
	
	// *TODO: don't use /tmp, use $HOME/.secondlife/tmp or something.
	mTempDir = "/tmp";
}
Ejemplo n.º 3
0
LLDir_Solaris::LLDir_Solaris()
{
	mDirDelimiter = "/";
	mCurrentDirIndex = -1;
	mCurrentDirCount = -1;
	mDirp = NULL;

	char tmp_str[LL_MAX_PATH];	/* Flawfinder: ignore */ 
	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 = "";
	mExecutableDir = strdup(tmp_str);
	mWorkingDir = strdup(tmp_str);
	mAppRODataDir = strdup(tmp_str);
	mOSUserDir = getCurrentUserHome(tmp_str);
	mOSUserAppDir = "";
	mLindenUserDir = tmp_str;

	char path [LL_MAX_PATH];	/* Flawfinder: ignore */ 

	sprintf(path, "/proc/%d/psinfo", (int)getpid());
	int proc_fd = -1;
	if((proc_fd = open(path, O_RDONLY)) == -1){
		llwarns << "unable to open " << path << llendl;
		return;
	}
	psinfo_t proc_psinfo;
	if(read(proc_fd, &proc_psinfo, sizeof(psinfo_t)) != sizeof(psinfo_t)){
		llwarns << "Unable to read " << path << llendl;
		close(proc_fd);
		return;
	}

	close(proc_fd);

	mExecutableFilename = strdup(proc_psinfo.pr_fname);
	llinfos << "mExecutableFilename = [" << mExecutableFilename << "]" << llendl;

	sprintf(path, "/proc/%d/path/a.out", (int)getpid());

	char execpath[LL_MAX_PATH];
	if(readlink(path, execpath, LL_MAX_PATH) == -1){
		llwarns << "Unable to read link from " << path << llendl;
		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;
		}
	
		if(s != execpath){
			*s = (char)NULL;
	
			mExecutableDir = strdup(execpath);
			llinfos << "mExecutableDir = [" << mExecutableDir << "]" << llendl;
		}
	}
	
	mLLPluginDir = mExecutableDir + mDirDelimiter + "llplugin";

	// *TODO: don't use /tmp, use $HOME/.secondlife/tmp or something.
	mTempDir = "/tmp";
}
Ejemplo n.º 4
0
LLDir_Linux::LLDir_Linux()
{
	mDirDelimiter = "/";
	mCurrentDirIndex = -1;
	mCurrentDirCount = -1;
	mDirp = NULL;

	char tmp_str[LL_MAX_PATH];	/* Flawfinder: ignore */ 
	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 = "";
	mExecutableDir = tmp_str;
	mWorkingDir = tmp_str;
	mOSUserDir = getCurrentUserHome(tmp_str);
	mOSUserAppDir = "";
	mLindenUserDir = tmp_str;

	char path [32];	/* Flawfinder: ignore */ 

	// *NOTE: /proc/%d/exe doesn't work on FreeBSD. But that's ok,
	// because this is the linux implementation.

	snprintf (path, sizeof(path), "/proc/%d/exe", (int) getpid ()); 
	int rc = readlink (path, tmp_str, sizeof (tmp_str)-1);	/* Flawfinder: ignore */ 
	if ( (rc != -1) && (rc <= ((int) sizeof (tmp_str)-1)) )
	{
		tmp_str[rc] = '\0'; //readlink() doesn't 0-terminate the buffer
		mExecutablePathAndName = tmp_str;
		char *path_end;
		if ((path_end = strrchr(tmp_str,'/')))
		{
			*path_end = '\0';
			mExecutableDir = tmp_str;
			mWorkingDir = tmp_str;
			mExecutableFilename = path_end+1;
		}
		else
		{
			mExecutableFilename = tmp_str;
		}
	}

    // We should be taking all of our stuff out of the share area
    //
	// Try as if app_settings lives at our level
	//
	mAppRODataDir = mExecutableDir;
	//
	if( !fileExists( mAppRODataDir + "/app_settings/message_template.msg" ) )
	{
		// Try as if we are running from the tarball
		//
		mAppRODataDir = mExecutableDir + "/../share/slitechat";
		//
		if( !fileExists( mAppRODataDir + "/app_settings/message_template.msg" ) )
		{
			// Try as if we are running from the Debian package
			//
			mAppRODataDir = "/usr/share/slitechat";
		}
	}

	// *TODO: don't use /tmp, use $HOME/.secondlife/tmp or something.
	mTempDir = "/tmp";
}
Ejemplo n.º 5
0
LLDir_Linux::LLDir_Linux()
{
	mDirDelimiter = "/";
	mCurrentDirIndex = -1;
	mCurrentDirCount = -1;
	mDirp = NULL;

	char tmp_str[LL_MAX_PATH];	/* Flawfinder: ignore */ 
	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 = "";
	mExecutableDir = tmp_str;
	mWorkingDir = tmp_str;
#ifdef APP_RO_DATA_DIR
	mAppRODataDir = APP_RO_DATA_DIR;
	mSkinBaseDir = mAppRODataDir + mDirDelimiter + "skins";
#else
	mAppRODataDir = tmp_str;

        U32 indra_pos = mExecutableDir.find("/indra");
        if (indra_pos != std::string::npos)
        {
		// ...we're in a dev checkout
		mSkinBaseDir = mExecutableDir.substr(0, indra_pos) + "/indra/newview/skins";
		llinfos << "Running in dev checkout with mSkinBaseDir "
		 << mSkinBaseDir << llendl;
        }
        else
        {
		// ...normal installation running
		mSkinBaseDir = mAppRODataDir + mDirDelimiter + "skins";
        }
#endif

	mOSUserDir = getCurrentUserHome(tmp_str);
	mOSUserAppDir = "";
	mLindenUserDir = "";

	char path [32];	/* Flawfinder: ignore */ 

	// *NOTE: /proc/%d/exe doesn't work on FreeBSD. But that's ok,
	// because this is the linux implementation.

	snprintf (path, sizeof(path), "/proc/%d/exe", (int) getpid ()); 
	int rc = readlink (path, tmp_str, sizeof (tmp_str)-1);	/* Flawfinder: ignore */ 
	if ( (rc != -1) && (rc <= ((int) sizeof (tmp_str)-1)) )
	{
		tmp_str[rc] = '\0'; //readlink() doesn't 0-terminate the buffer
		mExecutablePathAndName = tmp_str;
		char *path_end;
		if ((path_end = strrchr(tmp_str,'/')))
		{
			*path_end = '\0';
			mExecutableDir = tmp_str;
			mWorkingDir = tmp_str;
			mExecutableFilename = path_end+1;
		}
		else
		{
			mExecutableFilename = tmp_str;
		}
	}

	mLLPluginDir = mExecutableDir + mDirDelimiter + "llplugin";

	// *TODO: don't use /tmp, use $HOME/.secondlife/tmp or something.
	mTempDir = "/tmp";
}
Ejemplo n.º 6
0
LLDir_Linux::LLDir_Linux()
{
    mDirDelimiter = "/";
    mCurrentDirIndex = -1;
    mCurrentDirCount = -1;
    mDirp = NULL;

    char tmp_str[LL_MAX_PATH];	/* Flawfinder: ignore */
    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 = "";
    mExecutableDir = tmp_str;
    mWorkingDir = tmp_str;
    mAppRODataDir = tmp_str;
    mOSUserDir = getCurrentUserHome(tmp_str);
    mOSUserAppDir = "";
    mLindenUserDir = tmp_str;

    char path [32];	/* Flawfinder: ignore */

    // *NOTE: /proc/%d/exe doesn't work on FreeBSD. But that's ok,
    // because this is the linux implementation.

    snprintf (path, sizeof(path), "/proc/%d/exe", (int) getpid ());
    int rc = readlink (path, tmp_str, sizeof (tmp_str)-1);	/* Flawfinder: ignore */
    if ( (rc != -1) && (rc <= ((int) sizeof (tmp_str)-1)) )
    {
        tmp_str[rc] = '\0'; //readlink() doesn't 0-terminate the buffer
        mExecutablePathAndName = tmp_str;
        char *path_end;
        if ((path_end = strrchr(tmp_str,'/')))
        {
            *path_end = '\0';
            mExecutableDir = tmp_str;
            mWorkingDir = tmp_str;
            mExecutableFilename = path_end+1;
        }
        else
        {
            mExecutableFilename = tmp_str;
        }
    }

    mLLPluginDir = mExecutableDir + mDirDelimiter + "llplugin";

#ifdef APP_RO_DATA_DIR
    const char* appRODataDir = APP_RO_DATA_DIR;
    if(appRODataDir[0] == '/')
    {
        // We have a full path to the data directory.
        mAppRODataDir = appRODataDir;
    }
    else if(appRODataDir[0] != '\0')
    {
        // We have a relative path to the data directory.  Search
        // for it in each potential install prefix containing the
        // executable.
        for(std::string prefix = getDirName(mExecutableDir);
                !prefix.empty(); prefix = getDirName(prefix))
        {
            std::string dir = prefix + "/" + appRODataDir;
            if(fileExists(dir + "/app_settings"))
            {
                mAppRODataDir = dir;
                break;
            }
        }
    }
#endif

    // *TODO: don't use /tmp, use $HOME/.secondlife/tmp or something.
    mTempDir = "/tmp";
}