#endif
hostname[sizeof(hostname)-1] = 0;
if (asprintf(&ret, "%s.%u", hostname, (unsigned)getpid()) == -1) {
- fatal("could not allocate tmp_string");
+ fatal("Could not allocate tmp_string\n");
}
}
static void check_cache_dir(void)
{
if (!cache_dir) {
- fatal("Unable to determine home directory");
+ fatal("Unable to determine home directory\n");
}
}
void hash_buffer(struct mdfour *md, const char *s, int len);
void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
-void fatal(const char *msg);
+void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
void copy_fd(int fd_in, int fd_out);
int copy_file(const char *src, const char *dest);
int status;
pid = fork();
- if (pid == -1) fatal("Failed to fork");
+ if (pid == -1) fatal("Failed to fork\n");
if (pid == 0) {
int fd;
}
if (waitpid(pid, &status, 0) != pid) {
- fatal("waitpid failed");
+ fatal("waitpid failed\n");
}
if (WEXITSTATUS(status) == 0 && WIFSIGNALED(status)) {
fd = open(fname, O_RDONLY|O_BINARY);
if (fd == -1) {
- cc_log("Failed to open %s\n", fname);
- fatal("hash_file");
+ fatal("Failed to open %s\n", fname);
}
while ((n = read(fd, buf, sizeof(buf))) > 0) {
for (i=0;i<STATS_END;i++) {
len += snprintf(buf+len, sizeof(buf)-(len+1), "%u ", counters[i]);
- if (len >= (int)sizeof(buf)-1) fatal("stats too long?!");
+ if (len >= (int)sizeof(buf)-1) fatal("stats too long?!\n");
}
len += snprintf(buf+len, sizeof(buf)-(len+1), "\n");
- if (len >= (int)sizeof(buf)-1) fatal("stats too long?!");
+ if (len >= (int)sizeof(buf)-1) fatal("stats too long?!\n");
lseek(fd, 0, SEEK_SET);
- if (write(fd, buf, len) == -1) fatal("could not write stats");
+ if (write(fd, buf, len) == -1) fatal("Could not write stats\n");
}
}
/* something went badly wrong! */
-void fatal(const char *msg)
+void fatal(const char *format, ...)
{
- cc_log("FATAL: %s\n", msg);
+ va_list ap;
+ extern char *cache_logfile;
+
+ if (!cache_logfile) return;
+
+ if (!logfile) logfile = fopen(cache_logfile, "a");
+ if (!logfile) return;
+
+ va_start(ap, format);
+
+ fprintf(logfile, "FATAL: ");
+ vfprintf(logfile, format, ap);
+ fflush(logfile);
+
+ fprintf(stderr, "ccache: FATAL: ");
+ vfprintf(stderr, format, ap);
+
+ va_end(ap);
exit(1);
}
while ((n = read(fd_in, buf, sizeof(buf))) > 0) {
if (write(fd_out, buf, n) != n) {
- fatal("Failed to copy fd");
+ fatal("Failed to copy fd\n");
}
}
}
gz_in = gzdopen(dup(fd_in), "rb");
if (!gz_in) {
- fatal("Failed to copy fd");
+ fatal("Failed to copy fd\n");
}
while ((n = gzread(gz_in, buf, sizeof(buf))) > 0) {
if (write(fd_out, buf, n) != n) {
- fatal("Failed to copy fd");
+ fatal("Failed to copy fd\n");
}
}
}
*ptr = NULL;
va_start(ap, format);
if (vasprintf(ptr, format, ap) == -1) {
- fatal("out of memory in x_asprintf");
+ fatal("Out of memory in x_asprintf\n");
}
va_end(ap);
- if (!*ptr) fatal("out of memory in x_asprintf");
+ if (!*ptr) fatal("Out of memory in x_asprintf\n");
}
/*
char *ret;
ret = strdup(s);
if (!ret) {
- fatal("out of memory in strdup\n");
+ fatal("Out of memory in strdup\n");
}
return ret;
}
void *ret;
ret = malloc(size);
if (!ret) {
- fatal("out of memory in malloc\n");
+ fatal("Out of memory in malloc\n");
}
return ret;
}
if (!ptr) return x_malloc(size);
p2 = realloc(ptr, size);
if (!p2) {
- fatal("out of memory in x_realloc");
+ fatal("Out of memory in x_realloc\n");
}
return p2;
}