2002-11-05 17:49:05 +01:00
|
|
|
/*
|
|
|
|
* PROGRAM: Client/Server Common Code
|
|
|
|
* MODULE: config_root.cpp
|
|
|
|
* DESCRIPTION: Configuration manager (platform specific - linux/posix)
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
* You may obtain a copy of the Licence at
|
|
|
|
* http://www.gnu.org/licences/lgpl.html
|
|
|
|
*
|
|
|
|
* As a special exception this file can also be included in modules
|
|
|
|
* with other source code as long as that source code has been
|
|
|
|
* released under an Open Source Initiative certificed licence.
|
|
|
|
* More information about OSI certification can be found at:
|
|
|
|
* http://www.opensource.org
|
|
|
|
*
|
|
|
|
* This module is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public Licence for more details.
|
|
|
|
*
|
|
|
|
* This module was created by members of the firebird development
|
|
|
|
* team. All individual contributions remain the Copyright (C) of
|
|
|
|
* those individuals and all rights are reserved. Contributors to
|
|
|
|
* this file are either listed below or can be obtained from a CVS
|
|
|
|
* history command.
|
|
|
|
*
|
|
|
|
* Created by: Mark O'Donohue <skywalker@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2003-05-25 02:24:23 +02:00
|
|
|
* 25 May 2003 - Nickolay Samofatov: Fix several bugs that prevented
|
|
|
|
* 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"
|
2004-12-17 06:41:47 +01:00
|
|
|
#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"
|
|
|
|
|
2004-02-08 19:47:47 +01:00
|
|
|
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];
|
2004-06-05 11:37:18 +02:00
|
|
|
const int len = readlink("/proc/self/exe", buffer, sizeof(buffer));
|
2003-05-25 02:12:34 +02:00
|
|
|
if (len >= 0) {
|
2004-06-05 11:37:18 +02:00
|
|
|
buffer[len] = 0;
|
2003-05-25 02:12:34 +02:00
|
|
|
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()
|
|
|
|
{
|
2003-05-25 02:12:34 +02:00
|
|
|
#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();
|
2003-05-25 02:12:34 +02:00
|
|
|
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?
|
|
|
|
// ???
|
2003-05-25 02:12:34 +02:00
|
|
|
#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;
|
2003-05-25 02:12:34 +02:00
|
|
|
#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
|
|
|
{
|
2003-05-25 02:12:34 +02: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;
|
|
|
|
}
|
2003-05-25 02:12:34 +02:00
|
|
|
#endif
|
2002-11-05 17:49:05 +01:00
|
|
|
|
|
|
|
// As a last resort get it from the default install directory
|
2003-05-25 02:12:34 +02:00
|
|
|
root_dir = string(FB_PREFIX) + PathUtils::dir_sep;
|
2002-11-05 17:49:05 +01:00
|
|
|
}
|
2004-06-05 11:37:18 +02:00
|
|
|
|