forked from github/server
prove that logging is broken (new test segfaults)
This commit is contained in:
parent
1fa1693119
commit
41277ed5ee
|
@ -35,18 +35,34 @@ typedef struct logger {
|
||||||
void(*log)(void *data, int level, const char *module, const char *format, va_list args);
|
void(*log)(void *data, int level, const char *module, const char *format, va_list args);
|
||||||
void *data;
|
void *data;
|
||||||
int flags;
|
int flags;
|
||||||
|
int id;
|
||||||
struct logger *next;
|
struct logger *next;
|
||||||
} logger;
|
} logger;
|
||||||
|
|
||||||
static logger *loggers;
|
static logger *loggers;
|
||||||
|
static int log_id;
|
||||||
|
|
||||||
void log_create(int flags, void *data, log_fun call) {
|
int log_create(int flags, void *data, log_fun call) {
|
||||||
logger *lgr = malloc(sizeof(logger));
|
logger *lgr = malloc(sizeof(logger));
|
||||||
lgr->log = call;
|
lgr->log = call;
|
||||||
lgr->flags = flags;
|
lgr->flags = flags;
|
||||||
lgr->data = data;
|
lgr->data = data;
|
||||||
lgr->next = loggers;
|
lgr->next = loggers;
|
||||||
loggers = lgr;
|
loggers = lgr;
|
||||||
|
return lgr->id = ++log_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_destroy(int id) {
|
||||||
|
logger ** lp = &loggers;
|
||||||
|
while (*lp) {
|
||||||
|
logger *lg = *lp;
|
||||||
|
if (lg->id==id) {
|
||||||
|
*lp = lg->next;
|
||||||
|
free(lg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
lp = &lg->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAXLENGTH 4096 /* because I am lazy, CP437 output is limited to this many chars */
|
#define MAXLENGTH 4096 /* because I am lazy, CP437 output is limited to this many chars */
|
||||||
|
@ -138,7 +154,6 @@ static void _log_write(FILE * stream, int codepage, const char *format, va_list
|
||||||
if (codepage) {
|
if (codepage) {
|
||||||
char buffer[MAXLENGTH];
|
char buffer[MAXLENGTH];
|
||||||
char converted[MAXLENGTH];
|
char converted[MAXLENGTH];
|
||||||
|
|
||||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||||
if (cp_convert(buffer, converted, MAXLENGTH, codepage) == 0) {
|
if (cp_convert(buffer, converted, MAXLENGTH, codepage) == 0) {
|
||||||
fputs(converted, stream);
|
fputs(converted, stream);
|
||||||
|
@ -177,6 +192,7 @@ static void log_write(int flags, const char *module, const char *format, va_list
|
||||||
int level = flags & LOG_LEVELS;
|
int level = flags & LOG_LEVELS;
|
||||||
if (lg->flags & level) {
|
if (lg->flags & level) {
|
||||||
int dupe = 0;
|
int dupe = 0;
|
||||||
|
|
||||||
if (lg->flags & LOG_BRIEF) {
|
if (lg->flags & LOG_BRIEF) {
|
||||||
dupe = check_dupe(format, level);
|
dupe = check_dupe(format, level);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,8 @@ extern "C" {
|
||||||
|
|
||||||
typedef void(*log_fun)(void *data, int level, const char *module, const char *format, va_list args);
|
typedef void(*log_fun)(void *data, int level, const char *module, const char *format, va_list args);
|
||||||
|
|
||||||
void log_create(int flags, void *data, log_fun call);
|
int log_create(int flags, void *data, log_fun call);
|
||||||
|
void log_destroy(int id);
|
||||||
void log_to_file(int flags, FILE *out);
|
void log_to_file(int flags, FILE *out);
|
||||||
|
|
||||||
extern int log_flags;
|
extern int log_flags;
|
||||||
|
|
Loading…
Reference in New Issue