summaryrefslogtreecommitdiff
path: root/accel-pptpd/logs
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-09-27 13:27:12 +0400
committerKozlov Dmitry <dima@server>2010-09-27 13:27:12 +0400
commit59d9616d73973c529b08578f3596acaa081cd8bf (patch)
tree947fd1ab82c41beb57bba81e4e51ee5a4951bc6f /accel-pptpd/logs
parentf122327288ae4429bb88a0fefdcef0bf80f54023 (diff)
downloadaccel-ppp-59d9616d73973c529b08578f3596acaa081cd8bf.tar.gz
accel-ppp-59d9616d73973c529b08578f3596acaa081cd8bf.zip
bug fixes
Diffstat (limited to 'accel-pptpd/logs')
-rw-r--r--accel-pptpd/logs/log_file.c24
-rw-r--r--accel-pptpd/logs/log_pgsql.c30
2 files changed, 49 insertions, 5 deletions
diff --git a/accel-pptpd/logs/log_file.c b/accel-pptpd/logs/log_file.c
index 79af4c68..26ec3f90 100644
--- a/accel-pptpd/logs/log_file.c
+++ b/accel-pptpd/logs/log_file.c
@@ -34,8 +34,8 @@ struct log_file_t
struct log_file_pd_t *lpd;
int fd;
+ int new_fd;
off_t offset;
- int cnt;
uint64_t magic;
};
@@ -76,14 +76,13 @@ static uint64_t temp_seq;
static void send_next_chunk();
-#define MAGIC 0x9988776655443322llu
static void log_file_init(struct log_file_t *lf)
{
spinlock_init(&lf->lock);
INIT_LIST_HEAD(&lf->msgs);
lf->fd = -1;
- lf->magic = MAGIC;
+ lf->new_fd = -1;
}
static int log_file_open(struct log_file_t *lf, const char *fname)
@@ -201,11 +200,16 @@ static void send_next_chunk(void)
spin_unlock(&lf_queue_lock);
+ if (lf->new_fd != -1) {
+ close(lf->fd);
+ lf->fd = lf->new_fd;
+ lf->new_fd = -1;
+ }
+
aiocb.aio_fildes = lf->fd;
aiocb.aio_offset = lf->offset;
aiocb.aio_sigevent.sigev_value.sival_ptr = lf;
aiocb.aio_nbytes = dequeue_log(lf);
- __sync_add_and_fetch(&lf->cnt, 1);
if (aio_write(&aiocb))
log_emerg("log_file: aio_write: %s\n", strerror(errno));
@@ -323,6 +327,17 @@ static void per_session_log(struct log_msg_t *msg, struct ppp_t *ppp)
queue_log(&lpd->lf, msg);
}
+static void general_reopen(void)
+{
+ char *fname = conf_get_opt("log", "log-file");
+ int fd = open(fname, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
+ if (fd < 0) {
+ log_emerg("log_file: open '%s': %s\n", fname, strerror(errno));
+ return;
+ }
+ log_file->new_fd = fd;
+}
+
static void free_lpd(struct log_file_pd_t *lpd)
{
struct log_msg_t *msg;
@@ -515,6 +530,7 @@ out_err:
static struct log_target_t general_target =
{
.log = general_log,
+ .reopen = general_reopen,
};
static struct log_target_t per_user_target =
diff --git a/accel-pptpd/logs/log_pgsql.c b/accel-pptpd/logs/log_pgsql.c
index 351fc064..0eed2431 100644
--- a/accel-pptpd/logs/log_pgsql.c
+++ b/accel-pptpd/logs/log_pgsql.c
@@ -19,8 +19,11 @@ static char *conf_query;
static void start_connect(void);
static void start_connect_timer(struct triton_timer_t *);
+static void pgsql_close(struct triton_context_t *ctx);
-static struct triton_context_t pgsql_ctx;
+static struct triton_context_t pgsql_ctx = {
+ .close = pgsql_close,
+};
static struct triton_md_handler_t pgsql_hnd;
static struct triton_timer_t connect_timer = {
.period = 5000,
@@ -34,6 +37,7 @@ static int queue_size;
static int sleeping = 0;
static spinlock_t queue_lock = SPINLOCK_INITIALIZER;
static char *log_buf;
+static int need_close;
static void unpack_msg(struct log_msg_t *msg)
{
@@ -80,6 +84,12 @@ static void write_next_msg(void)
if (list_empty(&msg_queue)) {
sleeping = 1;
spin_unlock(&queue_lock);
+ if (need_close) {
+ triton_md_unregister_handler(&pgsql_hnd);
+ PQfinish(conn);
+ conn = NULL;
+ triton_context_unregister(&pgsql_ctx);
+ }
return;
}
@@ -162,6 +172,11 @@ static void queue_log(struct log_msg_t *msg)
{
int r = 0, f = 0;
spin_lock(&queue_lock);
+ if (!conn) {
+ log_free_msg(msg);
+ spin_unlock(&queue_lock);
+ return;
+ }
if (queue_size < conf_queue_max) {
list_add_tail(&msg->entry, &msg_queue);
++queue_size;
@@ -247,6 +262,19 @@ static void start_connect_timer(struct triton_timer_t *t)
start_connect();
}
+static void pgsql_close(struct triton_context_t *ctx)
+{
+ spin_lock(&queue_lock);
+ if (sleeping) {
+ triton_md_unregister_handler(&pgsql_hnd);
+ PQfinish(conn);
+ conn = NULL;
+ triton_context_unregister(&pgsql_ctx);
+ } else
+ need_close = 1;
+ spin_unlock(&queue_lock);
+}
+
static struct log_target_t target = {
.log = general_log,
};