1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-12-04 14:46:31 -05:00

log: When keeping around log lines, only allocate what we actually use. Allow

compiler printf arg checking.
timing: win32 fix, don't use timeGetTime, fixes access log timestamp

svn path=/icecast/trunk/log/; revision=15610
This commit is contained in:
Karl Heyes 2009-01-08 02:18:11 +00:00
parent 441c2c0988
commit 8acf94cdb5
3 changed files with 16 additions and 19 deletions

View File

@ -360,17 +360,16 @@ void log_shutdown(void)
static int create_log_entry (int log_id, const char *pre, const char *line) static int create_log_entry (int log_id, const char *pre, const char *line)
{ {
int len;
log_entry_t *entry; log_entry_t *entry;
if (loglist[log_id].keep_entries == 0) if (loglist[log_id].keep_entries == 0)
return fprintf (loglist[log_id].logfile, "%s%s\n", pre, line); return fprintf (loglist[log_id].logfile, "%s%s\n", pre, line);
entry = calloc (1, sizeof (log_entry_t)); entry = calloc (1, sizeof (log_entry_t));
entry->line = malloc (LOG_MAXLINELEN); entry->len = strlen (pre) + strlen (line) + 2;
len = snprintf (entry->line, LOG_MAXLINELEN, "%s%s\n", pre, line); entry->line = malloc (entry->len);
entry->len = len; snprintf (entry->line, entry->len, "%s%s\n", pre, line);
loglist [log_id].total += len; loglist [log_id].total += entry->len;
fprintf (loglist[log_id].logfile, "%s", entry->line); fprintf (loglist[log_id].logfile, "%s", entry->line);
*loglist [log_id].log_tail = entry; *loglist [log_id].log_tail = entry;
@ -386,7 +385,7 @@ static int create_log_entry (int log_id, const char *pre, const char *line)
} }
else else
loglist [log_id].entries++; loglist [log_id].entries++;
return len; return entry->len;
} }
@ -458,9 +457,9 @@ void log_write(int log_id, unsigned priority, const char *cat, const char *func,
void log_write_direct(int log_id, const char *fmt, ...) void log_write_direct(int log_id, const char *fmt, ...)
{ {
char line[LOG_MAXLINELEN];
va_list ap; va_list ap;
time_t now; time_t now;
char line[LOG_MAXLINELEN];
if (log_id < 0 || log_id >= LOG_MAXLOGS) return; if (log_id < 0 || log_id >= LOG_MAXLOGS) return;

View File

@ -39,6 +39,6 @@ void log_shutdown(void);
void log_write(int log_id, unsigned priority, const char *cat, const char *func, void log_write(int log_id, unsigned priority, const char *cat, const char *func,
const char *fmt, ...); const char *fmt, ...);
void log_write_direct(int log_id, const char *fmt, ...); void log_write_direct(int log_id, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
#endif /* __LOG_H__ */ #endif /* __LOG_H__ */

View File

@ -27,7 +27,7 @@
#include <sys/select.h> #include <sys/select.h>
#endif #endif
#ifdef __MINGW32__ #ifdef HAVE_SYS_TIMEB_H
#include <sys/timeb.h> #include <sys/timeb.h>
#endif #endif
@ -40,21 +40,19 @@
*/ */
uint64_t timing_get_time(void) uint64_t timing_get_time(void)
{ {
#ifdef _WIN32 #ifdef HAVE_GETTIMEOFDAY
#ifdef __MINGW32__
struct timeb t;
ftime(&t);
return t.time * 1000 + t.millitm;
#else
return timeGetTime();
#endif
#else
struct timeval mtv; struct timeval mtv;
gettimeofday(&mtv, NULL); gettimeofday(&mtv, NULL);
return (uint64_t)(mtv.tv_sec) * 1000 + (uint64_t)(mtv.tv_usec) / 1000; return (uint64_t)(mtv.tv_sec) * 1000 + (uint64_t)(mtv.tv_usec) / 1000;
#elif HAVE_FTIME
struct timeb t;
ftime(&t);
return t.time * 1000 + t.millitm;
#else
#error need time query handler
#endif #endif
} }