Bug 1463560: Part 1: Re-add the -os-restarted arg when launching after an update. r=mhowell draft
authorAdam Gashlin <agashlin@mozilla.com>
Sun, 27 May 2018 12:22:05 -0700
changeset 803777 7efb75b292d59b35913b4b118594e193f2ceb76f
parent 802711 9900cebb1f9000bd05731ba67736b7c51f7eb812
child 803778 ba9519fde4a6b6762a328a211a23646c435e76f8
push id112180
push userbmo:agashlin@mozilla.com
push dateMon, 04 Jun 2018 20:07:38 +0000
reviewersmhowell
bugs1463560
milestone62.0a1
Bug 1463560: Part 1: Re-add the -os-restarted arg when launching after an update. r=mhowell MozReview-Commit-ID: 509GetTCBCF
toolkit/xre/nsAppRunner.h
toolkit/xre/nsUpdateDriver.cpp
--- a/toolkit/xre/nsAppRunner.h
+++ b/toolkit/xre/nsAppRunner.h
@@ -40,16 +40,17 @@ extern nsXREDirProvider* gDirServiceProv
 // NOTE: gAppData will be null in embedded contexts.
 extern const mozilla::XREAppData* gAppData;
 extern bool gSafeMode;
 
 extern int    gArgc;
 extern char **gArgv;
 extern int    gRestartArgc;
 extern char **gRestartArgv;
+extern bool gRestartedByOS;
 extern bool gLogConsoleErrors;
 extern nsString gAbsoluteArgv0Path;
 
 extern bool gIsGtest;
 
 /**
  * Create the nativeappsupport implementation.
  *
--- a/toolkit/xre/nsUpdateDriver.cpp
+++ b/toolkit/xre/nsUpdateDriver.cpp
@@ -601,36 +601,42 @@ ApplyUpdate(nsIFile *greDir, nsIFile *up
   } else {
     // Signal the updater application that it should stage the update.
     pid.AssignASCII("-1");
   }
 
   int argc = 5;
   if (restart) {
     argc = appArgc + 6;
+    if (gRestartedByOS) {
+      argc += 1;
+    }
   }
   char **argv = new char*[argc + 1];
   if (!argv) {
     return;
   }
   argv[0] = (char*) updaterPath.get();
   argv[1] = (char*) updateDirPath.get();
   argv[2] = (char*) installDirPath.get();
   argv[3] = (char*) applyToDirPath.get();
   argv[4] = (char*) pid.get();
   if (restart && appArgc) {
     argv[5] = workingDirPath;
     argv[6] = (char*) appFilePath.get();
     for (int i = 1; i < appArgc; ++i) {
       argv[6 + i] = appArgv[i];
     }
-    argv[argc] = nullptr;
-  } else {
-    argv[5] = nullptr;
+    if (gRestartedByOS) {
+      // We haven't truly started up, restore this argument so that we will have
+      // it upon restart.
+      argv[6 + appArgc] = const_cast<char*>("-os-restarted");
+    }
   }
+  argv[argc] = nullptr;
 
   if (restart && gSafeMode) {
     PR_SetEnv("MOZ_SAFE_MODE_RESTART=1");
   }
 
 #if defined(MOZ_VERIFY_MAR_SIGNATURE) && !defined(XP_WIN) && !defined(XP_MACOSX)
   AppendToLibPath(installDirPath.get());
 #endif