(logerror): Ensure that logerror() only writes to the log file after log_init()

has been called
This commit is contained in:
Ron Koenderink 2007-03-03 15:23:32 +00:00
parent 8babf97d81
commit 3afb3925a2

View file

@ -89,13 +89,15 @@ logerror(char *format, ...)
p = strchr(msg, '\n'); p = strchr(msg, '\n');
p[1] = 0; p[1] = 0;
fputs(msg, stderr); fputs(msg, stderr);
time(&now); if (logfile[0] != '\0') {
memcpy(buf, ctime(&now), ctime_len); time(&now);
buf[ctime_len] = ' '; memcpy(buf, ctime(&now), ctime_len);
if ((logf = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0666)) < 0) buf[ctime_len] = ' ';
return; if ((logf = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0666)) < 0)
write(logf, buf, strlen(buf)); return;
close(logf); write(logf, buf, strlen(buf));
close(logf);
}
va_end(list); va_end(list);
} }