From 6af5d39494a10aff7807069ff79800d0934192dd Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Thu, 4 Dec 2025 14:20:28 -0800 Subject: [PATCH 1/3] localize some globals --- procServ.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/procServ.cc b/procServ.cc index c8d04a2..98c663c 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,7 +454,7 @@ 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; From 8ba48b73ddf6365e80af47b03d7b4f3661897d01 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Thu, 4 Dec 2025 14:36:39 -0800 Subject: [PATCH 2/3] read commands from environment --- procServ.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/procServ.cc b/procServ.cc index 98c663c..0b3796a 100644 --- a/procServ.cc +++ b/procServ.cc @@ -460,6 +460,28 @@ int main(int argc,char * argv[]) 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 Date: Thu, 4 Dec 2025 14:39:19 -0800 Subject: [PATCH 3/3] systemd unit using command from environment --- procServ.cc | 1 - procServ@.service | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 procServ@.service diff --git a/procServ.cc b/procServ.cc index 0b3796a..4a23e0f 100644 --- a/procServ.cc +++ b/procServ.cc @@ -477,7 +477,6 @@ int main(int argc,char * argv[]) } std::vector argvBuf(argvStore.size()+1); // include trailing NULL for(size_t i=0, N=argvStore.size(); i