Bug 823695 - unsetenv LD_PRELOAD when running the updater. r=cjones
authorDave Hylands <dhylands@gmail.com>
Mon, 14 Jan 2013 23:18:44 -0800
changeset 118868 7265493e26b047b97af8b85eeadb41b190cc55b0
parent 118867 2fb031ef6180ae7a8a97a4dfd570b546cdf5a423
child 118869 657519272d564619da06f300098bc3ae83b6d52a
push id24180
push useremorley@mozilla.com
push dateTue, 15 Jan 2013 22:58:27 +0000
treeherdermozilla-central@72e34ce7fd92 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs823695
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 823695 - unsetenv LD_PRELOAD when running the updater. r=cjones
toolkit/mozapps/update/updater/updater.cpp
--- a/toolkit/mozapps/update/updater/updater.cpp
+++ b/toolkit/mozapps/update/updater/updater.cpp
@@ -78,16 +78,17 @@ void LaunchMacPostProcess(const char* aA
 // we were launched using execv.  See nsUpdateDriver.cpp.
 #if defined(XP_UNIX) && !defined(XP_MACOSX)
 #define USE_EXECV
 #endif
 
 #if defined(MOZ_WIDGET_GONK)
 # include "automounter_gonk.h"
 # include <unistd.h>
+# include <android/log.h>
 # define MAYBE_USE_HARD_LINKS 1
 static bool sUseHardLinks = true;
 #else
 # define MAYBE_USE_HARD_LINKS 0
 #endif
 
 #ifdef XP_WIN
 #include "updatehelper.h"
@@ -2245,16 +2246,33 @@ UpdateThreadFunc(void *param)
   }
 
   LOG(("calling QuitProgressUI"));
   QuitProgressUI();
 }
 
 int NS_main(int argc, NS_tchar **argv)
 {
+#if defined(MOZ_WIDGET_GONK)
+  if (getenv("LD_PRELOAD")) {
+    // If the updater is launched with LD_PRELOAD set, then we wind up
+    // preloading libmozglue.so. Under some circumstances, this can cause
+    // the remount of /system to fail when going from rw to ro, so if we
+    // detect LD_PRELOAD we unsetenv it and relaunch ourselves without it.
+    // This will cause the offending preloaded library to be closed.
+    //
+    // For a variety of reasons, this is really hard to do in a safe manner
+    // in the parent process, so we do it here.
+    unsetenv("LD_PRELOAD");
+    execv(argv[0], argv);
+    __android_log_print(ANDROID_LOG_INFO, "updater",
+                        "execve failed: errno: %d. Exiting...", errno);
+    _exit(1);
+  }
+#endif
   InitProgressUI(&argc, &argv);
 
   // To process an update the updater command line must at a minimum have the
   // directory path containing the updater.mar file to process as the first argument
   // and the directory to apply the update to as the second argument. When the
   // updater is launched by another process the PID of the parent process should be
   // provided in the optional third argument and the updater will wait on the parent
   // process to exit if the value is non-zero and the process is present. This is