| 304 | } |
| 305 | |
| 306 | static process_rec *init_process(int *argc, const char * const * *argv) |
| 307 | { |
| 308 | process_rec *process; |
| 309 | apr_pool_t *cntx; |
| 310 | apr_status_t stat; |
| 311 | const char *failed = "apr_app_initialize()"; |
| 312 | |
| 313 | stat = apr_app_initialize(argc, argv, NULL); |
| 314 | if (stat == APR_SUCCESS) { |
| 315 | failed = "apr_pool_create()"; |
| 316 | stat = apr_pool_create(&cntx, NULL); |
| 317 | } |
| 318 | |
| 319 | if (stat != APR_SUCCESS) { |
| 320 | /* For all intents and purposes, this is impossibly unlikely, |
| 321 | * but APR doesn't exist yet, we can't use it for reporting |
| 322 | * these earliest two failures; |
| 323 | * |
| 324 | * XXX: Note the apr_ctime() and apr_time_now() calls. These |
| 325 | * work, today, against an uninitialized APR, but in the future |
| 326 | * (if they relied on global pools or mutexes, for example) then |
| 327 | * the datestamp logic will need to be replaced. |
| 328 | */ |
| 329 | char ctimebuff[APR_CTIME_LEN]; |
| 330 | apr_ctime(ctimebuff, apr_time_now()); |
| 331 | fprintf(stderr, "[%s] [crit] (%d) %s: %s failed " |
| 332 | "to initial context, exiting\n", |
| 333 | ctimebuff, stat, (*argv)[0], failed); |
| 334 | apr_terminate(); |
| 335 | exit(1); |
| 336 | } |
| 337 | |
| 338 | apr_pool_abort_set(abort_on_oom, cntx); |
| 339 | apr_pool_tag(cntx, "process"); |
| 340 | ap_open_stderr_log(cntx); |
| 341 | |
| 342 | /* Now we have initialized apr and our logger, no more |
| 343 | * exceptional error reporting required for the lifetime |
| 344 | * of this server process. |
| 345 | */ |
| 346 | |
| 347 | process = apr_palloc(cntx, sizeof(process_rec)); |
| 348 | process->pool = cntx; |
| 349 | |
| 350 | process->pconf = NULL; |
| 351 | reset_process_pconf(process); |
| 352 | |
| 353 | process->argc = *argc; |
| 354 | process->argv = *argv; |
| 355 | process->short_name = apr_filepath_name_get((*argv)[0]); |
| 356 | |
| 357 | #if AP_HAS_THREAD_LOCAL |
| 358 | { |
| 359 | apr_status_t rv; |
| 360 | apr_thread_t *thd = NULL; |
| 361 | if ((rv = ap_thread_main_create(&thd, process->pool))) { |
| 362 | char ctimebuff[APR_CTIME_LEN]; |
| 363 | apr_ctime(ctimebuff, apr_time_now()); |
no test coverage detected