From d1a0e95271bd49f76107f62820246ae05d0af9df Mon Sep 17 00:00:00 2001 From: paulbeach Date: Fri, 7 Dec 2007 12:19:37 +0000 Subject: [PATCH] MacOS 10.5 (Leopard) updates --- builds/install/arch-specific/darwin/FB.info | 4 +- .../arch-specific/darwin/install-script | 146 ++++++++++++------ .../darwin/launchd.org.firebird.gds.plist | 37 +++++ .../arch-specific/darwin/preupgrade-script | 4 + builds/posix/make.rules | 4 + builds/posix/postfix.darwin | 13 +- builds/posix/prefix.darwin | 14 +- configure.in | 14 ++ src/common/classes/semaphore.h | 53 +++++-- 9 files changed, 218 insertions(+), 71 deletions(-) create mode 100644 builds/install/arch-specific/darwin/launchd.org.firebird.gds.plist diff --git a/builds/install/arch-specific/darwin/FB.info b/builds/install/arch-specific/darwin/FB.info index 6d5b420f40..aa93051b9f 100644 --- a/builds/install/arch-specific/darwin/FB.info +++ b/builds/install/arch-specific/darwin/FB.info @@ -1,6 +1,6 @@ Title Firebird Database -Version 2.1.0 -Description Firebird 2.1.0 +Version 2.0.3 +Description Firebird 2.0.3 DefaultLocation /tmp/install DeleteWarning diff --git a/builds/install/arch-specific/darwin/install-script b/builds/install/arch-specific/darwin/install-script index cc6559fc7b..874e5226bb 100644 --- a/builds/install/arch-specific/darwin/install-script +++ b/builds/install/arch-specific/darwin/install-script @@ -1,6 +1,6 @@ #!/bin/sh # -# $Id: install-script,v 1.3 2007-06-11 14:21:13 paulbeach Exp $ +# $Id: install-script,v 1.4 2007-12-07 12:19:11 paulbeach Exp $ # # Script args: # $0: full path to script @@ -9,6 +9,17 @@ # $3: ????? Path to install Volume???? # $4: ????? +# MacOS Notes +# 10.0 Cheetah +# 10.01 Puma +# 10.2 Jaguar +# 10.3 Panther (xinetd) +# 10.4 Tiger - Uses Launchd (xinetd for backward compatibility) +# 10.5 Leopard - Uses Lanchd (No xinetd) (no ni* commands) + +OSVERSION=`sw_vers -productVersion | awk -F '.' '{print $2}'` +echo $OSVERSION + FB_FW="/Library/Frameworks/Firebird.framework" FB_RES="$FB_FW/Versions/A/Resources" INST_RES="$FB_RES/installer_files" @@ -25,11 +36,9 @@ if test `uname -r | sed -e 's/\.[0-9]*//g'` -lt 6; then fi fi -# Setup our services entry, our user account, and our group -# -# -# Start with the service entry -echo "Start with the service entry" +if test $OSVERSION -lt 5; then +# Setup our services entry +echo "Setup the service entry pre 10.5" if niutil -list . /services/gds_db 2&>1 /dev/null ; then echo -n else @@ -37,10 +46,17 @@ else niutil -createprop . /services/gds_db port 3050 niutil -createprop . /services/gds_db protocol tcp tcp fi +fi +# No niutil on 10.5 +# Setup our services entry +echo "Setup the service entry 10.5+" + +if test $OSVERSION -lt 5; then +# niutil works pre 10.5 # Now for the group. If the firebird group already exists, remember the -# id if we need it to create the firebird user -echo "Create the Firebird group" +# id if we need it to create the firebird user +echo "Create the Firebird group pre 10.5" if niutil -list . /groups/firebird 2&>1 /dev/null; then NEW_GID=`niutil -readprop . /groups/firebird gid` else @@ -50,9 +66,31 @@ else niutil -createprop . /groups/firebird gid $NEW_GID niutil -createprop . /groups/firebird users firebird fi +fi +# No niutil on 10.5 +# Now create the firebird group +if dscl localhost -read /Local/Default/Groups/firebird 2&>1 /dev/null; then + echo "Group Found" +else +gid=501 +dscl localhost -search /Local/Default/Groups PrimaryGroupID $gid | grep $gid +while [ "$?" = "0" ]; do + echo $gid + let "gid =$gid+1" + dscl localhost -search /Local/Default/Groups PrimaryGroupID $gid | grep $gid +done +echo "Create the Firebird group 10.5+" + dscl localhost -create /Local/Default/Groups/firebird + dscl localhost -create /Local/Default/Groups/firebird Password "*" + dscl localhost -create /Local/Default/Groups/firebird PrimaryGroupID $gid + dscl localhost -create /Local/Default/Groups/firebird RecordName firebird +fi + +if test $OSVERSION -lt 5; then +# niutil works pre 10.5 # Now create the firebird user -echo "Create the Firebird user" +echo "Create the Firebird user pre 10.5" if niutil -list . /users/firebird 2&>1 /dev/null; then echo -n else @@ -65,7 +103,39 @@ else niutil -createprop . /users/firebird shell /bin/tcsh niutil -createprop . /users/firebird change 0 niutil -createprop . /users/firebird gid $NEW_GID - niutil -createprop . /users/firebird realname "Firebird SQL Database" + niutil -createprop . /users/firebird realname "Firebird Database" +fi +fi + +# no niutil on 10.5 use dscl +# Now create the firebird user +if dscl localhost -read /Local/Default/Users/firebird 2&>1 /dev/null; then + echo "User Found" +else +ugid=501 +dscl localhost -search /Local/Default/Users UniqueID $ugid | grep $ugid +while [ "$?" = "0" ]; do + echo $ugid + let "ugid=$ugid+1" + dscl localhost -search /Local/Default/Users UniqueID $ugid | grep $ugid +done +echo "create the firebird user 10.5+" + dscl localhost -create /Local/Default/Users/firebird + echo "create user" + dscl localhost -create /Local/Default/Users/firebird NFSHomeDirectory /Library/Frameworks/firebird.framework + echo "create path" + dscl localhost -create /Local/Default/Users/firebird Password "*" + echo "create password" + dscl localhost -create /Local/Default/Users/firebird UserShell /bin/tcsh + echo "create shell" + dscl localhost -create /Local/Default/Users/firebird RecordName firebird + echo "create recordname" + dscl localhost -create /Local/Default/Users/firebird PrimaryGroupID $gid + echo "create primarygroupid" + dscl localhost -create /Local/Default/Users/firebird UniqueID $ugid + echo "create uniqueid" + dscl localhost -create /Local/Default/Users/firebird RealName "Firebird Database" + echo "create realname" fi # Shutdown any existing servers @@ -76,8 +146,7 @@ fi # Install the framework echo "Install the framework" -chown -R firebird "$FB_FW" -chgrp -R firebird "$FB_FW" +chown -R firebird:firebird "$FB_FW" # set the permissions correctly echo "Set the permissions correctly" @@ -93,10 +162,6 @@ else chmod a+s "$FB_FW/Resources/bin/gds_drop" chmod a+s "$FB_FW/Resources/bin/fb_lock_mgr" chmod a+s "$FB_FW/Resources/bin/fb_inet_server" - - chown root "$FB_FW/Resources/bin/gds_drop" - chown root "$FB_FW/Resources/bin/fb_lock_mgr" - chown root "$FB_FW/Resources/bin/fb_inet_server" fi # Install the startup item @@ -110,26 +175,6 @@ else rm -rf /Library/StartupItems/Firebird fi -# -# Add gds_db to the services file, if available -# -echo "Add gds_db to the services file" -HUPNEEDED='n' # Relevant to Classic only -if [ -f /etc/services ]; then - grep -s gds_db /etc/services > /dev/null 2>&1 - if test $? != 0 ; then - HUPNEEDED='y' - cat /etc/services > /etc/.interbase.temp.install.services - echo "gds_db 3050/tcp # Firebird Database Protocol" >> /etc/.interbase.temp.install.services - cp /etc/services /etc/services.fbsave - mv /etc/.interbase.temp.install.services /etc/services - fi -fi - -if [ -f /etc/inetd.conf ]; then - cp /etc/inetd.conf /etc/inetd.conf.fbsave -fi - # Remove all traces of Classic first echo "Remove all traces of Classic first" if [ -f /etc/inetd.conf ]; then @@ -146,15 +191,23 @@ if [ -f /etc/xinetd.d/firebird ]; then HUPNEEDED='y' fi +if [ -f /Library/LaunchDemons/org.firebird.gds.plist ]; then + launchctl unload /Library/LaunchDaemons/org.firebird.gds.plist + rm /Library/LaunchDaemons/org.firebird.gds.plist + HUPNEEDED='y' +fi + # Install ourselves in the correct place - SuperServer -echo "Install ourselves in the correct place" +echo "Install ourselves in the correct place SuperServer" if [ -f "$FB_FW/Versions/A/Resources/.SuperServer" ]; then cp -r $1/Contents/Resources/StartupItem /Library/StartupItems/Firebird fi # Install ourselves in the correct place - Classic -# inetd.d - older versions of MacOS +echo "Install ourselves in the correct place Classic" +# inetd.d - older versions of MacOS +echo "Test inetd" if [ -f //var/run/inted.pid -a -d /etc/inetd.d ]; then if [ -f /etc/inetd.conf ]; then echo "gds_db stream tcp nowait root $FB_FW/Resources/bin/fb_inet_server fb_inet_server" > /etc/.fb.inetd.conf.entry @@ -165,10 +218,12 @@ if [ -f //var/run/inted.pid -a -d /etc/inetd.d ]; then fi fi -# xinetd.d - Classic default +# xinetd.d - Pre MacOS 10.5 (Leopard) +echo "Test xinetd.d" if [ -f "$FB_FW/Versions/A/Resources/.SuperServer" ]; then echo -n else +if [ -f /etc/xinet.d ]; then cat > /etc/xinetd.d/firebird < + + + +Disabled + +Label +org.firebird.gds +ProgramArguments + +/Library/Frameworks/Firebird.framework/resources/bin/fb_inet_server + +InetdCompatibility + +Wait + + +InitGroups + +Sockets + +Listeners + +SockServiceName +gds_db +SockType +stream +SockFamily +IPv4 + + +OnDemand + +UserName +firebird + + diff --git a/builds/install/arch-specific/darwin/preupgrade-script b/builds/install/arch-specific/darwin/preupgrade-script index 4cf10dbd25..9ed28d8513 100644 --- a/builds/install/arch-specific/darwin/preupgrade-script +++ b/builds/install/arch-specific/darwin/preupgrade-script @@ -25,6 +25,10 @@ if [ -f /Library/StartupItems/Firebird/Firebird ]; then /Library/StartupItems/Firebird/Firebird stop fi +if [ -f /Library/LaunchDaemons/org.firebird.gds.plist ]; then + launchctl unload /Library/LaunchDaemons/org.firebird/gds.plist +fi rm -rf "$FB_FW/Firebird.framework" rm -rf /Library/StartupItems/Firebird +rm /Library/LaunchDaemons/org.firebird.gds.plist exit 0 diff --git a/builds/posix/make.rules b/builds/posix/make.rules index e5ff03299b..a6fd2165d1 100644 --- a/builds/posix/make.rules +++ b/builds/posix/make.rules @@ -96,6 +96,10 @@ $(SRC_ROOT)/dsql/%.cpp:: $(SRC_ROOT)/dsql/%.epp $(OBJ)/jrd/%.o: $(SRC_ROOT)/jrd/$(PLATFORM_PATH)/%.cpp $(CXX) $(CXXFLAGS) -c $(firstword $<) -o $@ +ifneq ($(strip $(PLATFORM_FALLBACK)),) +$(OBJ)/jrd/%.o: $(SRC_ROOT)/jrd/$(PLATFORM_FALLBACK)/%.cpp + $(CXX) $(CXXFLAGS) -c $(firstword $<) -o $@ +endif $(OBJ)/%.o: $(SRC_ROOT)/%.c $(CC) $(CFLAGS) -c $(firstword $<) -o $@ diff --git a/builds/posix/postfix.darwin b/builds/posix/postfix.darwin index 21d2b413ce..8f491089da 100644 --- a/builds/posix/postfix.darwin +++ b/builds/posix/postfix.darwin @@ -52,6 +52,7 @@ darwin_finish_cs_framework: ln -s A $(FB_FW)/Versions/Current cp -r ../gen/firebird/include $(FB_FW)/Versions/A/Headers cp ../gen/firebird/lib/libfbembed.dylib $(FB_FW)/Versions/A/Firebird + cp ../gen/firebird/lib/libfbclient.dylib $(FB_FW)/Versions/A/Libraries/libfbclient.dylib cp ../gen/firebird/lib/libicudata.dylib $(FB_FW)/Versions/A/Libraries/libicudata.dylib cp ../gen/firebird/lib/libicui18n.dylib $(FB_FW)/Versions/A/Libraries/libicui18n.dylib cp ../gen/firebird/lib/libicuuc.dylib $(FB_FW)/Versions/A/Libraries/libicuuc.dylib @@ -68,8 +69,9 @@ darwin_finish_cs_framework: cp -r ../gen/firebird/help $(FB_FW)/Resources/English.lproj/var/help cp ../gen/firebird/security2.fdb $(FB_FW)/Resources/English.lproj/var mkdir -p $(FB_FW)/Resources/doc - ln -s ../../doc $(FB_FW)/Resources/doc cp -r ../doc $(FB_FW)/Resources + mkdir -p $(FB_FW)/Resources/examples + cp -r ../gen/firebird/examples $(FB_FW)/Resources mkdir -p $(FB_FW)/Resources/bin ln -s ../../bin $(FB_FW)/Resources/English.lproj/var/bin cp ../gen/firebird/bin/fb_inet_server $(FB_FW)/Resources/bin @@ -82,15 +84,15 @@ darwin_finish_cs_framework: cp ../gen/firebird/bin/fb_lock_mgr $(FB_FW)/Resources/bin cp ../gen/firebird/bin/fb_lock_print $(FB_FW)/Resources/bin cp ../gen/firebird/bin/gds_drop $(FB_FW)/Resources/bin - #cp ../gen/firebird/bin/gds_relay $(FB_FW)/Resources/bin cp ../gen/firebird/bin/gsec $(FB_FW)/Resources/bin cp ../gen/firebird/bin/gstat $(FB_FW)/Resources/bin cp ../gen/firebird/bin/nbackup $(FB_FW)/Resources/bin - #cp -r ../gen/firebird/examples $(FB_FW)/Resources/examples cp ../src/extlib/ib_udf.sql $(FB_FW)/Resources/English.lproj/var/UDF cp ../src/extlib/fbudf/fbudf.sql $(FB_FW)/Resources/English.lproj/var/UDF cp ../builds/install/arch-specific/darwin/FrameworkInfo.plist \ $(FB_FW)/Resources/Info.plist + cp ../builds/install/arch-specific/darwin/launchd.org.firebird.gds.plist \ + $(FB_FW)/Resources/org.firebird.gds.plist cp ../gen/firebird/misc/firebird.conf $(FB_FW)/Resources/English.lproj/var darwin_finish_ss_framework: FB_FW = ../gen/firebird/frameworks/FirebirdSS.framework @@ -123,6 +125,8 @@ darwin_finish_ss_framework: mkdir -p $(FB_FW)/Resources/doc ln -s ../../doc $(FB_FW)/Resources/doc cp -r ../doc $(FB_FW)/Resources + mkdir -p $(FB_FW)/Resources/examples + cp -r ../gen/firebird/examples $(FB_FW)/Resources mkdir -p $(FB_FW)/Resources/bin touch $(FB_FW)/Resources/.SuperServer ln -s ../../bin $(FB_FW)/Resources/English.lproj/var/bin @@ -141,8 +145,7 @@ darwin_finish_ss_framework: cp ../gen/firebird/bin/nbackup $(FB_FW)/Resources/bin cp ../gen/firebird/bin/qli $(FB_FW)/Resources/bin cp ../gen/firebird/bin/gdef $(FB_FW)/Resources/bin - #cp -r ../gen/firebird/examples $(FB_FW)/Resources/examples - cp ../src/extlib/ib_udf.sql $(FB_FW)/Resources/examples + cp ../src/extlib/ib_udf.sql $(FB_FW)/Resources/English.lproj/var/UDF cp ../src/extlib/fbudf/fbudf.sql $(FB_FW)/Resources/English.lproj/var/UDF cp ../builds/install/arch-specific/darwin/FrameworkInfo.plist \ $(FB_FW)/Resources/Info.plist diff --git a/builds/posix/prefix.darwin b/builds/posix/prefix.darwin index 93d19596f0..75f45ac20a 100644 --- a/builds/posix/prefix.darwin +++ b/builds/posix/prefix.darwin @@ -24,15 +24,15 @@ export DYLD_LIBRARY_PATH OS_ServerFiles=inet_server.cpp -PROD_FLAGS=-O3 -DNDEBUG -DDARWIN -pipe -MMD -p -fPIC -fno-common -DEV_FLAGS=-ggdb -DDARWIN -pipe -MMD -p -fPIC -fno-common -Wall +PROD_FLAGS=-O3 -DNDEBUG -DDARWIN -pipe -p -MMD -fPIC -fno-common -arch i386 +DEV_FLAGS=-ggdb -DDARWIN -pipe -p -MMD -fPIC -fno-common -Wall -arch i386 EMBED_UTIL_TARGETS=gstat gds_drop gsec nbackup fb_lock_print CLIENT_UTIL_TARGETS=gds_drop gstat gsec fbguard fbmgr_bin nbackup fb_lock_print Physical_IO_Module=os/posix/unix.cpp PLATFORM_PATH=os/darwin -LINK_OPTS:= +LINK_OPTS:=-Wl,-macosx_version_min -Wl,10.4 LIB_BUNDLE_OPTIONS:=$(LD_FLAGS) -bundle -flat_namespace -undefined suppress LIB_LINK_OPTIONS:=$(LD_FLAGS) -dynamiclib -flat_namespace LIB_LINK_SONAME:=-current_version 2.1.0 -compatibility_version 2.1.0 -seg1addr 0x30000000 @@ -41,11 +41,11 @@ LINK_FIREBIRD_EMBED_SYMBOLS=$(LIB_LINK_MAPFILE)$(ROOT)/builds/posix/firebird.dar LINK_FIREBIRD_CLIENT_SYMBOLS=$(LIB_LINK_MAPFILE)$(ROOT)/builds/posix/firebird.darwin.client.vers LINK_FBINTL_SYMBOLS=$(LIB_LINK_MAPFILE)$(ROOT)/builds/posix/fbintl.vers -LIB_LINK_RPATH:=-install_name /Firebird.framework/Versions/A/Libraries/ -LIB_EMBED_LINK_OPTIONS:= -install_name Firebird.framework/Versions/A/Firebird -LIB_CLIENT_LINK_OPTIONS:= -install_name Firebird.framework/Versions/A/Firebird +LIB_LINK_RPATH:=-install_name /Library/Frameworks//Firebird.framework/Versions/A/Libraries/ +LIB_EMBED_LINK_OPTIONS:=-install_name /Library/Frameworks/Firebird.framework/Versions/A/Firebird +LIB_CLIENT_LINK_OPTIONS:=-install_name /Library/Frameworks/Firebird.framework/Versions/A/Firebird FBEMBED_LINK:=-F../gen/firebird -framework Firebird -L$(LIB) -lfbembed - +PLATFORM_FALLBACK=os/posix PLAT_CLASSIC_PRE_TARGET=darwin_setup_framework PLAT_CLASSIC_POST_TARGET=darwin_finish_cs_framework diff --git a/configure.in b/configure.in index 2321363e3d..0d846ab9f1 100644 --- a/configure.in +++ b/configure.in @@ -583,8 +583,22 @@ if test "$ac_cv_header_semaphore_h" = "yes"; then savedFlags="$CFLAGS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" AC_CHECK_FUNCS(sem_timedwait) +AC_CHECK_FUNCS(sem_init) +if test "$ac_cv_func_sem_init" = "yes"; then +AC_MSG_CHECKING(for working sem_int()) +AC_TRY_RUN([#include + main () { + sem_t s; + exit(sem_init(&s,0,0)); + } + ], +[AC_DEFINE(WORKING_SEM_INIT,1,[Define this is sem_init() works on the platform]) +AC_MSG_RESULT(yes)], +[AC_MSG_RESULT(no)]) +fi CFLAGS="$savedFlags" fi +AC_CHECK_FUNCS(semtimedop) # Checks for typedefs, structures, and compiler characteristics. AC_C_BIGENDIAN diff --git a/src/common/classes/semaphore.h b/src/common/classes/semaphore.h index bedcb0bd5a..072fc760db 100644 --- a/src/common/classes/semaphore.h +++ b/src/common/classes/semaphore.h @@ -81,33 +81,55 @@ public: #include #include +#ifndef WORKING_SEM_INIT +#include +#endif namespace Firebird { +#ifndef WORKING_SEM_INIT +static const char* semName = "/firebird_temp_sem"; +#endif class SignalSafeSemaphore { private: - sem_t sem; +#ifdef WORKING_SEM_INIT + sem_t sem[1]; +#else + sem_t* sem; +#endif bool init; public: SignalSafeSemaphore() : init(false) { - if (sem_init(&sem, 0, 0) == -1) { - //gds__log("Error on semaphore.h: constructor"); +#ifdef WORKING_SEM_INIT + if (sem_init(sem, 0, 0) == -1) { system_call_failed::raise("sem_init"); } +#else + sem = sem_open(semName, O_CREAT | O_EXCL, 0700, 0); + if (sem == SEM_FAILED) { + system_call_failed::raise("sem_open"); + } + sem_unlink(semName); +#endif init = true; } ~SignalSafeSemaphore() { fb_assert(init == true); - if (sem_destroy(&sem) == -1) { - //gds__log("Error on semaphore.h: destructor"); +#ifdef WORKING_SEM_INIT + if (sem_destroy(sem) == -1) { system_call_failed::raise("sem_destroy"); } +#else + if (sem_close(sem) == -1) { + system_call_failed::raise("sem_close"); + } +#endif init = false; } @@ -116,7 +138,7 @@ public: { fb_assert(init == true); do { - if (sem_wait(&sem) != -1) + if (sem_wait(sem) != -1) return; } while (errno == EINTR); system_call_failed::raise("semaphore.h: enter: sem_wait()"); @@ -127,7 +149,7 @@ public: fb_assert(init == true); for (int i = 0; i < count; i++) { - if (sem_post(&sem) == -1) + if (sem_post(sem) == -1) { system_call_failed::raise("semaphore.h: release: sem_post()"); } } @@ -143,7 +165,7 @@ public: { // Instant try do { - if (sem_trywait(&sem) != -1) + if (sem_trywait(sem) != -1) return true; } while (errno == EINTR); if (errno == EAGAIN) @@ -154,7 +176,7 @@ public: { // Unlimited wait, like enter() do { - if (sem_wait(&sem) != -1) + if (sem_wait(sem) != -1) return true; } while (errno == EINTR); system_call_failed::raise("sem_wait"); @@ -165,7 +187,7 @@ public: timeout.tv_nsec = 0; int errcode = 0; do { - int rc = sem_timedwait(&sem, &timeout); + int rc = sem_timedwait(sem, &timeout); if (rc == 0) return true; // fix for CORE-988, also please see @@ -195,7 +217,7 @@ typedef SignalSafeSemaphore Semaphore; // Should implement Semaphore independent from SignalSafeSemaphore. // In the worst case no SignalSafeSemaphore at all (and no SS for that platform). -#ifdef HAVE_SYS_SEM_H +#if defined(HAVE_SYS_SEM_H) && defined(HAVE_SEMTIMEDOP) #include #include @@ -294,7 +316,12 @@ public: } // namespace Firebird -#else //HAVE_SYS_SEM_H +#else //defined(HAVE_SYS_SEM_H) && defined(HAVE_SEMTIMEDOP) + +// This implementation will NOT work with FB > 2.1 +#ifdef SOLARIS +#error Mutex/Condition based semaphore is NOT OK for Solaris +#endif #include #include @@ -477,7 +504,7 @@ public: } // namespace Firebird -#endif //HAVE_SYS_SEM_H +#endif //defined(HAVE_SYS_SEM_H) && defined(HAVE_SEMTIMEDOP) #endif //HAVE_SEM_TIMEDWAIT