Bug 639090: Once you've restarted into safe mode from the menu you cannot restart into normal mode. r=bsmedberg
authorDave Townsend <dtownsend@oxymoronical.com>
Wed, 23 Mar 2011 10:28:18 -0700
changeset 63553 5f420b83c3fc2c56eb5445992570f5483995c3dd
parent 63552 ebb87a57ed5b07336bdd4d26241400daacdb7bc2
child 63554 67ccac595b48a114aff6fa607f2e419031138b2d
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs639090
milestone2.2a1pre
Bug 639090: Once you've restarted into safe mode from the menu you cannot restart into normal mode. r=bsmedberg
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -286,16 +286,24 @@ static void
 SaveToEnv(const char *putenv)
 {
   char *expr = strdup(putenv);
   if (expr)
     PR_SetEnv(expr);
   // We intentionally leak |expr| here since it is required by PR_SetEnv.
 }
 
+// Tests that an environment variable exists and has a value
+static PRBool
+EnvHasValue(const char *name)
+{
+  const char *val = PR_GetEnv(name);
+  return (val && *val);
+}
+
 // Save the given word to the specified environment variable.
 static void
 SaveWordToEnv(const char *name, const nsACString & word)
 {
   char *expr = PR_smprintf("%s=%s", name, PromiseFlatCString(word).get());
   if (expr)
     PR_SetEnv(expr);
   // We intentionally leak |expr| here since it is required by PR_SetEnv.
@@ -347,28 +355,26 @@ GetFileFromEnv(const char *name)
 #endif
 }
 
 // Save the path of the given word to the specified environment variable
 // provided the environment variable does not have a value.
 static void
 SaveWordToEnvIfUnset(const char *name, const nsACString & word)
 {
-  const char *val = PR_GetEnv(name);
-  if (!(val && *val))
+  if (!EnvHasValue(name))
     SaveWordToEnv(name, word);
 }
 
 // Save the path of the given file to the specified environment variable
 // provided the environment variable does not have a value.
 static void
 SaveFileToEnvIfUnset(const char *name, nsIFile *file)
 {
-  const char *val = PR_GetEnv(name);
-  if (!(val && *val))
+  if (!EnvHasValue(name))
     SaveFileToEnv(name, file);
 }
 
 static PRBool
 strimatch(const char* lowerstr, const char* mixedstr)
 {
   while(*lowerstr) {
     if (!*mixedstr) return PR_FALSE; // mixedstr is shorter
@@ -2063,18 +2069,17 @@ SelectProfile(nsIProfileLock* *aResult, 
   *aStartOffline = PR_FALSE;
 
   ar = CheckArg("offline", PR_TRUE);
   if (ar == ARG_BAD) {
     PR_fprintf(PR_STDERR, "Error: argument -offline is invalid when argument -osint is specified\n");
     return NS_ERROR_FAILURE;
   }
 
-  arg = PR_GetEnv("XRE_START_OFFLINE");
-  if ((arg && *arg) || ar)
+  if (ar || EnvHasValue("XRE_START_OFFLINE"))
     *aStartOffline = PR_TRUE;
 
 
   nsCOMPtr<nsILocalFile> lf = GetFileFromEnv("XRE_PROFILE_PATH");
   if (lf) {
     nsCOMPtr<nsILocalFile> localDir =
       GetFileFromEnv("XRE_PROFILE_LOCAL_PATH");
     if (!localDir) {
@@ -2189,18 +2194,17 @@ SelectProfile(nsIProfileLock* *aResult, 
     return rv;
   }
 
   PRUint32 count;
   rv = profileSvc->GetProfileCount(&count);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (gAppData->flags & NS_XRE_ENABLE_PROFILE_MIGRATOR) {
-    arg = PR_GetEnv("XRE_IMPORT_PROFILES");
-    if (!count && (!arg || !*arg)) {
+    if (!count && !EnvHasValue("XRE_IMPORT_PROFILES")) {
       return ImportProfiles(profileSvc, aNative);
     }
   }
 
   ar = CheckArg("p", PR_FALSE, &arg);
   if (ar == ARG_BAD) {
     ar = CheckArg("osint");
     if (ar == ARG_FOUND) {
@@ -2826,17 +2830,17 @@ XRE_main(int argc, char* argv[], const n
     gtkModulesStr.ReplaceSubstring("atk-bridge", "");
     char* expr = PR_smprintf("GTK_MODULES=%s", gtkModulesStr.get());
     if (expr)
       PR_SetEnv(expr);
     // We intentionally leak |expr| here since it is required by PR_SetEnv.
   }
 
   // Suppress atk-bridge init at startup, it works after GNOME 2.24.2
-  PR_SetEnv("NO_AT_BRIDGE=1");
+  SaveToEnv("NO_AT_BRIDGE=1");
 #endif
 
   gArgc = argc;
   gArgv = argv;
 
   NS_ENSURE_TRUE(aAppData, 2);
 
 #ifdef XP_MACOSX
@@ -2986,18 +2990,17 @@ XRE_main(int argc, char* argv[], const n
   }
 
   nsXREDirProvider dirProvider;
   rv = dirProvider.Initialize(gAppData->directory, gAppData->xreDirectory);
   if (NS_FAILED(rv))
     return 1;
 
 #ifdef MOZ_CRASHREPORTER
-  const char* crashreporterEnv = PR_GetEnv("MOZ_CRASHREPORTER");
-  if (crashreporterEnv && *crashreporterEnv) {
+  if (EnvHasValue("MOZ_CRASHREPORTER")) {
     appData.flags |= NS_XRE_ENABLE_CRASH_REPORTER;
   }
 
   if ((appData.flags & NS_XRE_ENABLE_CRASH_REPORTER) &&
       NS_SUCCEEDED(
          CrashReporter::SetExceptionHandler(appData.xreDirectory))) {
     if (appData.crashReporterURL)
       CrashReporter::SetServerURL(nsDependentCString(appData.crashReporterURL));
@@ -3045,17 +3048,17 @@ XRE_main(int argc, char* argv[], const n
                 overridePath.get());
         PR_SetEnv(overrideEnv);
       }
     }
   }
 #endif
 
 #ifdef XP_MACOSX
-  if (PR_GetEnv("MOZ_LAUNCHED_CHILD")) {
+  if (EnvHasValue("MOZ_LAUNCHED_CHILD")) {
     // This is needed, on relaunch, to force the OS to use the "Cocoa Dock
     // API".  Otherwise the call to ReceiveNextEvent() below will make it
     // use the "Carbon Dock API".  For more info see bmo bug 377166.
     EnsureUseCocoaDockAPI();
 
     // When the app relaunches, the original process exits.  This causes
     // the dock tile to stop bouncing, lose the "running" triangle, and
     // if the tile does not permanently reside in the Dock, even disappear.
@@ -3100,20 +3103,20 @@ XRE_main(int argc, char* argv[], const n
 
 #if defined(XP_OS2)
   PRBool StartOS2App(int aArgc, char **aArgv);
   if (!StartOS2App(gArgc, gArgv))
     return 1;
   ScopedFPHandler handler;
 #endif /* XP_OS2 */
 
-  if (PR_GetEnv("MOZ_SAFE_MODE_RESTART")) {
+  if (EnvHasValue("MOZ_SAFE_MODE_RESTART")) {
     gSafeMode = PR_TRUE;
     // unset the env variable
-    PR_SetEnv("MOZ_SAFE_MODE_RESTART=");
+    SaveToEnv("MOZ_SAFE_MODE_RESTART=");
   }
 
   ar = CheckArg("safe-mode", PR_TRUE);
   if (ar == ARG_BAD) {
     PR_fprintf(PR_STDERR, "Error: argument -safe-mode is invalid when argument -osint is specified\n");
     return 1;
   } else if (ar == ARG_FOUND) {
     gSafeMode = PR_TRUE;
@@ -3372,18 +3375,18 @@ XRE_main(int argc, char* argv[], const n
       SaveToEnv("MOZ_PROCESS_UPDATES=1");
     }
     ProcessUpdates(dirProvider.GetGREDir(),
                    dirProvider.GetAppDir(),
                    updRoot,
                    gRestartArgc,
                    gRestartArgv,
                    appData.version);
-    if (PR_GetEnv("MOZ_PROCESS_UPDATES")) {
-      PR_SetEnv("MOZ_PROCESS_UPDATES=");
+    if (EnvHasValue("MOZ_PROCESS_UPDATES")) {
+      SaveToEnv("MOZ_PROCESS_UPDATES=");
       return 0;
     }
 #endif
 
     nsCOMPtr<nsIProfileLock> profileLock;
     PRBool startOffline = PR_FALSE;
     nsCAutoString profileName;