mirror of
https://github.com/reactos/ccache.git
synced 2024-12-04 17:56:21 +00:00
Dont' crash when logging is disabled
This commit is contained in:
parent
48f9d72e98
commit
247f619565
6
ccache.h
6
ccache.h
@ -65,9 +65,9 @@ char *hash_result(struct mdfour *md);
|
||||
void hash_result_as_bytes(struct mdfour *md, unsigned char *out);
|
||||
void hash_buffer(struct mdfour *md, const void *s, size_t len);
|
||||
|
||||
void cc_log_no_newline(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
|
||||
void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
|
||||
void cc_log_executed_command(char **argv);
|
||||
int cc_log_no_newline(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
|
||||
int cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
|
||||
int cc_log_executed_command(char **argv);
|
||||
void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
|
||||
|
||||
void copy_fd(int fd_in, int fd_out);
|
||||
|
46
util.c
46
util.c
@ -42,49 +42,67 @@
|
||||
|
||||
static FILE *logfile;
|
||||
|
||||
static void cc_log_va_list(const char *format, va_list ap)
|
||||
static int cc_log_va_list(const char *format, va_list ap)
|
||||
{
|
||||
extern char *cache_logfile;
|
||||
|
||||
if (!cache_logfile) return;
|
||||
if (!cache_logfile) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!logfile) logfile = fopen(cache_logfile, "a");
|
||||
if (!logfile) return;
|
||||
if (!logfile) {
|
||||
logfile = fopen(cache_logfile, "a");
|
||||
if (!logfile) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(logfile, "[%-5d] ", getpid());
|
||||
vfprintf(logfile, format, ap);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Log a message to the CCACHE_LOGFILE location without newline and without
|
||||
* flushing.
|
||||
*/
|
||||
void cc_log_no_newline(const char *format, ...)
|
||||
int cc_log_no_newline(const char *format, ...)
|
||||
{
|
||||
int logged;
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
cc_log_va_list(format, ap);
|
||||
logged = cc_log_va_list(format, ap);
|
||||
va_end(ap);
|
||||
return logged;
|
||||
}
|
||||
|
||||
/*
|
||||
* Log a message to the CCACHE_LOGFILE location adding a newline and flushing.
|
||||
*/
|
||||
void cc_log(const char *format, ...)
|
||||
int cc_log(const char *format, ...)
|
||||
{
|
||||
int logged;
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
cc_log_va_list(format, ap);
|
||||
logged = cc_log_va_list(format, ap);
|
||||
if (logged) {
|
||||
fprintf(logfile, "\n");
|
||||
fflush(logfile);
|
||||
}
|
||||
va_end(ap);
|
||||
fprintf(logfile, "\n");
|
||||
fflush(logfile);
|
||||
return logged;
|
||||
}
|
||||
|
||||
void cc_log_executed_command(char **argv)
|
||||
int cc_log_executed_command(char **argv)
|
||||
{
|
||||
cc_log_no_newline("Executing ");
|
||||
print_command(logfile, argv);
|
||||
fflush(logfile);
|
||||
if (cc_log_no_newline("Executing ")) {
|
||||
print_command(logfile, argv);
|
||||
fflush(logfile);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* something went badly wrong! */
|
||||
|
Loading…
Reference in New Issue
Block a user