Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions procServ.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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<std::string> argvStore;
for(char** av = childArgv; *av; av++) {
if((*av)[0]=='$') { // expand command from environment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation for this needs to point out that it only accepts environment variables as a complete argument. As implemented an argument can't have a variable somewhere in the middle.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is enough interest, I would implement shell style unquoting and argument splitting.

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<char*> argvBuf(argvStore.size()+1); // include trailing NULL
for(size_t i=0, N=argvStore.size(); i<N; i++) {
argvBuf[i] = argvStore[i].data();
}
childArgv = argvBuf.data();

if (!stampFormat) {
char *tmp = (char*) calloc(strlen(timeFormat)+4, 1);
if (tmp) {
Expand Down
36 changes: 36 additions & 0 deletions procServ@.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[Unit]
Description="Managed process %i"

[Service]
Type=simple

ExecStart=/usr/bin/procServ \
--foreground --logfile - --name %N \
--info-file %t/%N/info \
--port 0 \
--port unix:%t/%N/control \
$PROCCMD

StandardOutput=syslog
StandardError=inherit
SyslogIdentifier=%N

# Create %t/%N
RuntimeDirectory=%N

# What, where, who
#Environment="PROCCMD=./st.cmd"
#WorkingDirectory=/
#User=softioc
#Group=softioc

# Permit RT priority for non-root
#AmbientCapabilities=cap_ipc_lock
#LimitRTPRIO=50
#LimitMEMLOCK=256M

[Install]
# --system
WantedBy=multi-user.target
# --user
#WantedBy=default.target