| 791 | } |
| 792 | |
| 793 | DBD_DECLARE_NONSTD(ap_dbd_t*) ap_dbd_open(apr_pool_t *pool, server_rec *s) |
| 794 | { |
| 795 | svr_cfg *svr = ap_get_module_config(s->module_config, &dbd_module); |
| 796 | dbd_group_t *group = svr->group; |
| 797 | dbd_cfg_t *cfg = svr->cfg; |
| 798 | ap_dbd_t *rec = NULL; |
| 799 | #if APR_HAS_THREADS |
| 800 | apr_status_t rv; |
| 801 | #endif |
| 802 | |
| 803 | /* If nothing is configured, we shouldn't be here */ |
| 804 | if (cfg->name == no_dbdriver) { |
| 805 | ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(02654) |
| 806 | "not configured"); |
| 807 | return NULL; |
| 808 | } |
| 809 | |
| 810 | if (!cfg->persist) { |
| 811 | /* Return a once-only connection */ |
| 812 | group = apr_pcalloc(pool, sizeof(dbd_group_t)); |
| 813 | |
| 814 | group->cfg = cfg; |
| 815 | |
| 816 | dbd_construct((void*) &rec, group, pool); |
| 817 | return rec; |
| 818 | } |
| 819 | |
| 820 | #if APR_HAS_THREADS |
| 821 | if (!group->reslist) { |
| 822 | if (dbd_setup_lock(s, group) != APR_SUCCESS) { |
| 823 | return NULL; |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | rv = apr_reslist_acquire(group->reslist, (void*) &rec); |
| 828 | if (rv != APR_SUCCESS) { |
| 829 | ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(02655) |
| 830 | "Failed to acquire DBD connection from pool!"); |
| 831 | return NULL; |
| 832 | } |
| 833 | |
| 834 | if (dbd_check(pool, s, rec) != APR_SUCCESS) { |
| 835 | apr_reslist_invalidate(group->reslist, rec); |
| 836 | return NULL; |
| 837 | } |
| 838 | #else |
| 839 | /* If we have a persistent connection and it's good, we'll use it; |
| 840 | * since this is non-threaded, we can update without a mutex |
| 841 | */ |
| 842 | rec = group->rec; |
| 843 | if (rec) { |
| 844 | if (dbd_check(pool, s, rec) != APR_SUCCESS) { |
| 845 | apr_pool_destroy(rec->pool); |
| 846 | rec = NULL; |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | /* We don't have a connection right now, so we'll open one */ |
no test coverage detected