exit adhocify if command is not found irrespective of -e

This commit is contained in:
Albert S. 2020-08-20 13:20:20 +02:00
parent 2e77170115
commit 875c176cc1

View File

@ -280,7 +280,8 @@ bool run_prog(const char *eventfile, uint32_t eventmask)
execvp(prog, script_arguments); execvp(prog, script_arguments);
logerror("Exec of %s failed: %s\n", prog, strerror(errno)); logerror("Exec of %s failed: %s\n", prog, strerror(errno));
return false; int exitcode = (errno == ENOENT) ? 127 : EXIT_FAILURE;
exit(exitcode);
} }
if(pid == -1) if(pid == -1)
{ {
@ -337,7 +338,6 @@ void check_forkbomb(const char *path_logfile, const char *path_prog)
{ {
if(lkp->isdir) if(lkp->isdir)
{ {
char *dir_lkpPath = lkp->path; char *dir_lkpPath = lkp->path;
if( STREQ(dir_lkpPath, dir_log) || STREQ(dir_lkpPath, dir_prog) ) if( STREQ(dir_lkpPath, dir_log) || STREQ(dir_lkpPath, dir_prog) )
{ {
@ -642,36 +642,37 @@ void child_handler(int signum, siginfo_t *info, void *context)
logerror("waitpid failed when handling child exit\n"); logerror("waitpid failed when handling child exit\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if(exit_with_child)
int adhocify_exit_code = 0;
if(WIFEXITED(status))
{ {
int adhocify_exit_code = 0; adhocify_exit_code = WEXITSTATUS(status);
if(WIFEXITED(status)) if(adhocify_exit_code == 127)
{ {
adhocify_exit_code = WEXITSTATUS(status); logwrite("command not found, exiting\n");
if(awaited_child_exit_code > -1) exit(adhocify_exit_code);
}
if(exit_with_child && awaited_child_exit_code > -1)
{
bool must_exit = adhocify_exit_code == awaited_child_exit_code;
if(negate_child_exit_code)
{ {
bool must_exit = adhocify_exit_code == awaited_child_exit_code; must_exit = !must_exit;
if(negate_child_exit_code) }
{ if(must_exit)
must_exit = !must_exit; {
} logwrite("child exited with specified exit code, exiting too\n");
if(must_exit) exit(adhocify_exit_code);
{
logwrite("child exited with specified exit code, exiting too\n");
exit(adhocify_exit_code);
}
return; //not the exit code we wanted, keep running
} }
} }
if(WIFSIGNALED(status)) }
{ if(exit_with_child && WIFSIGNALED(status))
adhocify_exit_code = 128 + WTERMSIG(status); //copy bash's behaviour {
} adhocify_exit_code = 128 + WTERMSIG(status); //copy bash's behaviour
//TODO: coredump?
exit(adhocify_exit_code); exit(adhocify_exit_code);
} }
} }
void set_signals() void set_signals()
{ {
struct sigaction action; struct sigaction action;