$OpenBSD$ index 2b9f8b4..aeb2b6b 100644 --- toolkit/xre/nsUpdateDriver.cpp.orig Fri Feb 20 15:40:39 2015 +++ toolkit/xre/nsUpdateDriver.cpp Fri Feb 20 15:40:39 2015 @@ -17,6 +17,7 @@ #include "prproces.h" #include "prlog.h" #include "prenv.h" +#include "prprf.h" #include "nsVersionComparator.h" #include "nsXREDirProvider.h" #include "SpecialSystemDirectory.h" @@ -132,6 +133,62 @@ GetCurrentWorkingDir(char *buf, size_t size) return NS_OK; } + +// In Tor Browser, updater(.exe) depends on some shared libraries that are +// located in the app directory. To allow the updater to run when it has been +// copied into the update directory, we prepend the app directory to the +// appropriate environment variable so it will be searched by the dynamic +// linker. + +#if defined(XP_WIN) +#define PATH_SEPARATOR ";" +#define LD_LIBRARY_PATH_ENVVAR_NAME "PATH" +#else +#define PATH_SEPARATOR ":" +#if defined(XP_MACOSX) +#define LD_LIBRARY_PATH_ENVVAR_NAME "DYLD_LIBRARY_PATH" +#else +#define LD_LIBRARY_PATH_ENVVAR_NAME "LD_LIBRARY_PATH" +#endif +#endif + +static nsresult +AdjustLibSearchPathForUpdater(nsIFile *appDir) +{ + nsAutoCString appPath; + nsresult rv = appDir->GetNativePath(appPath); + NS_ENSURE_SUCCESS(rv, rv); + + char *s = nullptr; + char *pathValue = PR_GetEnv(LD_LIBRARY_PATH_ENVVAR_NAME); + if ((nullptr == pathValue) || ('\0' == *pathValue)) { + s = PR_smprintf("%s=%s", + LD_LIBRARY_PATH_ENVVAR_NAME, appPath.get()); + } else { + s = PR_smprintf("%s=%s" PATH_SEPARATOR "%s", + LD_LIBRARY_PATH_ENVVAR_NAME, appPath.get(), pathValue); + } + + // We intentionally leak the value that is passed into PR_SetEnv() because + // the environment will hold a pointer to it. + if ((nullptr == s) || (PR_SUCCESS != PR_SetEnv(s))) + return NS_ERROR_FAILURE; + + return NS_OK; +} + + +#ifdef DEBUG +static void +dump_argv(const char *aPrefix, char **argv, int argc) +{ + printf("%s - %d args\n", aPrefix, argc); + for (int i = 0; i < argc; ++i) + printf(" %d: %s\n", i, argv[i]); +} +#endif + + #if defined(XP_MACOSX) // This is a copy of OS X's XRE_GetBinaryPath from nsAppRunner.cpp with the // gBinaryPath check removed so that the updater can reload the stub executable @@ -287,6 +344,10 @@ IsOlderVersion(nsIFile *versionFile, const char *appVersion) if (strncmp(buf, kNull, sizeof(kNull) - 1) == 0) return false; +#ifdef DEBUG + printf("IsOlderVersion checking appVersion %s against updateVersion %s\n", + appVersion, buf); +#endif if (mozilla::Version(appVersion) > buf) return true; @@ -576,6 +637,11 @@ SwitchToUpdatedApp(nsIFile *greDir, nsIFile *updateDir, nsIFile *statusFile, PR_SetEnv("MOZ_SAFE_MODE_RESTART=1"); } + nsresult rv2 = AdjustLibSearchPathForUpdater(appDir); + if (NS_FAILED(rv2)) { + LOG(("SwitchToUpdatedApp -- AdjustLibSearchPathForUpdater failed (0x%x)\n", rv2)); + } + LOG(("spawning updater process for replacing [%s]\n", updaterPath.get())); #if defined(USE_EXECV) @@ -865,6 +931,12 @@ ApplyUpdate(nsIFile *greDir, nsIFile *updateDir, nsIFile *statusFile, if (isOSUpdate) { PR_SetEnv("MOZ_OS_UPDATE=1"); } + + nsresult rv2 = AdjustLibSearchPathForUpdater(appDir); + if (NS_FAILED(rv2)) { + LOG(("ApplyUpdate -- AdjustLibSearchPathForUpdater failed (0x%x)\n", rv2)); + } + #if defined(MOZ_WIDGET_GONK) // We want the updater to be CPU friendly and not subject to being killed by // the low memory killer, so we pass in some preferences to allow it to @@ -884,6 +956,9 @@ ApplyUpdate(nsIFile *greDir, nsIFile *updateDir, nsIFile *statusFile, #endif LOG(("spawning updater process [%s]\n", updaterPath.get())); +#ifdef DEBUG + dump_argv("ApplyUpdate updater", argv, argc); +#endif #if defined(USE_EXECV) // Don't use execv when staging updates. @@ -907,6 +982,9 @@ ApplyUpdate(nsIFile *greDir, nsIFile *updateDir, nsIFile *statusFile, // LaunchChildMac uses posix_spawnp and prefers the current // architecture when launching. It doesn't require a // null-terminated string but it doesn't matter if we pass one. +#ifdef DEBUG + dump_argv("ApplyUpdate after SetupMacCommandLine", argv, argc); +#endif LaunchChildMac(argc, argv, 0, outpid); if (restart) { exit(0); @@ -948,6 +1026,12 @@ ProcessUpdates(nsIFile *greDir, nsIFile *appDir, nsIFile *updRootDir, nsresult rv; nsCOMPtr updatesDir; +#ifdef DEBUG + nsAutoCString path; + updRootDir->GetNativePath(path); + printf("ProcessUpdates updateRootDir: %s appVersion: %s\n", + path.get(), appVersion); +#endif rv = updRootDir->Clone(getter_AddRefs(updatesDir)); if (NS_FAILED(rv)) return rv; @@ -973,6 +1057,11 @@ ProcessUpdates(nsIFile *greDir, nsIFile *appDir, nsIFile *updRootDir, nsCOMPtr statusFile; UpdateStatus status = GetUpdateStatus(updatesDir, statusFile); +#ifdef DEBUG + printf("ProcessUpdates status: %d\n", status); + updatesDir->GetNativePath(path); + printf("ProcessUpdates updatesDir: %s\n", path.get()); +#endif switch (status) { case ePendingUpdate: case ePendingService: { @@ -1052,7 +1141,11 @@ nsUpdateProcessor::ProcessUpdate(nsIUpdate* aUpdate) if (NS_FAILED(rv)) appDir = dirProvider->GetAppDir(); +#ifdef TOR_BROWSER_UPDATE + appVersion = TOR_BROWSER_VERSION; +#else appVersion = gAppData->version; +#endif argc = gRestartArgc; argv = gRestartArgv; } else { @@ -1076,6 +1169,8 @@ nsUpdateProcessor::ProcessUpdate(nsIUpdate* aUpdate) if (NS_FAILED(rv)) updRoot = appDir; + // To support Tor Browser Bundle updates from xpcshell, modify the + // following code to use the TBB version fron the configure process. nsCOMPtr appInfo = do_GetService("@mozilla.org/xre/app-info;1"); if (appInfo) {