| 1330 | } |
| 1331 | |
| 1332 | PROXY_DECLARE(apr_status_t) ap_proxy_initialize_balancer(proxy_balancer *balancer, server_rec *s, apr_pool_t *p) |
| 1333 | { |
| 1334 | #if APR_HAS_THREADS |
| 1335 | apr_status_t rv = APR_SUCCESS; |
| 1336 | #endif |
| 1337 | ap_slotmem_provider_t *storage = balancer->storage; |
| 1338 | apr_size_t size; |
| 1339 | unsigned int num; |
| 1340 | |
| 1341 | if (!storage) { |
| 1342 | ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, APLOGNO(00918) |
| 1343 | "no provider for %s", balancer->s->name); |
| 1344 | return APR_EGENERAL; |
| 1345 | } |
| 1346 | /* |
| 1347 | * for each balancer we need to init the global |
| 1348 | * mutex and then attach to the shared worker shm |
| 1349 | */ |
| 1350 | if (!balancer->gmutex) { |
| 1351 | ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, APLOGNO(00919) |
| 1352 | "no mutex %s", balancer->s->name); |
| 1353 | return APR_EGENERAL; |
| 1354 | } |
| 1355 | |
| 1356 | /* Re-open the mutex for the child. */ |
| 1357 | rv = apr_global_mutex_child_init(&(balancer->gmutex), |
| 1358 | apr_global_mutex_lockfile(balancer->gmutex), |
| 1359 | p); |
| 1360 | if (rv != APR_SUCCESS) { |
| 1361 | ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, APLOGNO(00920) |
| 1362 | "Failed to reopen mutex %s in child", |
| 1363 | balancer->s->name); |
| 1364 | return rv; |
| 1365 | } |
| 1366 | |
| 1367 | /* now attach */ |
| 1368 | storage->attach(&(balancer->wslot), balancer->s->sname, &size, &num, p); |
| 1369 | if (!balancer->wslot) { |
| 1370 | ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, APLOGNO(00921) "slotmem_attach failed"); |
| 1371 | return APR_EGENERAL; |
| 1372 | } |
| 1373 | |
| 1374 | #if APR_HAS_THREADS |
| 1375 | if (balancer->tmutex == NULL) { |
| 1376 | rv = apr_thread_mutex_create(&(balancer->tmutex), APR_THREAD_MUTEX_DEFAULT, p); |
| 1377 | if (rv != APR_SUCCESS) { |
| 1378 | ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, APLOGNO(00922) |
| 1379 | "can not create balancer thread mutex"); |
| 1380 | return rv; |
| 1381 | } |
| 1382 | } |
| 1383 | #endif |
| 1384 | return APR_SUCCESS; |
| 1385 | } |
| 1386 | |
| 1387 | static proxy_worker *proxy_balancer_get_best_worker(proxy_balancer *balancer, |
| 1388 | request_rec *r, |
no test coverage detected