| 438 | } |
| 439 | |
| 440 | bool db_pgsql::dbopen(const char* /* charset = NULL */) |
| 441 | { |
| 442 | if (conn_) { |
| 443 | return true; |
| 444 | } |
| 445 | |
| 446 | char tmpbuf[256]; |
| 447 | char *db_host, *db_unix; |
| 448 | int db_port; |
| 449 | |
| 450 | char* ptr = strchr(dbaddr_, '/'); |
| 451 | if (ptr == NULL) { |
| 452 | ACL_SAFE_STRNCPY(tmpbuf, dbaddr_, sizeof(tmpbuf)); |
| 453 | ptr = strchr(tmpbuf, ':'); |
| 454 | if (ptr == NULL || *(ptr + 1) == 0) { |
| 455 | logger_error("invalid db_addr=%s", dbaddr_); |
| 456 | return false; |
| 457 | } else { |
| 458 | *ptr++ = 0; |
| 459 | } |
| 460 | db_host = tmpbuf; |
| 461 | |
| 462 | db_port = atoi(ptr); |
| 463 | if (db_port <= 0) { |
| 464 | logger_error("invalid port=%d", db_port); |
| 465 | return false; |
| 466 | } |
| 467 | db_unix = NULL; |
| 468 | } else { |
| 469 | db_unix = dbaddr_; |
| 470 | db_host = db_unix; |
| 471 | db_port = 0; |
| 472 | } |
| 473 | |
| 474 | int* dummy; |
| 475 | |
| 476 | if (acl_pthread_once(&__thread_once_control, thread_once) != 0) { |
| 477 | logger_error("call thread_once error: %s", acl_last_serror()); |
| 478 | } else if (!(dummy = (int*) acl_pthread_getspecific(__thread_key))) { |
| 479 | dummy = (int*) acl_mymalloc(sizeof(int)); |
| 480 | *dummy = 1; |
| 481 | if (acl_pthread_setspecific(__thread_key, dummy) != 0) { |
| 482 | abort(); |
| 483 | } |
| 484 | |
| 485 | if ((unsigned long) acl_pthread_self() |
| 486 | == acl_main_thread_self()) { |
| 487 | |
| 488 | __main_dummy = dummy; |
| 489 | #ifndef HAVE_NO_ATEXIT |
| 490 | atexit(main_free_dummy); |
| 491 | #endif |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | string info; |
| 496 | info.format("host=%s dbname=%s", db_host, dbname_); |
| 497 | if (db_unix == NULL) { |
no test coverage detected