]> err.no Git - sope/commitdiff
fixed some issues in MacOSX watchdog
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Sun, 6 Mar 2005 17:51:06 +0000 (17:51 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Sun, 6 Mar 2005 17:51:06 +0000 (17:51 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@624 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-appserver/NGObjWeb/ChangeLog
sope-appserver/NGObjWeb/Version
sope-appserver/NGObjWeb/WOWatchDogApplicationMainOSX.m

index 5a5200880b6214cb571c12d49940a0b2f7372ccb..57fac19a249bc446e600fa16133072134e3d2d89 100644 (file)
@@ -1,3 +1,8 @@
+2005-03-06  Helge Hess  <helge.hess@opengroupware.org>
+       
+       * WOWatchDogApplicationMainOSX.m: fixed some minor issues, still need
+         a fix to allow for starts without a full path (v4.5.128)
+
 2005-03-06  Mont Rothstein  <mont_rothstein@yahoo.com>
 
        * added an MacOSX specific WOWatchDogApplicationMain, this fixes some
index 44ddb30e56388955c87a7bb9b7408ae7a90392cb..25a3a660cb6daab215b41213901b2c2e861c1900 100644 (file)
@@ -1,6 +1,6 @@
 # version file
 
-SUBMINOR_VERSION:=127
+SUBMINOR_VERSION:=128
 
 # v4.5.122 requires libNGExtensions v4.5.153
 # v4.5.91  requires libNGExtensions v4.5.134
index 6f2652137815bc305318374c8e7de7b7c88f3d02..1311899496e3edb1a0d4b9e934eff1e75125b29e 100644 (file)
@@ -34,6 +34,7 @@
 #include <sys/wait.h>
 #include <sys/types.h>
 #include <sys/unistd.h>
+#include <sys/param.h>
 #include <time.h>
 
 static pid_t    child = -1;
@@ -247,6 +248,20 @@ int WOWatchDogApplicationMain
       return WOApplicationMain(appName, argc, argv);
   }
   
+  /* ensure we can actually do execve() */
+  if (argv[0][0] != '/') {
+    /*
+      Note: we cannot use getcwd to make the path absolute, the
+            binary could have been found anywhere in $PATH
+    */
+    fprintf(stderr,
+           "program called with a non-absolute path, can't use execve(): "
+           "'%s'\n"
+           "  (start using `which %s`)\n",
+           argv[0], argv[0]);
+    exit(123); // TODO: better error code
+  }
+  
   /* watch dog */
   {
     int      failCount = 0;
@@ -320,14 +335,11 @@ int WOWatchDogApplicationMain
            Set the path (0) argument and set -WOUseWatchDog to NO so this
            process won't execute a parent
          */
-          childArgv = malloc(argc + 3);
-          childArgv[0] = malloc(strlen(argv[0]) + 1);
-          strcpy(childArgv[0], argv[0]);
-          childArgv[1] = (char *)malloc(strlen("-WOUseWatchDog") + 1);
-          strcpy(childArgv[1], "-WOUseWatchDog");
-          childArgv[2] = (char *)malloc(strlen("NO") + 1);
-          strcpy(childArgv[2], "NO");
-
+          childArgv = calloc(argc + 5, sizeof(char *));
+          childArgv[0] = strdup(argv[0]);
+          childArgv[1] = strdup("-WOUseWatchDog");
+          childArgv[2] = strdup("NO");
+         
           /*
            Copy any remaining arguments skipping a -WOUseWatchDog if it exists
          */
@@ -348,21 +360,35 @@ int WOWatchDogApplicationMain
              }
             }
            
-            childArgv[childIndex] = (char *)malloc(strlen(argv[index]) + 1);
-            strcpy(childArgv[childIndex], argv[index]);
+            childArgv[childIndex] = strdup(argv[index]);
             childIndex++;
           }
           
          /* Mark the end of the array of arguments */
           childArgv[childIndex] = NULL; 
-
+         
           /* transform the child into a new process */
-          execve(argv[0], childArgv, environ);
-
-          /* shouldn't even get here ! */
-          fprintf(stderr,
-                  "exeve failed in child %i failed: %s\n",
-                  getpid(), strerror(errno));
+         {
+           const unsigned char *p;
+           
+           p = argv[0];
+           if (p[0] != '/') {
+             /*
+               Note: we cannot use getcwd to make the path absolute, the
+                     binary could have been found anywhere in $PATH
+             */
+             fprintf(stderr,
+                     "program called with a non-absolute path: '%s'\n", p);
+             exit(123); // TODO: better error code
+           }
+           
+           execve(p, childArgv, environ);
+         
+           /* shouldn't even get here ! */
+           fprintf(stderr,
+                   "execve of '%s' failed in child %i failed: %s\n",
+                   p, getpid(), strerror(errno));
+         }
           abort();
         }
         else {