From 10975c723ed0c5a6764fda3d4f539a36033dcb0d Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 13 Mar 2020 16:26:51 -0400 Subject: exec: Warn if a command dies abnormally --- exec.c | 11 ++++------- exec.h | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/exec.c b/exec.c index ce42f1a..3c791d7 100644 --- a/exec.c +++ b/exec.c @@ -37,7 +37,7 @@ /** Print some debugging info. */ BFS_FORMATTER(2, 3) static void bfs_exec_debug(const struct bfs_exec *execbuf, const char *format, ...) { - if (!(execbuf->flags & BFS_EXEC_DEBUG)) { + if (!(execbuf->cmdline->debug & DEBUG_EXEC)) { return; } @@ -123,6 +123,7 @@ struct bfs_exec *parse_bfs_exec(char **argv, enum bfs_exec_flags flags, const st } execbuf->flags = flags; + execbuf->cmdline = cmdline; execbuf->argv = NULL; execbuf->argc = 0; execbuf->argv_cap = 0; @@ -133,10 +134,6 @@ struct bfs_exec *parse_bfs_exec(char **argv, enum bfs_exec_flags flags, const st execbuf->wd_len = 0; execbuf->ret = 0; - if (cmdline->debug & DEBUG_EXEC) { - execbuf->flags |= BFS_EXEC_DEBUG; - } - size_t i; for (i = 1; ; ++i) { const char *arg = argv[i]; @@ -391,9 +388,9 @@ fail: } } else if (WIFSIGNALED(wstatus)) { int sig = WTERMSIG(wstatus); - bfs_exec_debug(execbuf, "Command '%s' terminated by signal %d\n", execbuf->argv[0], sig); + bfs_warning(execbuf->cmdline, "Command '${ex}%s${rs}' terminated by signal %d\n", execbuf->argv[0], sig); } else { - bfs_exec_debug(execbuf, "Command '%s' terminated abnormally\n", execbuf->argv[0]); + bfs_warning(execbuf->cmdline, "Command '${ex}%s${rs}' terminated abnormally\n", execbuf->argv[0]); } errno = 0; diff --git a/exec.h b/exec.h index 78cdbd2..ab3f59a 100644 --- a/exec.h +++ b/exec.h @@ -36,8 +36,6 @@ enum bfs_exec_flags { BFS_EXEC_CHDIR = 1 << 1, /** Pass multiple files at once to the command (-exec ... {} +). */ BFS_EXEC_MULTI = 1 << 2, - /** Print debugging information (-D exec). */ - BFS_EXEC_DEBUG = 1 << 3, }; /** @@ -47,6 +45,8 @@ struct bfs_exec { /** Flags for this exec buffer. */ enum bfs_exec_flags flags; + /** The overall command line. */ + const struct cmdline *cmdline; /** Command line template. */ char **tmpl_argv; /** Command line template size. */ -- cgit v1.2.3