aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2016-01-26 15:32:44 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2016-01-26 15:33:42 +0900
commit7cf1935749d789e83403b242c6a270fa24f1a730 (patch)
tree84424539c64c4216346ac7b351494021843d6044
parent271c5805cfe5c5bbd063a89d9778bb647ad53416 (diff)
downloadkati-7cf1935749d789e83403b242c6a270fa24f1a730.tar.gz
[C++] Show an error message when exec in RunCommand fails
-rw-r--r--fileutil.cc5
-rw-r--r--log.h6
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) {
diff --git a/log.h b/log.h
index 6507bde..11cf0e5 100644
--- a/log.h
+++ b/log.h
@@ -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)