summaryrefslogtreecommitdiffstats
path: root/mod_log_sql.c
diff options
context:
space:
mode:
Diffstat (limited to 'mod_log_sql.c')
-rw-r--r--mod_log_sql.c62
1 files changed, 35 insertions, 27 deletions
diff --git a/mod_log_sql.c b/mod_log_sql.c
index a247f30..3b4e6f4 100644
--- a/mod_log_sql.c
+++ b/mod_log_sql.c
@@ -164,7 +164,8 @@ static logsql_opendb_ret log_sql_opendb_link(server_rec* s)
164 } 164 }
165 return result; 165 return result;
166 } else { 166 } else {
167 log_error(APLOG_MARK,APLOG_ERR,s,"mod_log_sql: insufficient configuration info to establish database link"); 167 log_error(APLOG_MARK, APLOG_ERR, 0, s,
168 "mod_log_sql: insufficient configuration info to establish database link");
168 return LOGSQL_OPENDB_FAIL; 169 return LOGSQL_OPENDB_FAIL;
169 } 170 }
170} 171}
@@ -188,10 +189,11 @@ static void preserve_entry(request_rec *r, const char *query)
188 FILE *fp; 189 FILE *fp;
189 int result; 190 int result;
190 fp = ap_pfopen(r->pool, cls->preserve_file, "a"); 191 fp = ap_pfopen(r->pool, cls->preserve_file, "a");
191 result = (fp)?0:1; 192 result = (fp)?0:errno;
192 #endif 193 #endif
193 if (result != APR_SUCCESS) { 194 if (result != APR_SUCCESS) {
194 log_error(APLOG_MARK,APLOG_ERR,r->server,"attempted append of local preserve file '%s' but failed.",cls->preserve_file); 195 log_error(APLOG_MARK, APLOG_ERR, result, r->server,
196 "attempted append of local preserve file '%s' but failed.",cls->preserve_file);
195 } else { 197 } else {
196 #if defined(WITH_APACHE20) 198 #if defined(WITH_APACHE20)
197 apr_file_printf(fp,"%s;\n", query); 199 apr_file_printf(fp,"%s;\n", query);
@@ -200,7 +202,8 @@ static void preserve_entry(request_rec *r, const char *query)
200 fprintf(fp,"%s;\n", query); 202 fprintf(fp,"%s;\n", query);
201 ap_pfclose(r->pool, fp); 203 ap_pfclose(r->pool, fp);
202 #endif 204 #endif
203 log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: entry preserved in %s", cls->preserve_file); 205 log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
206 "mod_log_sql: entry preserved in %s", cls->preserve_file);
204 } 207 }
205} 208}
206 209
@@ -403,14 +406,17 @@ static void log_sql_child_init(server_rec *s, apr_pool_t *p)
403 retval = log_sql_opendb_link(s); 406 retval = log_sql_opendb_link(s);
404 switch (retval) { 407 switch (retval) {
405 case LOGSQL_OPENDB_FAIL: 408 case LOGSQL_OPENDB_FAIL:
406 log_error(APLOG_MARK,APLOG_ERR,s,"mod_log_sql: child spawned but unable to open database link"); 409 log_error(APLOG_MARK, APLOG_ERR, 0, s,
410 "mod_log_sql: child spawned but unable to open database link");
407 break; 411 break;
408 case LOGSQL_OPENDB_SUCCESS: 412 case LOGSQL_OPENDB_SUCCESS:
409 case LOGSQL_OPENDB_ALREADY: 413 case LOGSQL_OPENDB_ALREADY:
410 log_error(APLOG_MARK,APLOG_DEBUG,s,"mod_log_sql: open_logdb_link successful"); 414 log_error(APLOG_MARK,APLOG_DEBUG,0, s,
415 "mod_log_sql: open_logdb_link successful");
411 break; 416 break;
412 case LOGSQL_OPENDB_PRESERVE: 417 case LOGSQL_OPENDB_PRESERVE:
413 log_error(APLOG_MARK,APLOG_DEBUG,s,"mod_log_sql: open_logdb_link said that preservation is forced"); 418 log_error(APLOG_MARK,APLOG_DEBUG, 0, s,
419 "mod_log_sql: open_logdb_link said that preservation is forced");
414 break; 420 break;
415 } 421 }
416} 422}
@@ -488,7 +494,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
488 global_config.db.connected = 0; 494 global_config.db.connected = 0;
489 /* re-open the connection and try again */ 495 /* re-open the connection and try again */
490 if (log_sql_opendb_link(r->server) != LOGSQL_OPENDB_FAIL) { 496 if (log_sql_opendb_link(r->server) != LOGSQL_OPENDB_FAIL) {
491 log_error(APLOG_MARK,APLOG_ERR,r->server,"db reconnect successful"); 497 log_error(APLOG_MARK,APLOG_NOTICE,0, r->server,"db reconnect successful");
492# if defined(WITH_APACHE20) 498# if defined(WITH_APACHE20)
493 apr_sleep(apr_time_from_sec(0.25)); /* pause for a quarter second */ 499 apr_sleep(apr_time_from_sec(0.25)); /* pause for a quarter second */
494# elif defined(WITH_APACHE13) 500# elif defined(WITH_APACHE13)
@@ -499,7 +505,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
499 delay.tv_nsec = 250000000; /* pause for a quarter second */ 505 delay.tv_nsec = 250000000; /* pause for a quarter second */
500 nanoret = nanosleep(&delay, &remainder); 506 nanoret = nanosleep(&delay, &remainder);
501 if (nanoret && errno != EINTR) { 507 if (nanoret && errno != EINTR) {
502 log_error(APLOG_MARK,APLOG_ERR,r->server,"nanosleep unsuccessful"); 508 log_error(APLOG_MARK,APLOG_ERR, errno, r->server,"nanosleep unsuccessful");
503 } 509 }
504 } 510 }
505# endif 511# endif
@@ -507,50 +513,52 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
507 if (result == LOGSQL_QUERY_SUCCESS) { 513 if (result == LOGSQL_QUERY_SUCCESS) {
508 return LOGSQL_QUERY_SUCCESS; 514 return LOGSQL_QUERY_SUCCESS;
509 } else { 515 } else {
510 log_error(APLOG_MARK,APLOG_ERR,r->server,"second attempt failed"); 516 log_error(APLOG_MARK,APLOG_ERR,0,r->server,"second attempt failed");
511 preserve_entry(r, query); 517 preserve_entry(r, query);
512 return LOGSQL_QUERY_PRESERVED; 518 return LOGSQL_QUERY_PRESERVED;
513 } 519 }
514 } else { 520 } else {
515 log_error(APLOG_MARK,APLOG_ERR,r->server,"reconnect failed, unable to reach database. SQL logging stopped until child regains a db connection."); 521 log_error(APLOG_MARK,APLOG_ERR,0,r->server,
516 log_error(APLOG_MARK,APLOG_ERR,r->server,"log entries are being preserved in %s",cls->preserve_file); 522 "reconnect failed, unable to reach database. SQL logging stopped until child regains a db connection.");
523 log_error(APLOG_MARK,APLOG_ERR,0,r->server,
524 "log entries are being preserved in %s",cls->preserve_file);
517 preserve_entry(r, query); 525 preserve_entry(r, query);
518 return LOGSQL_QUERY_PRESERVED; 526 return LOGSQL_QUERY_PRESERVED;
519 } 527 }
520 break; 528 break;
521 case LOGSQL_QUERY_NOTABLE: 529 case LOGSQL_QUERY_NOTABLE:
522 if (global_config.createtables) { 530 if (global_config.createtables) {
523 log_error(APLOG_MARK,APLOG_ERR,r->server, 531 log_error(APLOG_MARK,APLOG_ERR,0,r->server,
524 "table doesn't exist...creating now"); 532 "table doesn't exist...creating now");
525 if ((result = log_sql_mysql_create(r, &global_config.db, table_type, 533 if ((result = log_sql_mysql_create(r, &global_config.db, table_type,
526 table_name))!=LOGSQL_TABLE_SUCCESS) { 534 table_name))!=LOGSQL_TABLE_SUCCESS) {
527 log_error(APLOG_MARK,APLOG_ERR,r->server, 535 log_error(APLOG_MARK,APLOG_ERR,result,r->server,
528 "child attempted but failed to create one or more tables for %s, preserving query", ap_get_server_name(r)); 536 "child attempted but failed to create one or more tables for %s, preserving query", ap_get_server_name(r));
529 preserve_entry(r, query); 537 preserve_entry(r, query);
530 return LOGSQL_QUERY_PRESERVED; 538 return LOGSQL_QUERY_PRESERVED;
531 } else { 539 } else {
532 log_error(APLOG_MARK,APLOG_ERR,r->server, 540 log_error(APLOG_MARK,APLOG_ERR,result, r->server,
533 "tables successfully created - retrying query"); 541 "tables successfully created - retrying query");
534 if ((result = log_sql_mysql_query(r,&global_config.db,query))!=LOGSQL_QUERY_SUCCESS) { 542 if ((result = log_sql_mysql_query(r,&global_config.db,query))!=LOGSQL_QUERY_SUCCESS) {
535 log_error(APLOG_MARK,APLOG_ERR,r->server, 543 log_error(APLOG_MARK,APLOG_ERR,result, r->server,
536 "giving up, preserving query"); 544 "giving up, preserving query");
537 preserve_entry(r, query); 545 preserve_entry(r, query);
538 return LOGSQL_QUERY_PRESERVED; 546 return LOGSQL_QUERY_PRESERVED;
539 } else { 547 } else {
540 log_error(APLOG_MARK,APLOG_ERR,r->server, 548 log_error(APLOG_MARK,APLOG_NOTICE,0, r->server,
541 "query successful after table creation"); 549 "query successful after table creation");
542 return LOGSQL_QUERY_SUCCESS; 550 return LOGSQL_QUERY_SUCCESS;
543 } 551 }
544 } 552 }
545 } else { 553 } else {
546 log_error(APLOG_MARK,APLOG_ERR,r->server, 554 log_error(APLOG_MARK,APLOG_ERR,0,r->server,
547 "table doesn't exist, creation denied by configuration, preserving query"); 555 "table doesn't exist, creation denied by configuration, preserving query");
548 preserve_entry(r, query); 556 preserve_entry(r, query);
549 return LOGSQL_QUERY_PRESERVED; 557 return LOGSQL_QUERY_PRESERVED;
550 } 558 }
551 break; 559 break;
552 default: 560 default:
553 log_error(APLOG_MARK,APLOG_ERR,r->server, 561 log_error(APLOG_MARK,APLOG_ERR,0, r->server,
554 "Invalid return code from mog_log_query"); 562 "Invalid return code from mog_log_query");
555 return LOGSQL_QUERY_FAIL; 563 return LOGSQL_QUERY_FAIL;
556 break; 564 break;
@@ -773,7 +781,7 @@ static int log_sql_transaction(request_rec *orig)
773 for (i = 0; i<length; i++) { 781 for (i = 0; i<length; i++) {
774 logsql_item *item = cls->parsed_log_format[i]; 782 logsql_item *item = cls->parsed_log_format[i];
775 if (item==NULL) { 783 if (item==NULL) {
776 log_error(APLOG_MARK, APLOG_ERR, orig->server, 784 log_error(APLOG_MARK, APLOG_ERR, 0, orig->server,
777 "Log Format '%c' unknown",cls->transfer_log_format[i]); 785 "Log Format '%c' unknown",cls->transfer_log_format[i]);
778 continue; 786 continue;
779 } 787 }
@@ -825,7 +833,7 @@ static int log_sql_transaction(request_rec *orig)
825 note_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", 833 note_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s",
826 /*global_config.insertdelayed?"delayed":*/"", notes_tablename, itemsets); 834 /*global_config.insertdelayed?"delayed":*/"", notes_tablename, itemsets);
827 835
828 log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: note string: %s", note_query); 836 log_error(APLOG_MARK,APLOG_DEBUG,0, orig->server,"mod_log_sql: note string: %s", note_query);
829 } 837 }
830 838
831 /* Work through the list of headers-out defined by LogSQLWhichHeadersOut*/ 839 /* Work through the list of headers-out defined by LogSQLWhichHeadersOut*/
@@ -853,7 +861,7 @@ static int log_sql_transaction(request_rec *orig)
853 hout_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", 861 hout_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s",
854 /*global_config.insertdelayed?"delayed":*/"", hout_tablename, itemsets); 862 /*global_config.insertdelayed?"delayed":*/"", hout_tablename, itemsets);
855 863
856 log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: header_out string: %s", hout_query); 864 log_error(APLOG_MARK,APLOG_DEBUG,0, orig->server,"mod_log_sql: header_out string: %s", hout_query);
857 } 865 }
858 866
859 867
@@ -882,7 +890,7 @@ static int log_sql_transaction(request_rec *orig)
882 hin_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", 890 hin_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s",
883 /*global_config.insertdelayed?"delayed":*/"", hin_tablename, itemsets); 891 /*global_config.insertdelayed?"delayed":*/"", hin_tablename, itemsets);
884 892
885 log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: header_in string: %s", hin_query); 893 log_error(APLOG_MARK,APLOG_DEBUG,0, orig->server,"mod_log_sql: header_in string: %s", hin_query);
886 } 894 }
887 895
888 896
@@ -912,7 +920,7 @@ static int log_sql_transaction(request_rec *orig)
912 cookie_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", 920 cookie_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s",
913 /*global_config.insertdelayed?"delayed":*/"", cookie_tablename, itemsets); 921 /*global_config.insertdelayed?"delayed":*/"", cookie_tablename, itemsets);
914 922
915 log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: cookie string: %s", cookie_query); 923 log_error(APLOG_MARK,APLOG_DEBUG,0, orig->server,"mod_log_sql: cookie string: %s", cookie_query);
916 } 924 }
917 925
918 926
@@ -920,13 +928,13 @@ static int log_sql_transaction(request_rec *orig)
920 access_query = apr_psprintf(r->pool, "insert %s into `%s` (%s) values (%s)", 928 access_query = apr_psprintf(r->pool, "insert %s into `%s` (%s) values (%s)",
921 /*global_config.insertdelayed?"delayed":*/"", transfer_tablename, fields, values); 929 /*global_config.insertdelayed?"delayed":*/"", transfer_tablename, fields, values);
922 930
923 log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: access string: %s", access_query); 931 log_error(APLOG_MARK,APLOG_DEBUG,0, r->server,"mod_log_sql: access string: %s", access_query);
924 932
925 /* If the person activated force-preserve, go ahead and push all the entries 933 /* If the person activated force-preserve, go ahead and push all the entries
926 * into the preserve file, then return. 934 * into the preserve file, then return.
927 */ 935 */
928 if (global_config.forcepreserve) { 936 if (global_config.forcepreserve) {
929 log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: preservation forced"); 937 log_error(APLOG_MARK,APLOG_DEBUG,0, orig->server,"mod_log_sql: preservation forced");
930 preserve_entry(orig, access_query); 938 preserve_entry(orig, access_query);
931 if ( note_query != NULL ) 939 if ( note_query != NULL )
932 preserve_entry(orig, note_query); 940 preserve_entry(orig, note_query);
@@ -964,7 +972,7 @@ static int log_sql_transaction(request_rec *orig)
964 return OK; 972 return OK;
965 } else { 973 } else {
966 /* Whew, we got the DB link back */ 974 /* Whew, we got the DB link back */
967 log_error(APLOG_MARK,APLOG_NOTICE,orig->server,"mod_log_sql: child established database connection"); 975 log_error(APLOG_MARK,APLOG_NOTICE,0, orig->server,"mod_log_sql: child established database connection");
968 } 976 }
969 } 977 }
970 978