| 6577 | int comdb2_cheapstack_char_array(char *str, int maxln); |
| 6578 | |
| 6579 | int cdb2_open(cdb2_hndl_tp **handle, const char *dbname, const char *type, |
| 6580 | int flags) |
| 6581 | { |
| 6582 | cdb2_hndl_tp *hndl; |
| 6583 | int rc = 0; |
| 6584 | void *callbackrc; |
| 6585 | cdb2_event *e = NULL; |
| 6586 | |
| 6587 | pthread_mutex_lock(&cdb2_cfg_lock); |
| 6588 | pthread_once(&init_once, do_init_once); |
| 6589 | pthread_mutex_unlock(&cdb2_cfg_lock); |
| 6590 | |
| 6591 | *handle = hndl = calloc(1, sizeof(cdb2_hndl_tp)); |
| 6592 | hndl->events = calloc(1, sizeof(*hndl->events)); |
| 6593 | hndl->gbl_event_version = calloc(1, sizeof(*hndl->gbl_event_version)); |
| 6594 | strncpy(hndl->dbname, dbname, sizeof(hndl->dbname) - 1); |
| 6595 | strncpy(hndl->cluster, type, sizeof(hndl->cluster) - 1); |
| 6596 | strncpy(hndl->type, type, sizeof(hndl->type) - 1); |
| 6597 | hndl->flags = flags; |
| 6598 | hndl->dbnum = 1; |
| 6599 | hndl->connected_host = -1; |
| 6600 | hndl->send_stack = 0; |
| 6601 | hndl->read_intrans_results = 1; |
| 6602 | |
| 6603 | /* We don't do dbinfo if DIRECT_CPU. So we'd default peer SSL mode to |
| 6604 | ALLOW. We will find it out later when we send SSL negotitaion packet |
| 6605 | to the server. */ |
| 6606 | hndl->s_sslmode = PEER_SSL_ALLOW; |
| 6607 | |
| 6608 | hndl->max_retries = MAX_RETRIES; |
| 6609 | hndl->min_retries = MIN_RETRIES; |
| 6610 | |
| 6611 | hndl->env_tz = getenv("COMDB2TZ"); |
| 6612 | hndl->is_admin = (flags & CDB2_ADMIN); |
| 6613 | |
| 6614 | if (hndl->env_tz == NULL) |
| 6615 | hndl->env_tz = getenv("TZ"); |
| 6616 | |
| 6617 | if (hndl->env_tz == NULL) |
| 6618 | hndl->env_tz = DB_TZNAME_DEFAULT; |
| 6619 | |
| 6620 | |
| 6621 | cdb2_init_context_msgs(hndl); |
| 6622 | |
| 6623 | if (getenv("CDB2_DEBUG")) { |
| 6624 | hndl->debug_trace = 1; |
| 6625 | debugprint("debug trace enabled\n"); |
| 6626 | } |
| 6627 | |
| 6628 | if (hndl->flags & CDB2_RANDOM) { |
| 6629 | strcpy(hndl->policy, "random"); |
| 6630 | } else if (hndl->flags & CDB2_RANDOMROOM) { |
| 6631 | strcpy(hndl->policy, "random_room"); |
| 6632 | } else if (hndl->flags & CDB2_ROOM) { |
| 6633 | strcpy(hndl->policy, "room"); |
| 6634 | } else { |
| 6635 | hndl->flags |= CDB2_RANDOMROOM; |
| 6636 | /* DIRECTCPU mode behaves like RANDOMROOM. But let's pick a shorter policy name |