From e359383d3bebd583b894c9ee9d02cce2be318b56 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 26 Jul 2017 20:15:05 -0400 Subject: [PATCH 1/3] Mac: Don't execve in main or fork & crash to evade its ill effects... This at once reverts fixes for bugs 543 and 290; 290 being a problem loading libraries, 543 being a minor problem with the fix for 290, resulting in a rewrite of the fix, but this rewrite having bad consequences, as in bugs 1567 and 1703. See discussion in bug 1702 for the detailed history See also commits a05d039055909d7d1dc2d4f31e1fe0659a3207dd (fork and crash) 36361a6b86dac4b0f2b16b7017007b4cc7717c7a (introduced execve) --- src/AudacityApp.cpp | 50 +-------------------------------------------- src/AudacityApp.h | 5 ----- src/MenusMac.cpp | 6 ------ 3 files changed, 1 insertion(+), 60 deletions(-) diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index 1517ab56a..802537476 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -651,54 +651,12 @@ public: }; #if defined(__WXMAC__) -// This should be removed when Lame and FFmpeg support is converted -// from loadable libraries to commands. -// -// The purpose of this is to give the user more control over where libraries -// such as Lame and FFmpeg get loaded from. -// -// Since absolute pathnames are used when loading these libraries, the normal search -// path would be DYLD_LIBRARY_PATH, absolute path, DYLD_FALLBACK_LIBRARY_PATH. This -// means that DYLD_LIBRARY_PATH can override what the user actually wants. -// -// So, we simply clear DYLD_LIBRARY_PATH to allow the users choice to be the first -// one tried. + IMPLEMENT_APP_NO_MAIN(AudacityApp) IMPLEMENT_WX_THEME_SUPPORT int main(int argc, char *argv[]) { - bool doCrash = false; - -#ifdef FIX_BUG1567 - doCrash = AudacityApp::IsSierraOrLater(); -#endif - - bool doExec = !doCrash && getenv("DYLD_LIBRARY_PATH"); - unsetenv("DYLD_LIBRARY_PATH"); - - extern char **environ; - -#ifdef FIX_BUG1567 - const char *var_name = "_NO_CRASH"; - if ( doCrash && !( getenv( var_name ) ) ) { - setenv(var_name, "1", TRUE); - // Bizarre fix for Bug1567 - // Crashing one Audacity and immediately starting another avoids intermittent - // failures to load libraries on Sierra - if ( fork() ) - // The original process crashes at once - raise(SIGTERM); - - // Child process can't proceed until doing this: - execve(argv[0], argv, environ); - } - else -#else - if (doExec) - execve(argv[0], argv, environ); -#endif - wxDISABLE_DEBUG_SUPPORT(); return wxEntry(argc, argv); @@ -1542,12 +1500,6 @@ bool AudacityApp::OnInit() temporarywindow.SetTitle(_("Audacity is starting up...")); SetTopWindow(&temporarywindow); -#ifdef FIX_BUG1567 - // Without this, splash screen may be hidden under other programs. - if (IsSierraOrLater()) - MacActivateApp(); -#endif - // ANSWER-ME: Why is YieldFor needed at all? //wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI|wxEVT_CATEGORY_USER_INPUT|wxEVT_CATEGORY_UNKNOWN); wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI); diff --git a/src/AudacityApp.h b/src/AudacityApp.h index edf1961f7..dafca471b 100644 --- a/src/AudacityApp.h +++ b/src/AudacityApp.h @@ -164,12 +164,7 @@ class AudacityApp final : public wxApp { #ifdef __WXMAC__ - #if ! defined(__WXDEBUG__) - #define FIX_BUG1567 - #endif - void MacActivateApp(); - static bool IsSierraOrLater(); #endif diff --git a/src/MenusMac.cpp b/src/MenusMac.cpp index a1b091eca..3b74e0fe4 100644 --- a/src/MenusMac.cpp +++ b/src/MenusMac.cpp @@ -92,9 +92,3 @@ void AudacityApp::MacActivateApp() if ( [app respondsToSelector:@selector(activateIgnoringOtherApps:)] ) [app activateIgnoringOtherApps:YES]; } - -bool AudacityApp::IsSierraOrLater() -{ - auto number = kCFCoreFoundationVersionNumber; - return number >= 1348.1; -} From 8b32eea8bb32c95a6e0f59e4061d22eb6c89d2e2 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 26 Jul 2017 23:51:50 -0400 Subject: [PATCH 2/3] Bug290 (load LAME, FFmpeg from correct place): original fix again... ... That is, put a little shell script in the application bundle, and invoke it (in Release, though not Debug where it interferes with Xcode debugging) See commit 07661c186f7e8e6d978fa35485d65364b96dfb3a The shell nulls the environment variable DYLD_LIBRARY_PATH and then executes the main program. This is needed because changes to DYLD_LIBRARY_PATH during the main program's run fail to affect the loading of dynamic libraries afterward. We need null in DYLD_LIBRARY_PATH to make absolute paths to libraries take priority. More info: Documentation of workings of the macOS dynamic loader https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryUsageGuidelines.html The same problem and solution is discussed here https://stackoverflow.com/questions/6713692/problems-with-using-setenv-and-then-making-the-dlopen-call It is claimed there that Firefox did the same trick with a shell, which I do not observe in my version, but GIMP 2.8.16 does this, as I can see by examining package contents Also note the mention in this commit's comments (where the script was removed because bug543's fix left it unused), that the script also used to interfere with signing. I hope that there will be a way around that. 98186b9317adf842e0469fe98175b55da31d3210 --- mac/Audacity.sh | 21 +++++++++++++++++++++ mac/Audacity.xcodeproj/project.pbxproj | 15 +++++++++++++++ mac/scripts/create_info_header.sh | 8 +++++++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 mac/Audacity.sh diff --git a/mac/Audacity.sh b/mac/Audacity.sh new file mode 100755 index 000000000..9c856ab6c --- /dev/null +++ b/mac/Audacity.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# +# The purpose of this script is to give the user more control over where libraries +# such as Lame and FFmpeg get loaded from. +# +# Since absolute pathnames are used when loading these libraries, the normal search +# path would be DYLD_LIBRARY_PATH, absolute path, DYLD_FALLBACK_LIBRARY_PATH. This +# means that DYLD_LIBRARY_PATH can override what the user actually wants. +# +# So, we simply clear DYLD_LIBRARY_PATH to allow the users choice to be the first +# one tried. +# + +DYLD_FALLBACK_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$DYLD_FALLBACK_LIBRARY_PATH:$HOME/lib:/usr/local/lib:/usr/lib" +export DYLD_FALLBACK_LIBRARY_PATH + +DYLD_LIBRARY_PATH="" +export DYLD_LIBRARY_PATH + +dir=$(dirname "$0") +"$dir/Audacity" diff --git a/mac/Audacity.xcodeproj/project.pbxproj b/mac/Audacity.xcodeproj/project.pbxproj index 107807302..381d9acff 100644 --- a/mac/Audacity.xcodeproj/project.pbxproj +++ b/mac/Audacity.xcodeproj/project.pbxproj @@ -890,6 +890,7 @@ 28BD8AB3101DF4C700686679 /* ExecMenuCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28BD8AAC101DF4C600686679 /* ExecMenuCommand.cpp */; }; 28BD8AB4101DF4C700686679 /* GetAllMenuCommands.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28BD8AAE101DF4C600686679 /* GetAllMenuCommands.cpp */; }; 28C3946D1818356800FDDAC9 /* AudacityLogger.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28C3946B1818356800FDDAC9 /* AudacityLogger.cpp */; }; + 28C816BA131255790035BB10 /* Audacity.sh in Install wrapper */ = {isa = PBXBuildFile; fileRef = 28C816B81312555B0035BB10 /* Audacity.sh */; }; 28C8211D1B5C661E00B53328 /* ViewInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28C8211C1B5C661E00B53328 /* ViewInfo.cpp */; }; 28CA9E6B1AE60C53005C0BFE /* dBTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82FF184D13CF01A600C1B664 /* dBTable.cpp */; }; 28CA9E6C1AE60C53005C0BFE /* dBTable.h in Headers */ = {isa = PBXBuildFile; fileRef = 82FF184E13CF01A600C1B664 /* dBTable.h */; }; @@ -1491,6 +1492,17 @@ name = "Install miscellany"; runOnlyForDeploymentPostprocessing = 1; }; + 28C816B7131255550035BB10 /* Install wrapper */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 8; + dstPath = ""; + dstSubfolderSpec = 6; + files = ( + 28C816BA131255790035BB10 /* Audacity.sh in Install wrapper */, + ); + name = "Install wrapper"; + runOnlyForDeploymentPostprocessing = 1; + }; ED95519E195D956F0027176E /* Install background image */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 8; @@ -2697,6 +2709,7 @@ 28CC03A61AD386CF00826380 /* sndsliders.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sndsliders.c; sourceTree = ""; }; 28CC03A71AD386CF00826380 /* sndsliders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sndsliders.h; sourceTree = ""; }; 28CC03B01AD3874500826380 /* security.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = security.c; sourceTree = ""; }; + 28C816B81312555B0035BB10 /* Audacity.sh */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text.script.sh; name = Audacity.sh; path = mac/Audacity.sh; sourceTree = ""; }; 28CCDCFF0F939FD70081F2FC /* FileHistory.cpp */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.cpp.cpp; path = FileHistory.cpp; sourceTree = ""; tabWidth = 3; }; 28CCDD040F93A0B20081F2FC /* FileHistory.h */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = FileHistory.h; sourceTree = ""; tabWidth = 3; }; 28D000A31A32920C00367B21 /* DeviceChange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeviceChange.cpp; sourceTree = ""; }; @@ -3913,6 +3926,7 @@ isa = PBXGroup; children = ( 174F73C8098D516D009CD6E0 /* Resources */, + 28C816B81312555B0035BB10 /* Audacity.sh */, 28006FFA132C167600BD34D7 /* Install.txt */, 178CF4FF0989541C0056CE58 /* configmac.h */, 174F73D7098D51AA009CD6E0 /* Info.plist */, @@ -6800,6 +6814,7 @@ 28708D631B17C3C400496FEB /* Copy wxWidgets libs */, 288F0980131A400F0008E860 /* Install manual */, 282413DA131D52CE009FD931 /* Install plugins */, + 28C816B7131255550035BB10 /* Install wrapper */, 2892CE28131AFB1900E1E17D /* Install miscellany */, ED95519E195D956F0027176E /* Install background image */, 282413D8131D51FC009FD931 /* Create dist */, diff --git a/mac/scripts/create_info_header.sh b/mac/scripts/create_info_header.sh index 15aa10999..b5df33c1e 100755 --- a/mac/scripts/create_info_header.sh +++ b/mac/scripts/create_info_header.sh @@ -21,8 +21,14 @@ done cd ${TOPLEVEL} mkdir -p mac/build eval $(g++ -E -dM src/Audacity.h | awk '/#define *AUDACITY_(VERSION|RELEASE|REVISION|MODLEVEL) /{print $2 "=" $3}') +if [ $CONFIGURATION == 'Debug' ] +then + AUDACITY_EXECUTABLE=Audacity +else + AUDACITY_EXECUTABLE=Audacity.sh +fi cat >mac/build/Info.plist.h < Date: Thu, 27 Jul 2017 13:56:27 -0400 Subject: [PATCH 3/3] Copying of Audacity.sh not an intall-only step, for debug convenience --- mac/Audacity.xcodeproj/project.pbxproj | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/mac/Audacity.xcodeproj/project.pbxproj b/mac/Audacity.xcodeproj/project.pbxproj index 381d9acff..31ba571e0 100644 --- a/mac/Audacity.xcodeproj/project.pbxproj +++ b/mac/Audacity.xcodeproj/project.pbxproj @@ -1494,14 +1494,14 @@ }; 28C816B7131255550035BB10 /* Install wrapper */ = { isa = PBXCopyFilesBuildPhase; - buildActionMask = 8; + buildActionMask = 12; dstPath = ""; dstSubfolderSpec = 6; files = ( 28C816BA131255790035BB10 /* Audacity.sh in Install wrapper */, ); name = "Install wrapper"; - runOnlyForDeploymentPostprocessing = 1; + runOnlyForDeploymentPostprocessing = 0; }; ED95519E195D956F0027176E /* Install background image */ = { isa = PBXCopyFilesBuildPhase; @@ -2697,6 +2697,7 @@ 28BD8AB0101DF4C600686679 /* Validators.h */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = Validators.h; sourceTree = ""; tabWidth = 3; }; 28C3946B1818356800FDDAC9 /* AudacityLogger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudacityLogger.cpp; sourceTree = ""; }; 28C3946C1818356800FDDAC9 /* AudacityLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudacityLogger.h; sourceTree = ""; }; + 28C816B81312555B0035BB10 /* Audacity.sh */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text.script.sh; name = Audacity.sh; path = mac/Audacity.sh; sourceTree = ""; }; 28C8211C1B5C661E00B53328 /* ViewInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ViewInfo.cpp; sourceTree = ""; }; 28CBD65D1B9F7DF7003AC5EE /* pt_PT.po */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = pt_PT.po; path = ../locale/pt_PT.po; sourceTree = ""; }; 28CBD65E1B9F7DF7003AC5EE /* zh_CN.po */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = zh_CN.po; path = ../locale/zh_CN.po; sourceTree = ""; }; @@ -2709,7 +2710,6 @@ 28CC03A61AD386CF00826380 /* sndsliders.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sndsliders.c; sourceTree = ""; }; 28CC03A71AD386CF00826380 /* sndsliders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sndsliders.h; sourceTree = ""; }; 28CC03B01AD3874500826380 /* security.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = security.c; sourceTree = ""; }; - 28C816B81312555B0035BB10 /* Audacity.sh */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text.script.sh; name = Audacity.sh; path = mac/Audacity.sh; sourceTree = ""; }; 28CCDCFF0F939FD70081F2FC /* FileHistory.cpp */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.cpp.cpp; path = FileHistory.cpp; sourceTree = ""; tabWidth = 3; }; 28CCDD040F93A0B20081F2FC /* FileHistory.h */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = FileHistory.h; sourceTree = ""; tabWidth = 3; }; 28D000A31A32920C00367B21 /* DeviceChange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeviceChange.cpp; sourceTree = ""; }; @@ -8436,8 +8436,7 @@ SDKROOT = macosx10.6; SSE_CPPFLAGS = "-Xarch_i386 -DAPPLE_I386"; TOPLEVEL = ..; - WARNING_CFLAGS = ( - ); + WARNING_CFLAGS = ""; WX_CFLAGS = "-I$(WX_PREFIX)/lib/wx/include/osx_cocoa-unicode-$(WX_VER)-$(WX_FLAVOR) -I$(WX_PREFIX)/include/wx-$(WX_VER)-$(WX_FLAVOR) -D_FILE_OFFSET_BITS=64 -DwxDEBUG_LEVEL=1 -DWXUSINGDLL -D__WXMAC__ -D__WXOSX__ -D__WXOSX_COCOA__"; WX_CONFIG = "$(WX_PREFIX)/bin/wx-config"; WX_CXXFLAGS = "$(WX_CFLAGS)"; @@ -8763,8 +8762,7 @@ SDKROOT = macosx10.6; SSE_CPPFLAGS = "-Xarch_i386 -DAPPLE_I386"; TOPLEVEL = ..; - WARNING_CFLAGS = ( - ); + WARNING_CFLAGS = ""; WX_CFLAGS = "-I$(WX_PREFIX)/lib/wx/include/osx_cocoa-unicode-$(WX_VER)-$(WX_FLAVOR) -I$(WX_PREFIX)/include/wx-$(WX_VER)-$(WX_FLAVOR) -D_FILE_OFFSET_BITS=64 -DwxDEBUG_LEVEL=0 -DWXUSINGDLL -D__WXMAC__ -D__WXOSX__ -D__WXOSX_COCOA__"; WX_CONFIG = "$(WX_PREFIX)/bin/wx-config"; WX_CXXFLAGS = "$(WX_CFLAGS)";