static process_rec *init_process(int *argc, const char * const * *argv) { process_rec *process; apr_pool_t *cntx; apr_status_t stat; const char *failed = "apr_app_initialize()"; stat = apr_app_initialize(argc, argv, NULL); if (stat == APR_SUCCESS) { failed = "apr_pool_create()"; stat = apr_pool_create(&cntx, NULL); } if (stat != APR_SUCCESS) { /* For all intents and purposes, this is impossibly unlikely, * but APR doesn't exist yet, we can't use it for reporting * these earliest two failures; */ char ctimebuff[APR_CTIME_LEN]; apr_ctime(ctimebuff, apr_time_now()); fprintf(stderr, "[%s] [crit] (%d) %s: %s failed " "to initial context, exiting\n", ctimebuff, stat, (*argv)[0], failed); apr_terminate(); exit(1); } apr_pool_tag(cntx, "process"); ap_open_stderr_log(cntx); /* Now we have initialized apr and our logger, no more * exceptional error reporting required for the lifetime * of this server process. */ process = apr_palloc(cntx, sizeof(process_rec)); process->pool = cntx; apr_pool_create(&process->pconf, process->pool); apr_pool_tag(process->pconf, "pconf"); process->argc = *argc; process->argv = *argv; process->short_name = apr_filepath_name_get((*argv)[0]); return process; }
void mpm_nt_eventlog_stderr_open(char *argv0, apr_pool_t *p) { SECURITY_ATTRIBUTES sa; HANDLE hProc = GetCurrentProcess(); HANDLE hPipeRead = NULL; HANDLE hPipeWrite = NULL; HANDLE hDup = NULL; DWORD threadid; apr_file_t *eventlog_file; apr_file_t *stderr_file; display_name = argv0; /* Create a pipe to send stderr messages to the system error log. * * _dup2() duplicates the write handle inheritable for us. */ sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = FALSE; CreatePipe(&hPipeRead, &hPipeWrite, NULL, 0); ap_assert(hPipeRead && hPipeWrite); stderr_ready = CreateEvent(NULL, FALSE, FALSE, NULL); stderr_thread = CreateThread(NULL, 0, service_stderr_thread, (LPVOID) hPipeRead, 0, &threadid); ap_assert(stderr_ready && stderr_thread); WaitForSingleObject(stderr_ready, INFINITE); if ((apr_file_open_stderr(&stderr_file, p) == APR_SUCCESS) && (apr_os_file_put(&eventlog_file, &hPipeWrite, APR_WRITE, p) == APR_SUCCESS)) apr_file_dup2(stderr_file, eventlog_file, p); /* The code above _will_ corrupt the StdHandle... * and we must do so anyways. We set this up only * after we initialized the posix stderr API. */ ap_open_stderr_log(p); }