diff options
author | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2016-01-26 15:32:44 +0900 |
---|---|---|
committer | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2016-01-26 15:33:42 +0900 |
commit | 7cf1935749d789e83403b242c6a270fa24f1a730 (patch) | |
tree | 84424539c64c4216346ac7b351494021843d6044 | |
parent | 271c5805cfe5c5bbd063a89d9778bb647ad53416 (diff) | |
download | kati-7cf1935749d789e83403b242c6a270fa24f1a730.tar.gz |
[C++] Show an error message when exec in RunCommand fails
-rw-r--r-- | fileutil.cc | 5 | ||||
-rw-r--r-- | log.h | 6 |
2 files changed, 9 insertions, 2 deletions
diff --git a/fileutil.cc b/fileutil.cc index abfad9d..42e81a2 100644 --- a/fileutil.cc +++ b/fileutil.cc @@ -20,6 +20,7 @@ #include <fcntl.h> #include <glob.h> #include <limits.h> +#include <signal.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/wait.h> @@ -109,8 +110,10 @@ int RunCommand(const string& shell, const string& cmd, shell.c_str(), "-c", cmd.c_str(), NULL }; execvp(argv[0], const_cast<char**>(argv)); + PLOG("execvp for %s failed", argv[0]); + kill(getppid(), SIGTERM); + _exit(1); } - abort(); } void GetExecutablePath(string* path) { @@ -44,9 +44,13 @@ extern string* g_last_error; fprintf(stderr, "*kati*: %s\n", StringPrintf(args).c_str()); \ } while(0) -#define PERROR(...) do { \ +#define PLOG(...) do { \ fprintf(stderr, "%s: %s\n", StringPrintf(__VA_ARGS__).c_str(), \ strerror(errno)); \ + } while (0) + +#define PERROR(...) do { \ + PLOG(__VA_ARGS__); \ exit(1); \ } while (0) |