Allow specifying negated exit status codes for --exit-with-child
This commit is contained in:
parent
519afe63d1
commit
0d0d42cb31
@ -62,6 +62,8 @@ adhocify -m IN_CREATE --exit-with-child=0 -- /usr/bin/test -f awaited_file
|
||||
```
|
||||
Keep running until the file named "awaited_file" is created in the current directory.
|
||||
|
||||
`--exit-with-child` also supports negation, so e. g. with `--exit-with-child='!0'` adhocify would keep running as long as the child commands exits with 0.
|
||||
|
||||
Other tools
|
||||
===========
|
||||
If adhocify does not suit your needs, take a look at:
|
||||
|
18
adhocify.c
18
adhocify.c
@ -69,6 +69,7 @@ bool forkbombcheck = true;
|
||||
bool daemonize = false;
|
||||
bool exit_with_child = false;
|
||||
int awaited_child_exit_code = -1;
|
||||
bool negate_child_exit_code = false;
|
||||
|
||||
uint32_t mask = 0;
|
||||
char *prog = NULL;
|
||||
@ -529,6 +530,16 @@ void parse_options(int argc, char **argv)
|
||||
exit_with_child = true;
|
||||
if(optarg)
|
||||
{
|
||||
if(*optarg == '!')
|
||||
{
|
||||
negate_child_exit_code = true;
|
||||
++optarg;
|
||||
}
|
||||
if(*optarg == '\0')
|
||||
{
|
||||
logerror("Please specify the exit code\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
awaited_child_exit_code = atoi(optarg);
|
||||
}
|
||||
break;
|
||||
@ -642,7 +653,12 @@ void child_handler(int signum, siginfo_t *info, void *context)
|
||||
adhocify_exit_code = WEXITSTATUS(status);
|
||||
if(awaited_child_exit_code > -1)
|
||||
{
|
||||
if(adhocify_exit_code == awaited_child_exit_code)
|
||||
bool must_exit = adhocify_exit_code == awaited_child_exit_code;
|
||||
if(negate_child_exit_code)
|
||||
{
|
||||
must_exit = !must_exit;
|
||||
}
|
||||
if(must_exit)
|
||||
{
|
||||
logwrite("child exited with specified exit code, exiting too\n");
|
||||
exit(adhocify_exit_code);
|
||||
|
Loading…
Reference in New Issue
Block a user