From: helge Date: Sun, 6 Mar 2005 17:51:06 +0000 (+0000) Subject: fixed some issues in MacOSX watchdog X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73e92fb51f6b7457ffbb63091977286cb62de910;p=sope fixed some issues in MacOSX watchdog git-svn-id: http://svn.opengroupware.org/SOPE/trunk@624 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 5a520088..57fac19a 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,8 @@ +2005-03-06 Helge Hess + + * 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 * added an MacOSX specific WOWatchDogApplicationMain, this fixes some diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index 44ddb30e..25a3a660 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -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 diff --git a/sope-appserver/NGObjWeb/WOWatchDogApplicationMainOSX.m b/sope-appserver/NGObjWeb/WOWatchDogApplicationMainOSX.m index 6f265213..13118994 100644 --- a/sope-appserver/NGObjWeb/WOWatchDogApplicationMainOSX.m +++ b/sope-appserver/NGObjWeb/WOWatchDogApplicationMainOSX.m @@ -34,6 +34,7 @@ #include #include #include +#include #include 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 {