diff options
author | Kozlov Dmitry <dima@server> | 2010-09-23 19:43:39 +0400 |
---|---|---|
committer | Kozlov Dmitry <dima@server> | 2010-09-23 19:43:39 +0400 |
commit | 8681ad6d60565ca2e399156bf721f67f8a8bdc92 (patch) | |
tree | e736428b3d5dcfe52f65d9234b8ebc4ba17259cf /accel-pptpd/logs/log_pgsql.c | |
parent | 82b0f0953159fc9ab8e387f5e6014dc377b14b38 (diff) | |
download | accel-ppp-8681ad6d60565ca2e399156bf721f67f8a8bdc92.tar.gz accel-ppp-8681ad6d60565ca2e399156bf721f67f8a8bdc92.zip |
various bug fixes
Diffstat (limited to 'accel-pptpd/logs/log_pgsql.c')
-rw-r--r-- | accel-pptpd/logs/log_pgsql.c | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/accel-pptpd/logs/log_pgsql.c b/accel-pptpd/logs/log_pgsql.c index 393c3bdc..351fc064 100644 --- a/accel-pptpd/logs/log_pgsql.c +++ b/accel-pptpd/logs/log_pgsql.c @@ -74,31 +74,40 @@ static void write_next_msg(void) const char *paramValues[4]; int paramFormats[4] = {0, 0, 0, 0}; char *ptr1, *ptr2; + int r; spin_lock(&queue_lock); - if (!list_empty(&msg_queue)) { - msg = list_entry(msg_queue.next, typeof(*msg), entry); - list_del(&msg->entry); - --queue_size; + if (list_empty(&msg_queue)) { + sleeping = 1; spin_unlock(&queue_lock); + return; + } - unpack_msg(msg); + msg = list_entry(msg_queue.next, typeof(*msg), entry); + list_del(&msg->entry); + --queue_size; + spin_unlock(&queue_lock); - ptr1 = strchr(msg->hdr->msg, 0); - ptr2 = strchr(ptr1 + 1, 0); + unpack_msg(msg); - paramValues[1] = ptr1[1] ? ptr1 + 1 : NULL; - paramValues[2] = ptr2[1] ? ptr2 + 1 : NULL; - paramValues[0] = msg->hdr->msg; - paramValues[3] = log_buf; + ptr1 = strchr(msg->hdr->msg, 0); + ptr2 = strchr(ptr1 + 1, 0); - PQsendQueryParams(conn, conf_query, 4, NULL, paramValues, NULL, paramFormats, 0); - PQflush(conn); - log_free_msg(msg); - return; - } - sleeping = 1; - spin_unlock(&queue_lock); + paramValues[1] = ptr1[1] ? ptr1 + 1 : NULL; + paramValues[2] = ptr2[1] ? ptr2 + 1 : NULL; + paramValues[0] = msg->hdr->msg; + paramValues[3] = log_buf; + + if (!PQsendQueryParams(conn, conf_query, 4, NULL, paramValues, NULL, paramFormats, 0)) + log_emerg("log_pgsql: %s\n", PQerrorMessage(conn)); + + log_free_msg(msg); + + r = PQflush(conn); + if (r == -1) + log_emerg("log_pgsql: %s\n", PQerrorMessage(conn)); + if (r == 0) + triton_md_enable_handler(&pgsql_hnd, MD_MODE_WRITE); } static int pgsql_check_ready(struct triton_md_handler_t *h) @@ -132,7 +141,15 @@ static int pgsql_check_ready(struct triton_md_handler_t *h) static int pgsql_flush(struct triton_md_handler_t *h) { - PQflush(conn); + int r; + + r = PQflush(conn); + if (r == -1) + log_emerg("log_pgsql: %s\n", PQerrorMessage(conn)); + if (r == 1) + return 0; + + triton_md_disable_handler(&pgsql_hnd, MD_MODE_WRITE); return 0; } @@ -196,7 +213,7 @@ static int wait_connect(struct triton_md_handler_t *h) PQsetnonblocking(conn, 1); h->write = pgsql_flush; h->read = pgsql_check_ready; - triton_md_enable_handler(&pgsql_hnd, MD_MODE_READ | MD_MODE_WRITE); + triton_md_enable_handler(&pgsql_hnd, MD_MODE_READ); wakeup_log(); break; default: @@ -266,6 +283,8 @@ static void __init init(void) triton_context_register(&pgsql_ctx, NULL); triton_md_register_handler(&pgsql_ctx, &pgsql_hnd); + triton_md_set_trig(&pgsql_hnd, MD_TRIG_LEVEL); + triton_context_wakeup(&pgsql_ctx); start_connect(); |