From: Bruce Hill <bhill@slac.stanford.edu>
Date: Tue, 8 Sep 2020 14:45:17 -0700
Subject: Modify restartMode oneshot feature to run once AFTER selecting
 oneshot restartMode.

If IOC process is not running and the developer tries to change
restartMode, it kills procServ when the developer toggles through
oneshot mode.

This commit sets firstRun true as restartMode is toggled. Thus,
developers can toggle through oneshot mode w/o killing procServ and the
IOC will run at least once before oneshot mode will kill procServ.

Origin: upstream, https://github.com/ralphlange/procServ/commit/66137916c0d88dabc21d923f10468bcb1503e7ce
---
 clientFactory.cc | 5 ++++-
 procServ.cc      | 2 +-
 procServ.h       | 1 +
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clientFactory.cc b/clientFactory.cc
index c79f865..9a926ca 100755
--- a/clientFactory.cc
+++ b/clientFactory.cc
@@ -222,7 +222,10 @@ void clientItem::processInput(const char *buf, int len)
             }
             if (toggleRestartChar && buf[i] == toggleRestartChar) {
                 if (restartMode == restart) restartMode = norestart;
-                else if (restartMode == norestart) restartMode = oneshot;
+                else if (restartMode == norestart) {
+                    restartMode = oneshot;
+                    firstRun    = true;	// Allow process to run once AFTER selecting oneshot
+                }
                 else restartMode = restart;
                 char msg[128] = NL;
                 PRINTF ("Got a toggleAutoRestart command\n");
diff --git a/procServ.cc b/procServ.cc
index c050cb9..0902c9e 100755
--- a/procServ.cc
+++ b/procServ.cc
@@ -55,6 +55,7 @@ bool   quiet = false;            // Suppress info output (server)
 bool   setCoreSize = false;      // Set core size for child
 bool   singleEndpointStyle = true;  // Compatibility style: first non-option is endpoint
 RestartMode restartMode = restart;  // Child restart mode (restart/norestart/oneshot)
+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
@@ -212,7 +213,6 @@ int main(int argc,char * argv[])
     const size_t BUFLEN = 512;
     char buff[BUFLEN];
     std::string infofile;
-    bool firstRun;
 
     time(&procServStart);             // remember start time
     procservName = argv[0];
diff --git a/procServ.h b/procServ.h
index 8191c18..29e15c4 100755
--- a/procServ.h
+++ b/procServ.h
@@ -40,6 +40,7 @@ extern bool   waitForManualStart;
 extern volatile bool shutdownServer;
 extern bool   setCoreSize;
 extern RestartMode restartMode;
+extern bool   firstRun;
 extern char   *procservName;
 extern char   *childName;
 extern char   *ignChars;
