ToDo: This function should be made to handle setting up * a scoreboard shared between processes using any IPC technique, * not just a shared memory segment */
| 206 | * not just a shared memory segment |
| 207 | */ |
| 208 | static apr_status_t open_scoreboard(apr_pool_t *pconf) |
| 209 | { |
| 210 | #if APR_HAS_SHARED_MEMORY |
| 211 | apr_status_t rv; |
| 212 | char *fname = NULL; |
| 213 | apr_pool_t *global_pool; |
| 214 | |
| 215 | /* We don't want to have to recreate the scoreboard after |
| 216 | * restarts, so we'll create a global pool and never clean it. |
| 217 | */ |
| 218 | rv = apr_pool_create(&global_pool, NULL); |
| 219 | if (rv != APR_SUCCESS) { |
| 220 | ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, APLOGNO(00002) |
| 221 | "Fatal error: unable to create global pool " |
| 222 | "for use by the scoreboard"); |
| 223 | return rv; |
| 224 | } |
| 225 | |
| 226 | /* The config says to create a name-based shmem */ |
| 227 | if (ap_scoreboard_fname) { |
| 228 | /* make sure it's an absolute pathname */ |
| 229 | fname = ap_server_root_relative(pconf, ap_scoreboard_fname); |
| 230 | if (!fname) { |
| 231 | ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EBADPATH, ap_server_conf, APLOGNO(00003) |
| 232 | "Fatal error: Invalid Scoreboard path %s", |
| 233 | ap_scoreboard_fname); |
| 234 | return APR_EBADPATH; |
| 235 | } |
| 236 | return create_namebased_scoreboard(global_pool, fname); |
| 237 | } |
| 238 | else { /* config didn't specify, we get to choose shmem type */ |
| 239 | rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, NULL, |
| 240 | global_pool); /* anonymous shared memory */ |
| 241 | if ((rv != APR_SUCCESS) && (rv != APR_ENOTIMPL)) { |
| 242 | ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, APLOGNO(00004) |
| 243 | "Unable to create or access scoreboard " |
| 244 | "(anonymous shared memory failure)"); |
| 245 | return rv; |
| 246 | } |
| 247 | /* Make up a filename and do name-based shmem */ |
| 248 | else if (rv == APR_ENOTIMPL) { |
| 249 | /* Make sure it's an absolute pathname */ |
| 250 | ap_scoreboard_fname = DEFAULT_SCOREBOARD; |
| 251 | fname = ap_server_root_relative(pconf, ap_scoreboard_fname); |
| 252 | |
| 253 | return create_namebased_scoreboard(global_pool, fname); |
| 254 | } |
| 255 | } |
| 256 | #endif /* APR_HAS_SHARED_MEMORY */ |
| 257 | return APR_SUCCESS; |
| 258 | } |
| 259 | |
| 260 | /* If detach is non-zero, this is a separate child process, |
| 261 | * if zero, it is a forked child. |
no test coverage detected