8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-31 21:23:02 +01:00
firebird-mirror/src/jrd/os/posix/config_root.cpp

110 lines
2.8 KiB
C++
Raw Normal View History

2002-11-05 17:49:05 +01:00
/*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
2002-11-05 17:49:05 +01:00
*
* Software distributed under the License is distributed AS IS,
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights
* and limitations under the License.
*
* The Original Code was created by Mark O'Donohue
* for the Firebird Open Source RDBMS project.
2002-11-05 17:49:05 +01:00
*
* Copyright (c) 2002 Mark O'Donohue <skywalker@users.sourceforge.net>
* and all contributors signed below.
2002-11-05 17:49:05 +01:00
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
* 25 May 2003 - Nickolay Samofatov: Fix several bugs that prevented
2003-05-25 02:24:23 +02:00
* compatibility with Kylix
2002-11-05 17:49:05 +01:00
*
*/
#include "firebird.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "fb_types.h"
#include "../common/classes/fb_string.h"
2002-11-05 17:49:05 +01:00
#include "../jrd/os/config_root.h"
#include "../jrd/os/path_utils.h"
typedef Firebird::PathName string;
2002-11-05 17:49:05 +01:00
/******************************************************************************
*
* Platform-specific root locator
*/
2003-08-10 00:52:35 +02:00
#if defined SUPERSERVER || defined EMBEDDED
2002-11-05 17:49:05 +01:00
#ifdef HAVE__PROC_SELF_EXE
static string getExePathViaProcEntry()
{
char buffer[MAXPATHLEN];
const int len = readlink("/proc/self/exe", buffer, sizeof(buffer));
if (len >= 0) {
buffer[len] = 0;
return buffer;
}
return "";
2002-11-05 17:49:05 +01:00
}
2003-08-10 00:52:35 +02:00
#endif
2002-11-05 17:49:05 +01:00
#endif
/******************************************************************************
*
*
*/
2003-08-10 00:35:11 +02:00
#if defined SUPERSERVER || defined EMBEDDED
2002-11-05 17:49:05 +01:00
static string getRootPathFromExePath()
{
#ifdef HAVE__PROC_SELF_EXE
2002-11-05 17:49:05 +01:00
// get the pathname of the running executable
2004-12-06 11:17:00 +01:00
string bin_dir = getExePathViaProcEntry();
if (bin_dir.length() == 0)
return "";
2002-11-05 17:49:05 +01:00
// get rid of the filename
int index = bin_dir.rfind(PathUtils::dir_sep);
bin_dir = bin_dir.substr(0, index);
// how should we decide to use bin_dir instead of root_dir? any ideas?
// ???
#ifdef EMBEDDED
// Placed here in case we introduce embedded POSIX build
root_dir = bin_dir + PathUtils::dir_sep;
return;
#endif
2002-11-05 17:49:05 +01:00
// go to the parent directory
index = bin_dir.rfind(PathUtils::dir_sep, bin_dir.length());
string root_dir = (index ? bin_dir.substr(0, index) : bin_dir) + PathUtils::dir_sep;
return root_dir;
#else
return "";
#endif
2002-11-05 17:49:05 +01:00
}
2003-08-10 00:35:11 +02:00
#endif
2002-11-05 17:49:05 +01:00
2004-02-29 06:49:03 +01:00
void ConfigRoot::osConfigRoot()
2002-11-05 17:49:05 +01:00
{
#if defined SUPERSERVER || defined EMBEDDED
2002-11-05 17:49:05 +01:00
// Try getting the root path from the executable
root_dir = getRootPathFromExePath();
if (root_dir.length() != 0) {
return;
}
#endif
2002-11-05 17:49:05 +01:00
// As a last resort get it from the default install directory
root_dir = string(FB_PREFIX) + PathUtils::dir_sep;
2002-11-05 17:49:05 +01:00
}