* Create an already defined balancer and free up memory. */
| 1283 | * Create an already defined balancer and free up memory. |
| 1284 | */ |
| 1285 | PROXY_DECLARE(apr_status_t) ap_proxy_share_balancer(proxy_balancer *balancer, |
| 1286 | proxy_balancer_shared *shm, |
| 1287 | int i) |
| 1288 | { |
| 1289 | apr_status_t rv = APR_SUCCESS; |
| 1290 | proxy_balancer_method *lbmethod; |
| 1291 | char *action = "copying"; |
| 1292 | if (!shm || !balancer->s) |
| 1293 | return APR_EINVAL; |
| 1294 | |
| 1295 | if ((balancer->s->hash.def != shm->hash.def) || |
| 1296 | (balancer->s->hash.fnv != shm->hash.fnv)) { |
| 1297 | memcpy(shm, balancer->s, sizeof(proxy_balancer_shared)); |
| 1298 | if (balancer->s->was_malloced) |
| 1299 | free(balancer->s); |
| 1300 | } else { |
| 1301 | action = "re-using"; |
| 1302 | } |
| 1303 | balancer->s = shm; |
| 1304 | balancer->s->index = i; |
| 1305 | ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02337) |
| 1306 | "%s shm[%d] (0x%pp) for %s", action, i, (void *)shm, |
| 1307 | balancer->s->name); |
| 1308 | /* the below should always succeed */ |
| 1309 | lbmethod = ap_lookup_provider(PROXY_LBMETHOD, balancer->s->lbpname, "0"); |
| 1310 | if (lbmethod) { |
| 1311 | balancer->lbmethod = lbmethod; |
| 1312 | balancer->lbmethod_set = 1; |
| 1313 | } else { |
| 1314 | ap_log_error(APLOG_MARK, APLOG_CRIT, 0, ap_server_conf, APLOGNO(02432) |
| 1315 | "Cannot find LB Method: %s", balancer->s->lbpname); |
| 1316 | return APR_EINVAL; |
| 1317 | } |
| 1318 | if (*balancer->s->nonce == PROXY_UNSET_NONCE) { |
| 1319 | char nonce[APR_UUID_FORMATTED_LENGTH + 1]; |
| 1320 | apr_uuid_t uuid; |
| 1321 | |
| 1322 | /* Generate a pseudo-UUID from the PRNG to use as a nonce for |
| 1323 | * the lifetime of the process. uuid.data is a char array so |
| 1324 | * this is an adequate substitute for apr_uuid_get(). */ |
| 1325 | ap_random_insecure_bytes(uuid.data, sizeof uuid.data); |
| 1326 | apr_uuid_format(nonce, &uuid); |
| 1327 | rv = PROXY_STRNCPY(balancer->s->nonce, nonce); |
| 1328 | } |
| 1329 | return rv; |
| 1330 | } |
| 1331 | |
| 1332 | PROXY_DECLARE(apr_status_t) ap_proxy_initialize_balancer(proxy_balancer *balancer, server_rec *s, apr_pool_t *p) |
| 1333 | { |
no test coverage detected