log.c revision 2cfe9983ce7a6280636ee12beccc2e865111967b
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "ioloop.h"
#include "istream.h"
#include "fd-set-nonblock.h"
#include "fd-close-on-exec.h"
#include "log.h"
#include <unistd.h>
struct log_io {
int refcount;
unsigned int log_counter;
unsigned int max_lines_per_sec;
char *prefix;
char next_log_type;
unsigned int throttle_msg:1;
unsigned int destroying:1;
};
static unsigned int throttle_count;
static void log_throttle_timeout(void *context);
{
const char *line;
log_io->log_counter = 0;
}
return FALSE;
}
return TRUE;
}
{
if (!log_io->throttle_msg) {
FALSE);
}
return;
}
}
{
}
{
return;
timeout_remove(&to);
}
{
const char *prefix;
/* our internal protocol.
\001 + log_type */
line += 2;
} else {
}
}
t_push();
switch (log_io->next_log_type) {
case 'I':
break;
case 'W':
break;
default:
break;
}
t_pop();
if (!continues)
!log_io->destroying) {
return 0;
}
return 1;
}
{
const unsigned char *data;
const char *line;
int ret;
if (!log_write_pending(log_io))
return 0;
if (ret < 0) {
if (ret == -1) {
/* closed */
return -1;
}
/* buffer full. treat it as one line */
return 0;
}
if (!log_write_pending(log_io))
return 0;
return 0;
}
{
int fd[2];
i_error("pipe() failed: %m");
return -1;
}
return fd[1];
}
{
}
{
}
{
const unsigned char *data;
if (log_io->destroying)
return;
/* if there was something in buffer, write it */
(void)log_write_pending(log_io);
/* write partial data as well */
if (size != 0) {
t_push();
t_pop();
}
else
else
}
{
return;
}
{
unsigned int left = throttle_count;
if (log_write_pending(log))
if (--left == 0)
break;
}
}
}
void log_init(void)
{
throttle_count = 0;
}
void log_deinit(void)
{
/* do one final log read in case there's still something
waiting */
}
timeout_remove(&to);
}