Lines 51-56
Link Here
|
51 |
*/ |
51 |
*/ |
52 |
|
52 |
|
53 |
#ifdef DLZ_POSTGRES |
53 |
#ifdef DLZ_POSTGRES |
|
|
54 |
#define CUT_TEMP_MSGS |
54 |
|
55 |
|
55 |
#include <config.h> |
56 |
#include <config.h> |
56 |
#include <stdio.h> |
57 |
#include <stdio.h> |
Lines 297-306
Link Here
|
297 |
|
298 |
|
298 |
REQUIRE(*rs == NULL); |
299 |
REQUIRE(*rs == NULL); |
299 |
|
300 |
|
|
|
301 |
#ifndef CUT_TEMP_MSGS |
300 |
/* temporary logging message */ |
302 |
/* temporary logging message */ |
301 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
303 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
302 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
304 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
303 |
"%d Getting DBI", dlz_thread_num); |
305 |
"%d Getting DBI", dlz_thread_num); |
|
|
306 |
#endif |
304 |
|
307 |
|
305 |
/* get db instance / connection */ |
308 |
/* get db instance / connection */ |
306 |
#ifdef ISC_PLATFORM_USETHREADS |
309 |
#ifdef ISC_PLATFORM_USETHREADS |
Lines 318-328
Link Here
|
318 |
|
321 |
|
319 |
#endif /* ISC_PLATFORM_USETHREADS */ |
322 |
#endif /* ISC_PLATFORM_USETHREADS */ |
320 |
|
323 |
|
321 |
/* temporary logging message */ |
324 |
#ifndef CUT_TEMP_MSGS |
|
|
325 |
/* temporary logging message */ |
322 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
326 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
323 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
327 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
324 |
"%d Got DBI - checking query", dlz_thread_num); |
328 |
"%d Got DBI - checking query", dlz_thread_num); |
325 |
|
329 |
#endif |
326 |
/* if DBI is null, can't do anything else */ |
330 |
/* if DBI is null, can't do anything else */ |
327 |
if (dbi == NULL) { |
331 |
if (dbi == NULL) { |
328 |
result = ISC_R_FAILURE; |
332 |
result = ISC_R_FAILURE; |
Lines 391-400
Link Here
|
391 |
goto cleanup; |
395 |
goto cleanup; |
392 |
} |
396 |
} |
393 |
|
397 |
|
|
|
398 |
#ifndef CUT_TEMP_MSGS |
394 |
/* temporary logging message */ |
399 |
/* temporary logging message */ |
395 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
400 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
396 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
401 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
397 |
"%d checked query", dlz_thread_num); |
402 |
"%d checked query", dlz_thread_num); |
|
|
403 |
#endif |
398 |
|
404 |
|
399 |
/* |
405 |
/* |
400 |
* was a zone string passed? If so, make it safe for use in |
406 |
* was a zone string passed? If so, make it safe for use in |
Lines 410-420
Link Here
|
410 |
dbi->zone = NULL; |
416 |
dbi->zone = NULL; |
411 |
} |
417 |
} |
412 |
|
418 |
|
|
|
419 |
#ifndef CUT_TEMP_MSGS |
413 |
/* temporary logging message */ |
420 |
/* temporary logging message */ |
414 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
421 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
415 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
422 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
416 |
"%d did zone", dlz_thread_num); |
423 |
"%d did zone", dlz_thread_num); |
417 |
|
424 |
#endif |
418 |
/* |
425 |
/* |
419 |
* was a record string passed? If so, make it safe for use in |
426 |
* was a record string passed? If so, make it safe for use in |
420 |
* queries. |
427 |
* queries. |
Lines 429-440
Link Here
|
429 |
dbi->record = NULL; |
436 |
dbi->record = NULL; |
430 |
} |
437 |
} |
431 |
|
438 |
|
432 |
|
439 |
#ifndef CUT_TEMP_MSGS |
433 |
/* temporary logging message */ |
440 |
/* temporary logging message */ |
434 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
441 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
435 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
442 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
436 |
"%d did record", dlz_thread_num); |
443 |
"%d did record", dlz_thread_num); |
437 |
|
444 |
#endif |
438 |
/* |
445 |
/* |
439 |
* was a client string passed? If so, make it safe for use in |
446 |
* was a client string passed? If so, make it safe for use in |
440 |
* queries. |
447 |
* queries. |
Lines 449-459
Link Here
|
449 |
dbi->client = NULL; |
456 |
dbi->client = NULL; |
450 |
} |
457 |
} |
451 |
|
458 |
|
|
|
459 |
#ifndef CUT_TEMP_MSGS |
452 |
/* temporary logging message */ |
460 |
/* temporary logging message */ |
453 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
461 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
454 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
462 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
455 |
"%d did client", dlz_thread_num); |
463 |
"%d did client", dlz_thread_num); |
456 |
|
464 |
#endif |
457 |
/* |
465 |
/* |
458 |
* what type of query are we going to run? |
466 |
* what type of query are we going to run? |
459 |
* this time we build the actual query to run. |
467 |
* this time we build the actual query to run. |
Lines 486-495
Link Here
|
486 |
goto cleanup; |
494 |
goto cleanup; |
487 |
} |
495 |
} |
488 |
|
496 |
|
|
|
497 |
#ifndef CUT_TEMP_MSGS |
489 |
/* temporary logging message */ |
498 |
/* temporary logging message */ |
490 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
499 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
491 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
500 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
492 |
"%d built query", dlz_thread_num); |
501 |
"%d built query", dlz_thread_num); |
|
|
502 |
#endif |
493 |
|
503 |
|
494 |
/* if the querystring is null, Bummer, outta RAM. UPGRADE TIME!!! */ |
504 |
/* if the querystring is null, Bummer, outta RAM. UPGRADE TIME!!! */ |
495 |
if (querystring == NULL) { |
505 |
if (querystring == NULL) { |
Lines 497-507
Link Here
|
497 |
goto cleanup; |
507 |
goto cleanup; |
498 |
} |
508 |
} |
499 |
|
509 |
|
|
|
510 |
#ifndef CUT_TEMP_MSGS |
500 |
/* temporary logging message */ |
511 |
/* temporary logging message */ |
501 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
512 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
502 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
513 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
503 |
"%d query is '%s'", dlz_thread_num, querystring); |
514 |
"%d query is '%s'", dlz_thread_num, querystring); |
504 |
|
515 |
#endif |
505 |
/* |
516 |
/* |
506 |
* output the full query string during debug so we can see |
517 |
* output the full query string during debug so we can see |
507 |
* what lame error the query has. |
518 |
* what lame error the query has. |
Lines 512-522
Link Here
|
512 |
|
523 |
|
513 |
/* attempt query up to 3 times. */ |
524 |
/* attempt query up to 3 times. */ |
514 |
for (j=0; j < 3; j++) { |
525 |
for (j=0; j < 3; j++) { |
|
|
526 |
#ifndef CUT_TEMP_MSGS |
515 |
/* temporary logging message */ |
527 |
/* temporary logging message */ |
516 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
528 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
517 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
529 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
518 |
"%d executing query for %d time", |
530 |
"%d executing query for %d time", |
519 |
dlz_thread_num, j); |
531 |
dlz_thread_num, j); |
|
|
532 |
#endif |
520 |
/* try to get result set */ |
533 |
/* try to get result set */ |
521 |
*rs = PQexec((PGconn *)dbi->dbconn, querystring ); |
534 |
*rs = PQexec((PGconn *)dbi->dbconn, querystring ); |
522 |
result = ISC_R_SUCCESS; |
535 |
result = ISC_R_SUCCESS; |
Lines 525-535
Link Here
|
525 |
* attempts. |
538 |
* attempts. |
526 |
*/ |
539 |
*/ |
527 |
for (i=0; *rs == NULL && i < 3; i++) { |
540 |
for (i=0; *rs == NULL && i < 3; i++) { |
|
|
541 |
#ifndef CUT_TEMP_MSGS |
528 |
/* temporary logging message */ |
542 |
/* temporary logging message */ |
529 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
543 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
530 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
544 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
531 |
"%d resetting connection", |
545 |
"%d resetting connection", |
532 |
dlz_thread_num); |
546 |
dlz_thread_num); |
|
|
547 |
#endif |
533 |
result = ISC_R_FAILURE; |
548 |
result = ISC_R_FAILURE; |
534 |
PQreset((PGconn *) dbi->dbconn); |
549 |
PQreset((PGconn *) dbi->dbconn); |
535 |
/* connection ok, break inner loop */ |
550 |
/* connection ok, break inner loop */ |
Lines 538-554
Link Here
|
538 |
} |
553 |
} |
539 |
/* result set ok, break outter loop */ |
554 |
/* result set ok, break outter loop */ |
540 |
if (PQresultStatus(*rs) == PGRES_TUPLES_OK) { |
555 |
if (PQresultStatus(*rs) == PGRES_TUPLES_OK) { |
|
|
556 |
#ifndef CUT_TEMP_MSGS |
541 |
/* temporary logging message */ |
557 |
/* temporary logging message */ |
542 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
558 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
543 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
559 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
544 |
"%d rs ok", dlz_thread_num); |
560 |
"%d rs ok", dlz_thread_num); |
|
|
561 |
#endif |
545 |
break; |
562 |
break; |
546 |
} else { |
563 |
} else { |
547 |
/* we got a result set object, but it's not right. */ |
564 |
/* we got a result set object, but it's not right. */ |
|
|
565 |
#ifndef CUT_TEMP_MSGS |
548 |
/* temporary logging message */ |
566 |
/* temporary logging message */ |
549 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
567 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
550 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
568 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
551 |
"%d clearing rs", dlz_thread_num); |
569 |
"%d clearing rs", dlz_thread_num); |
|
|
570 |
#endif |
552 |
PQclear(*rs); /* get rid of it */ |
571 |
PQclear(*rs); /* get rid of it */ |
553 |
/* in case this was the last attempt */ |
572 |
/* in case this was the last attempt */ |
554 |
result = ISC_R_FAILURE; |
573 |
result = ISC_R_FAILURE; |
Lines 558-568
Link Here
|
558 |
cleanup: |
577 |
cleanup: |
559 |
/* it's always good to cleanup after yourself */ |
578 |
/* it's always good to cleanup after yourself */ |
560 |
|
579 |
|
|
|
580 |
#ifndef CUT_TEMP_MSGS |
561 |
/* temporary logging message */ |
581 |
/* temporary logging message */ |
562 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
582 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
563 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
583 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
564 |
"%d cleaning up", dlz_thread_num); |
584 |
"%d cleaning up", dlz_thread_num); |
565 |
|
585 |
#endif |
566 |
/* if we couldn't even allocate DBI, just return NULL */ |
586 |
/* if we couldn't even allocate DBI, just return NULL */ |
567 |
if (dbi == NULL) |
587 |
if (dbi == NULL) |
568 |
return ISC_R_FAILURE; |
588 |
return ISC_R_FAILURE; |
Lines 581-591
Link Here
|
581 |
|
601 |
|
582 |
#ifdef ISC_PLATFORM_USETHREADS |
602 |
#ifdef ISC_PLATFORM_USETHREADS |
583 |
|
603 |
|
|
|
604 |
#ifndef CUT_TEMP_MSGS |
584 |
/* temporary logging message */ |
605 |
/* temporary logging message */ |
585 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
606 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
586 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
607 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
587 |
"%d unlocking mutex", dlz_thread_num); |
608 |
"%d unlocking mutex", dlz_thread_num); |
588 |
|
609 |
#endif |
589 |
/* release the lock so another thread can use this dbi */ |
610 |
/* release the lock so another thread can use this dbi */ |
590 |
isc_mutex_unlock(&dbi->instance_lock); |
611 |
isc_mutex_unlock(&dbi->instance_lock); |
591 |
|
612 |
|
Lines 595-605
Link Here
|
595 |
if (querystring != NULL) |
616 |
if (querystring != NULL) |
596 |
isc_mem_free(ns_g_mctx, querystring ); |
617 |
isc_mem_free(ns_g_mctx, querystring ); |
597 |
|
618 |
|
|
|
619 |
#ifndef CUT_TEMP_MSGS |
598 |
/* temporary logging message */ |
620 |
/* temporary logging message */ |
599 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
621 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
600 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
622 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
601 |
"%d returning", dlz_thread_num); |
623 |
"%d returning", dlz_thread_num); |
602 |
|
624 |
#endif |
603 |
/* return result */ |
625 |
/* return result */ |
604 |
return result; |
626 |
return result; |
605 |
} |
627 |
} |
Lines 752-759
Link Here
|
752 |
FINDZONE, dbdata, &rs); |
774 |
FINDZONE, dbdata, &rs); |
753 |
/* if we didn't get a result set, log an err msg. */ |
775 |
/* if we didn't get a result set, log an err msg. */ |
754 |
if (result != ISC_R_SUCCESS) { |
776 |
if (result != ISC_R_SUCCESS) { |
755 |
if (rs != NULL) |
777 |
/* if (rs != NULL) PQclear(rs);*/ |
756 |
PQclear(rs); |
|
|
757 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
778 |
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, |
758 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
779 |
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, |
759 |
"Postgres driver unable to return " |
780 |
"Postgres driver unable to return " |