MCPcopy Create free account
hub / github.com/apache/httpd / dbd_construct

Function dbd_construct

modules/database/mod_dbd.c:512–611  ·  view source on GitHub ↗

an apr_reslist_constructor for SQL connections * Also use this for opening in non-reslist modes, since it gives * us all the error-handling in one place. */

Source from the content-addressed store, hash-verified

510 * us all the error-handling in one place.
511 */
512static apr_status_t dbd_construct(void **data_ptr,
513 void *params, apr_pool_t *pool)
514{
515 dbd_group_t *group = params;
516 dbd_cfg_t *cfg = group->cfg;
517 apr_pool_t *rec_pool, *prepared_pool;
518 ap_dbd_t *rec;
519 apr_status_t rv;
520 const char *err = "";
521
522 rv = apr_pool_create(&rec_pool, pool);
523 if (rv != APR_SUCCESS) {
524 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, cfg->server, APLOGNO(00624)
525 "Failed to create memory pool");
526 return rv;
527 }
528 apr_pool_tag(rec_pool, "dbd_rec_pool");
529
530 rec = apr_pcalloc(rec_pool, sizeof(ap_dbd_t));
531
532 rec->pool = rec_pool;
533
534 /* The driver is loaded at config time now, so this just checks a hash.
535 * If that changes, the driver DSO could be registered to unload against
536 * our pool, which is probably not what we want. Error checking isn't
537 * necessary now, but in case that changes in the future ...
538 */
539 rv = apr_dbd_get_driver(rec->pool, cfg->name, &rec->driver);
540 if (rv != APR_SUCCESS) {
541 if (APR_STATUS_IS_ENOTIMPL(rv)) {
542 ap_log_error(APLOG_MARK, APLOG_ERR, rv, cfg->server, APLOGNO(00625)
543 "driver for %s not available", cfg->name);
544 }
545 else if (APR_STATUS_IS_EDSOOPEN(rv)) {
546 ap_log_error(APLOG_MARK, APLOG_ERR, rv, cfg->server, APLOGNO(00626)
547 "can't find driver for %s", cfg->name);
548 }
549 else if (APR_STATUS_IS_ESYMNOTFOUND(rv)) {
550 ap_log_error(APLOG_MARK, APLOG_ERR, rv, cfg->server, APLOGNO(00627)
551 "driver for %s is invalid or corrupted",
552 cfg->name);
553 }
554 else {
555 ap_log_error(APLOG_MARK, APLOG_ERR, rv, cfg->server, APLOGNO(00628)
556 "mod_dbd not compatible with APR in get_driver");
557 }
558 apr_pool_destroy(rec->pool);
559 return rv;
560 }
561
562 rv = apr_dbd_open_ex(rec->driver, rec->pool, cfg->params, &rec->handle, &err);
563 if (rv != APR_SUCCESS) {
564 switch (rv) {
565 case APR_EGENERAL:
566 ap_log_error(APLOG_MARK, APLOG_ERR, rv, cfg->server, APLOGNO(00629)
567 "Can't connect to %s: %s", cfg->name, err);
568 break;
569 default:

Callers 1

ap_dbd_openFunction · 0.85

Calls 2

dbd_prepared_initFunction · 0.85
ap_log_errorFunction · 0.50

Tested by

no test coverage detected