if (!initialize(path_prefix) && errno == ENOENT) {
auto dir = Util::dir_name(path);
if (!Util::create_dir(dir)) {
- FATAL("Failed to create directory {}: {}", dir, strerror(errno));
+ fatal("Failed to create directory {}: {}", dir, strerror(errno));
}
initialize(path_prefix);
}
if (!fd) {
- FATAL("Failed to create temporary file for {}: {}", path, strerror(errno));
+ fatal("Failed to create temporary file for {}: {}", path, strerror(errno));
}
set_cloexec_flag(*fd);
}
}
#endif
- FATAL("Could not determine home directory from $HOME or getpwuid(3)");
+ fatal("Could not determine home directory from $HOME or getpwuid(3)");
}
const char*
for (const auto& word : Util::split_into_strings(prefix_command, " ")) {
std::string path = find_executable(ctx, word, MYNAME);
if (path.empty()) {
- FATAL("{}: {}", word, strerror(errno));
+ fatal("{}: {}", word, strerror(errno));
}
prefix.push_back(path);
std::string compiler = find_executable(ctx, base, MYNAME);
if (compiler.empty()) {
- FATAL("Could not find compiler \"{}\" in PATH", base);
+ fatal("Could not find compiler \"{}\" in PATH", base);
}
if (compiler == argv[0]) {
- FATAL("Recursive invocation (the name of the ccache binary must be \"{}\")",
+ fatal("Recursive invocation (the name of the ccache binary must be \"{}\")",
MYNAME);
}
ctx.orig_args[0] = compiler;
MTR_END("config", "conf_read_secondary");
if (config.cache_dir().empty()) {
- FATAL("configuration setting \"cache_dir\" must not be the empty string");
+ fatal("configuration setting \"cache_dir\" must not be the empty string");
}
if ((p = getenv("CCACHE_DIR"))) {
config.set_cache_dir(p);
}
if (config.cache_dir().empty()) {
- FATAL("CCACHE_DIR must not be the empty string");
+ fatal("CCACHE_DIR must not be the empty string");
}
config.set_primary_config_path(
cc_log_argv("Executing ", execv_argv.data());
ctx.reset(); // Dump debug logs last thing before executing.
execv(execv_argv[0], const_cast<char* const*>(execv_argv.data()));
- FATAL("execv of {} failed: {}", execv_argv[0], strerror(errno));
+ fatal("execv of {} failed: {}", execv_argv[0], strerror(errno));
}
}
#include "third_party/nonstd/optional.hpp"
#include <stdexcept>
-
-// Something went badly wrong! Print a message to stderr and exit with non-zero
-// exit code.
-#define FATAL(...) \
- do { \
- throw FatalError(fmt::format(__VA_ARGS__)); \
- } while (false)
+#include <utility>
// Don't throw or catch ErrorBase directly, use a subclass.
class ErrorBase : public std::runtime_error
{
return m_stat;
}
+
+// Something went badly wrong! Print a message to stderr and exit with non-zero
+// exit code. `args` are forwarded to `fmt::format`.
+template<typename... T>
+[[noreturn]] inline void
+fatal(T&&... args)
+{
+ throw FatalError(fmt::format(std::forward<T>(args)...));
+}
}
if (*pid == -1) {
- FATAL("Failed to fork: {}", strerror(errno));
+ fatal("Failed to fork: {}", strerror(errno));
}
if (*pid == 0) {
int status;
if (waitpid(*pid, &status, 0) != *pid) {
- FATAL("waitpid failed: {}", strerror(errno));
+ fatal("waitpid failed: {}", strerror(errno));
}
{
#else
int pipefd[2];
if (pipe(pipefd) == -1) {
- FATAL("pipe failed: {}", strerror(errno));
+ fatal("pipe failed: {}", strerror(errno));
}
pid_t pid = fork();
if (pid == -1) {
- FATAL("fork failed: {}", strerror(errno));
+ fatal("fork failed: {}", strerror(errno));
}
if (pid == 0) {
static void
warn_log_fail()
{
- // Note: Can't call FATAL() since that would lead to recursion.
+ // Note: Can't call fatal() since that would lead to recursion.
fprintf(stderr,
"ccache: error: Failed to write to %s: %s\n",
logfile_path.c_str(),