Bug 650237 - Allow applications to use a symbolic link to the xulrunner-stub instead of a copy. r=bsmedberg
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 01 Jul 2011 10:42:28 +0200
changeset 72704 2fda596a9a3f48df6f31c65ab3c7f4e7674edb96
parent 72703 7308d42e070d714e5bbf441f76399ae319bc7aee
child 72705 cbb285709139e8a9144d755a4130ece9e313d491
push id159
push usereakhgari@mozilla.com
push dateTue, 16 Aug 2011 17:53:11 +0000
treeherdermozilla-beta@8786e3e49240 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs650237
milestone7.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 650237 - Allow applications to use a symbolic link to the xulrunner-stub instead of a copy. r=bsmedberg
xulrunner/stub/nsXULStub.cpp
--- a/xulrunner/stub/nsXULStub.cpp
+++ b/xulrunner/stub/nsXULStub.cpp
@@ -258,45 +258,56 @@ main(int argc, char **argv)
   // multiple applications, we will try a series of techniques:
   //
   // 1) use realpath() on argv[0], which works unless we're loaded from the
   //    PATH
   // 2) manually walk through the PATH and look for ourself
   // 3) give up
 
   struct stat fileStat;
-
-  if (!realpath(argv[0], iniPath) || stat(iniPath, &fileStat)) {
+  strncpy(tmpPath, argv[0], sizeof(tmpPath));
+  lastSlash = strrchr(tmpPath, '/');
+  if (lastSlash) {
+    *lastSlash = 0;
+    realpath(tmpPath, iniPath);
+  } else {
     const char *path = getenv("PATH");
     if (!path)
       return 1;
 
     char *pathdup = strdup(path);
     if (!pathdup)
       return 1;
 
     PRBool found = PR_FALSE;
     char *token = strtok(pathdup, ":");
     while (token) {
       sprintf(tmpPath, "%s/%s", token, argv[0]);
-      if (realpath(tmpPath, iniPath) && stat(iniPath, &fileStat) == 0) {
+      if (stat(tmpPath, &fileStat) == 0) {
         found = PR_TRUE;
+        lastSlash = strrchr(tmpPath, '/');
+        *lastSlash = 0;
+        realpath(tmpPath, iniPath);
         break;
       }
       token = strtok(NULL, ":");
     }
     free (pathdup);
     if (!found)
       return 1;
   }
+  lastSlash = iniPath + strlen(iniPath);
+  *lastSlash = '/';
 #endif
 
+#ifndef XP_UNIX
   lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR);
   if (!lastSlash)
     return 1;
+#endif
 
   *(++lastSlash) = '\0';
 
   // On Linux/Win, look for XULRunner in appdir/xulrunner
 
   snprintf(greDir, sizeof(greDir),
            "%sxulrunner" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL,
            iniPath);