Bug 1268475: Allow elevated updater on OSX to make 10 IPC connection attempts to obtain updater arguments. r=mstange
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Wed, 04 May 2016 16:44:07 -0400
changeset 491520 49ffaf5f3c29ea098c1ff7e3fcf63dcc648727b3
parent 491519 29c972eff732f14deeab1f98baf0290bf90f75d8
child 491521 aad19b0e37a40fccb0614bc52d31259f99249181
push id47343
push userbmo:dothayer@mozilla.com
push dateWed, 01 Mar 2017 22:58:58 +0000
reviewersmstange
bugs1268475
milestone49.0a1
Bug 1268475: Allow elevated updater on OSX to make 10 IPC connection attempts to obtain updater arguments. r=mstange
toolkit/mozapps/update/updater/launchchild_osx.mm
--- a/toolkit/mozapps/update/updater/launchchild_osx.mm
+++ b/toolkit/mozapps/update/updater/launchchild_osx.mm
@@ -141,28 +141,42 @@ void CleanupElevatedMacUpdate(bool aFail
 
 // Note: Caller is responsible for freeing argv.
 bool ObtainUpdaterArguments(int* argc, char*** argv)
 {
   MacAutoreleasePool pool;
 
   id updateServer = nil;
   @try {
-    updateServer = (id)[NSConnection
-      rootProxyForConnectionWithRegisteredName:
-        @"org.mozilla.updater.server"
-      host:nil
-      usingNameServer:[NSSocketPortNameServer sharedInstance]];
-    if (!updateServer ||
-        ![updateServer respondsToSelector:@selector(getArguments)] ||
-        ![updateServer respondsToSelector:@selector(shutdown)]) {
-      NSLog(@"Server doesn't exist or doesn't provide correct selectors.");
-      // Let's try our best and clean up.
-      CleanupElevatedMacUpdate(true);
-      return false; // Won't actually get here due to CleanupElevatedMacUpdate.
+    BOOL isConnected = NO;
+    int currTry = 0;
+    const int numRetries = 10; // Number of IPC connection retries before
+                               // giving up.
+    while (!isConnected) {
+      updateServer = (id)[NSConnection
+        rootProxyForConnectionWithRegisteredName:
+          @"org.mozilla.updater.server"
+        host:nil
+        usingNameServer:[NSSocketPortNameServer sharedInstance]];
+      if (!updateServer ||
+          ![updateServer respondsToSelector:@selector(getArguments)] ||
+          ![updateServer respondsToSelector:@selector(shutdown)]) {
+        NSLog(@"Server doesn't exist or doesn't provide correct selectors.");
+        if (currTry >= numRetries) {
+          // We've exceeded the number of permissible connection retry attempts.
+          // Let's try our best and clean up.
+          CleanupElevatedMacUpdate(true);
+          return false; // Won't actually get here due to
+                        // CleanupElevatedMacUpdate.
+        }
+        sleep(1); // Wait 1 second.
+        currTry++;
+      } else {
+        isConnected = YES;
+      }
     }
     NSArray* updaterArguments =
       [updateServer performSelector:@selector(getArguments)];
     *argc = [updaterArguments count];
     char** tempArgv = (char**)malloc(sizeof(char*) * (*argc));
     for (int i = 0; i < *argc; i++) {
       int argLen = [[updaterArguments objectAtIndex:i] length] + 1;
       tempArgv[i] = (char*)malloc(argLen);