Bug 452174 - Make updater binary parent-pid command line arg optional. r=bsmedberg
authorRobert Strong <robert.bugzilla@gmail.com>
Tue, 26 Aug 2008 14:06:45 -0700
changeset 18428 43e89bd626d27eb3574f5a3af9239b2fc24e7c97
parent 18427 b6fde4f6d35cffb593b4ef2fc6df390f70166a66
child 18429 12616044efd376d65d505b25c096c86007a9a13c
child 18461 c397279747fa966ebedd9806d691c7aeede5cbe3
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs452174
milestone1.9.1a2pre
Bug 452174 - Make updater binary parent-pid command line arg optional. r=bsmedberg
toolkit/mozapps/update/src/updater/updater.cpp
--- a/toolkit/mozapps/update/src/updater/updater.cpp
+++ b/toolkit/mozapps/update/src/updater/updater.cpp
@@ -1180,41 +1180,43 @@ int NS_main(int argc, NS_tchar **argv)
 
   // The updater command line consists of the directory path containing the
   // updater.mar file to process followed by the PID of the calling process.
   // The updater will wait on the parent process to exit if the PID is non-
   // zero.  This is leveraged on platforms such as Windows where it is
   // necessary for the parent process to exit before its executable image may
   // be altered.
 
-  if (argc < 3) {
-    fprintf(stderr, "Usage: updater <dir-path> <parent-pid> [working-dir callback args...]\n");
+  if (argc < 2) {
+    fprintf(stderr, "Usage: updater <dir-path> [parent-pid [working-dir callback args...]]\n");
     return 1;
   }
 
-  int pid = NS_tatoi(argv[2]);
-  if (pid) {
+  if (argc > 2 ) {
+    int pid = NS_tatoi(argv[2]);
+    if (pid) {
 #ifdef XP_WIN
-    HANDLE parent = OpenProcess(SYNCHRONIZE, FALSE, (DWORD) pid);
-    // May return NULL if the parent process has already gone away.
-    // Otherwise, wait for the parent process to exit before starting the
-    // update.
-    if (parent) {
-      DWORD result = WaitForSingleObject(parent, 5000);
-      CloseHandle(parent);
-      if (result != WAIT_OBJECT_0)
-        return 1;
-      // The process may be signaled before it releases the executable image.
-      // This is a terrible hack, but it'll have to do for now :-(
-      Sleep(50);
+      HANDLE parent = OpenProcess(SYNCHRONIZE, FALSE, (DWORD) pid);
+      // May return NULL if the parent process has already gone away.
+      // Otherwise, wait for the parent process to exit before starting the
+      // update.
+      if (parent) {
+        DWORD result = WaitForSingleObject(parent, 5000);
+        CloseHandle(parent);
+        if (result != WAIT_OBJECT_0)
+          return 1;
+        // The process may be signaled before it releases the executable image.
+        // This is a terrible hack, but it'll have to do for now :-(
+        Sleep(50);
+      }
+#else
+      int status;
+      waitpid(pid, &status, 0);
+#endif
     }
-#else
-    int status;
-    waitpid(pid, &status, 0);
-#endif
   }
 
 #ifdef XP_WIN
   // Launch a second instance of the updater with the runas verb on Windows
   // when write access is denied to the installation directory.
 
   NS_tchar updateLockFilePath[MAXPATHLEN];
   NS_tsnprintf(updateLockFilePath, MAXPATHLEN,