From a91efa1ae8762a4e6efb51ca078cc97b27ca5110 Mon Sep 17 00:00:00 2001 From: skywalker Date: Tue, 5 Nov 2002 16:49:05 +0000 Subject: [PATCH] Added config_root.cpp file for posix. --- builds/posix/make.shared.variables | 2 +- configure.in | 25 ++- src/install/classic/postinstall.sh.in | 198 +++++++++++++----------- src/install/classic/postuninstall.sh.in | 64 ++++++-- src/install/classic/preinstall.sh.in | 69 ++++++--- src/install/classic/preuninstall.sh.in | 15 +- src/jrd/os/posix/config_root.cpp | 154 ++++++++++++++++++ src/make.new/config/config.h.in | 7 +- 8 files changed, 388 insertions(+), 146 deletions(-) create mode 100644 src/jrd/os/posix/config_root.cpp diff --git a/builds/posix/make.shared.variables b/builds/posix/make.shared.variables index 1bf6a55b37..6effa66c4b 100644 --- a/builds/posix/make.shared.variables +++ b/builds/posix/make.shared.variables @@ -232,7 +232,7 @@ FBCOMMON_Objects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(FBCOMMON_So # # Platform Manager -OS_SPECIFIC_Files= path_utils.cpp mod_loader.cpp +OS_SPECIFIC_Files= config_root.cpp path_utils.cpp mod_loader.cpp OS_SPECIFIC_Sources = $(addprefix $(PLATFORM_PATH)/, $(OS_SPECIFIC_Files)) OS_SPECIFIC_Objects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(OS_SPECIFIC_Sources)))) diff --git a/configure.in b/configure.in index 0fb942e4a9..588e38fb50 100644 --- a/configure.in +++ b/configure.in @@ -1,4 +1,4 @@ -dnl $Id: configure.in,v 1.62 2002-11-05 13:15:47 kkuznetsov Exp $ +dnl $Id: configure.in,v 1.63 2002-11-05 16:48:59 skywalker Exp $ dnl ############################# INITIALISATION ############################### @@ -237,6 +237,14 @@ AC_CHECK_TYPE(socklen_t,int) AC_SYS_LARGEFILE AC_CHECK_SIZEOF(void*) +dnl MOD: Check for /proc/self/exe mainly used on linux systems +dnl this is used to determine path to executable file. + +AC_MSG_CHECKING(for file /proc/self/exe) +AC_CHECK_FILES(/proc/self/exe) + + + dnl EKU: try to determine the alignment of long and double dnl replaces ALIGNMENT and DOUBLE_ALIGN in src/jrd/common.h AC_MSG_CHECKING(alignment of long) @@ -462,6 +470,8 @@ mkdir -p gen/libfbembed/common/memory MAKE_SRC_DIR=builds/posix +INSTALL_SRC_DIR=src/install/${FIREBIRD_ARCH_TYPE} + AC_DEFINE_UNQUOTED(ISC_PREFIX,$(if test "x$prefix" = "xNONE" ; then echo \"$ac_default_prefix\"; else echo \"$prefix\"; fi)) AC_OUTPUT( @@ -505,12 +515,13 @@ gen/Makefile.embed.gpre:${MAKE_SRC_DIR}/Makefile.in.embed.gpre src/v5_examples/Makefile:${MAKE_SRC_DIR}/Makefile.in.example5 gen/Makefile.install:${MAKE_SRC_DIR}/Makefile.in.install Makefile:Makefile.in -gen/install/scripts/preinstall.sh:src/install/${FIREBIRD_ARCH_TYPE}/preinstall.sh.in -gen/install/scripts/install.sh:src/install/${FIREBIRD_ARCH_TYPE}/install.sh.in -gen/install/scripts/postinstall.sh:src/install/${FIREBIRD_ARCH_TYPE}/postinstall.sh.in -gen/install/scripts/preuninstall.sh:src/install/${FIREBIRD_ARCH_TYPE}/preuninstall.sh.in -gen/install/scripts/postuninstall.sh:src/install/${FIREBIRD_ARCH_TYPE}/postuninstall.sh.in -gen/install/install.sh:src/install/${FIREBIRD_ARCH_TYPE}/tarInstall.sh.in +gen/install/makeInstallImage.sh:${INSTALL_SRC_DIR}/makeInstallImage.sh.in +gen/install/scripts/preinstall.sh:${INSTALL_SRC_DIR}/preinstall.sh.in +gen/install/scripts/install.sh:${INSTALL_SRC_DIR}/install.sh.in +gen/install/scripts/postinstall.sh:${INSTALL_SRC_DIR}/postinstall.sh.in +gen/install/scripts/preuninstall.sh:${INSTALL_SRC_DIR}/preuninstall.sh.in +gen/install/scripts/postuninstall.sh:${INSTALL_SRC_DIR}/postuninstall.sh.in +gen/install/install.sh:${INSTALL_SRC_DIR}/tarInstall.sh.in src/install/misc/firebird.xinetd dnl SINIX-Z start gen/install/sinixz/Makefile:src/install/arch-specific/sinixz/Makefile.in diff --git a/src/install/classic/postinstall.sh.in b/src/install/classic/postinstall.sh.in index 28d0035f43..54697da1e2 100755 --- a/src/install/classic/postinstall.sh.in +++ b/src/install/classic/postinstall.sh.in @@ -70,7 +70,7 @@ addFirebirdUser() { testStr=`grep firebird /etc/passwd` if [ -z "$testDir" ] then - useradd -o -r -m -d $FBRootDir -s /bin/bash \ + useradd -o -r -m -d $IBRootDir -s /bin/bash \ -c "Firebird Database Administrator" -g firebird -u 84 firebird # >/dev/null 2>&1 @@ -99,8 +99,8 @@ changeXinetdServiceUser() { InitFile=/etc/xinetd.d/firebird if [ -f $InitFile ] then - ed -s $InitFile < $DBAPasswordFile @@ -170,7 +173,7 @@ keepOrigDBAPassword() { echo "daemon init routine in the file /etc/init.d/firebird)" >> $DBAPasswordFile echo "" >> $DBAPasswordFile echo "Your should password can be changed to a more suitable one using the" >> $DBAPasswordFile - echo "@prefix@/bin/changeDBAPassword.sh script" >> $DBAPasswordFile + echo "/opt/interbase/bin/changeDBAPassword.sh script" >> $DBAPasswordFile echo "" >> $DBAPasswordFile chmod u=r,go= $DBAPasswordFile @@ -186,9 +189,14 @@ keepOrigDBAPassword() { generateNewDBAPassword() { - DBAPasswordFile=$FBRootDir/SYSDBA.password + DBAPasswordFile=$IBRootDir/SYSDBA.password NewPasswd=`/usr/bin/mkpasswd -l 8` + if [ -z "$NewPasswd" ] + then + keepOrigDBAPassword + return + fi echo "Firebird generated password " > $DBAPasswordFile echo "for user SYSDBA is : $NewPasswd" >> $DBAPasswordFile @@ -197,11 +205,11 @@ generateNewDBAPassword() { echo "daemon init routine in the file /etc/rc.d/init.d/firebird)" >> $DBAPasswordFile echo "" >> $DBAPasswordFile echo "Your password can be changed to a more suitable one using the" >> $DBAPasswordFile - echo "@prefix@/bin/changeDBAPassword.sh script" >> $DBAPasswordFile + echo "/opt/interbase/bin/changeDBAPassword.sh script" >> $DBAPasswordFile echo "" >> $DBAPasswordFile chmod u=r,go= $DBAPasswordFile - $FBBin/gsec -user sysdba -password masterkey < $DBAPasswordFile # chmod ga-rwx $DBAPasswordFile @@ -228,7 +236,7 @@ askUserForNewDBAPassword() { NewPasswd=$Answer if [ ! -z "$NewPasswd" ] then - $FBBin/gsec -user sysdba -password masterkey < + * + * Contributor(s): + * + * + * $Id: config_root.cpp,v 1.1 2002-11-05 16:49:05 skywalker Exp $ + */ + +#include "firebird.h" + +#ifdef HAVE_UNISTD_H +#include +#endif + +#include "fb_types.h" +#include "fb_string.h" + +#include "../jrd/os/config_root.h" +#include "../jrd/os/path_utils.h" + +typedef Firebird::string string; + +const string CONFIG_FILE = "firebird.conf"; + +/****************************************************************************** + * + * Platform-specific root locator + */ + +#ifdef HAVE__PROC_SELF_EXE +static string getExePathViaProcEntry() +{ + char buffer[MAXPATHLEN]; + int len = readlink("/proc/self/exe", buffer, sizeof(buffer)); + buffer[len]=0; + + string pathName = buffer; + + return pathName; +} + +#endif + +/****************************************************************************** + * + * + */ + +static string getRootPathFromExePath() +{ + // get the pathname of the running executable + string bin_dir; + + +#ifdef HAVE__PROC_SELF_EXE + bin_dir = getExePathViaProcEntry(); +#endif + + // 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? + // ??? + + // 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; +} + +static string getRootPathFromEnvVar() +{ + const char* varPtr = getenv("FIREBIRD"); + + string rootpath; + + if (varPtr == NULL) { + rootpath = varPtr; + } + + return rootpath; +} + + +static string getRootPathFromInstallDir() +{ + + // Need to speak to Erik about this one, as the variable + // needs to come from the autoconf file. + + string rootpath; + + return rootpath; +} + +ConfigRoot::ConfigRoot() +{ + + // Try getting the root path from the executable + root_dir = getRootPathFromExePath(); + if (root_dir.length() != 0) { + return; + } + + + // Try getting the root path from environment variable + root_dir = getRootPathFromEnvVar(); + if (root_dir.length() != 0) { + return; + } + + // As a last resort get it from the default install directory + root_dir = ISC_PREFIX; +} + +string ConfigRoot::getRootDirectory() const +{ + return root_dir; +} + +string ConfigRoot::getConfigFile() const +{ + return "/etc/" + CONFIG_FILE; +} diff --git a/src/make.new/config/config.h.in b/src/make.new/config/config.h.in index 9bc7fc8edf..06ab99d9ae 100644 --- a/src/make.new/config/config.h.in +++ b/src/make.new/config/config.h.in @@ -1,4 +1,4 @@ -#ident "$Id: config.h.in,v 1.44 2002-11-05 13:48:42 kkuznetsov Exp $" +#ident "$Id: config.h.in,v 1.45 2002-11-05 16:49:05 skywalker Exp $" /* * 2002.02.15 Sean Leyne - Code Cleanup, removed obsolete ports: @@ -74,6 +74,7 @@ #undef HAVE_GETPAGESIZE #undef HAVE_XDR_HYPER + /* Types */ #undef socklen_t @@ -108,6 +109,10 @@ /* Support databases on Raw Devices (UNIX only) */ #undef SUPPORT_RAW_DEVICES +/* Support /etc/proc/exe as link to current executable + * enables us to find path to install directory (Linux only) */ +#undef HAVE__PROC_SELF_EXE + /* CPU types */ #undef PowerPC #undef sparc