diff --git a/procServ.cc b/procServ.cc index c8d04a2..4a23e0f 100644 --- a/procServ.cc +++ b/procServ.cc @@ -59,8 +59,6 @@ RestartMode restartMode = restart; // Child restart mode (restart/norestart/one bool firstRun; // Has process run for purposes of oneshot restart mode char *procservName; // The name of this beast (server) char *childName; // The name of that beast (child) -char *childExec; // Exec to run as child -char **childArgv; // Argv for child process int connectionNo; // Total number of connections char *ignChars = NULL; // Characters to ignore char killChar = 0x18; // Kill command character (default: ^X) @@ -214,6 +212,7 @@ int main(int argc,char * argv[]) const size_t BUFLEN = 512; char buff[BUFLEN]; std::string infofile; + char *childExec = NULL; // Exec to run as child time(&procServStart); // remember start time procservName = argv[0]; @@ -455,12 +454,33 @@ int main(int argc,char * argv[]) command = argv[optind]; if (childName == NULL) childName = command; - childArgv = argv + optind - 1; + char** childArgv = argv + optind - 1; if (childExec == NULL) { childArgv++; childExec = command; } + // reallocate argv[] storage, and expand any unexpanded arguments + std::vector argvStore; + for(char** av = childArgv; *av; av++) { + if((*av)[0]=='$') { // expand command from environment + const char *ev = getenv(&(*av)[1]); + if(!ev) { + fprintf(stderr, "argument references %s which is not set in environment\n", *av); + exit(1); + } + argvStore.push_back(ev); + + } else { + argvStore.push_back(*av); + } + } + std::vector argvBuf(argvStore.size()+1); // include trailing NULL + for(size_t i=0, N=argvStore.size(); i