if (pSD == NULL || sa == NULL) {
return NULL;
}
+ apr_set_os_error(0);
if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)
- || GetLastError()) {
+ || apr_get_os_error()) {
LocalFree( pSD );
LocalFree( sa );
return NULL;
}
if (!SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE)
- || GetLastError()) {
+ || apr_get_os_error()) {
LocalFree( pSD );
LocalFree( sa );
return NULL;
/* Um, problem, can't signal the parent, which means we can't
* signal ourselves to die. Ignore for now...
*/
- ap_log_error(APLOG_MARK, APLOG_EMERG, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_EMERG, apr_get_os_error(), server_conf,
"OpenEvent on %s event", signal_name);
return;
}
if (SetEvent(e) == 0) {
/* Same problem as above */
- ap_log_error(APLOG_MARK, APLOG_EMERG, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_EMERG, apr_get_os_error(), server_conf,
"SetEvent on %s event", signal_name);
CloseHandle(e);
return;
for (lr = ap_listeners; lr; lr = lr->next) {
if (!ReadFile(pipe, &WSAProtocolInfo, sizeof(WSAPROTOCOL_INFO),
&BytesRead, (LPOVERLAPPED) NULL)) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), server_conf,
"setup_inherited_listeners: Unable to read socket data from parent");
signal_parent(0); /* tell parent to die */
exit(1);
nsd = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
&WSAProtocolInfo, 0, 0);
if (nsd == INVALID_SOCKET) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, WSAGetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_netos_error(), server_conf,
"Child %d: setup_inherited_listeners(), WSASocket failed to open the inherited socket.", my_pid);
signal_parent(0); /* tell parent to die */
exit(1);
/* allocate the completion context and the transaction pool */
context = apr_pcalloc(pconf, sizeof(COMP_CONTEXT));
if (!context) {
- ap_log_error(APLOG_MARK,APLOG_ERR, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK,APLOG_ERR, apr_get_os_error(), server_conf,
"win9x_get_connection: apr_pcalloc() failed. Process will exit.");
return NULL;
}
context->sa_server = apr_palloc(context->ptrans, len);
if (getsockname(context->accept_socket,
context->sa_server, &len)== SOCKET_ERROR) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, WSAGetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_netos_error(), server_conf,
"getsockname failed");
continue;
}
context->sa_client = apr_palloc(context->ptrans, len);
if ((getpeername(context->accept_socket,
context->sa_client, &len)) == SOCKET_ERROR) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, WSAGetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_netos_error(), server_conf,
"getpeername failed");
memset(&context->sa_client, '\0', sizeof(context->sa_client));
}
rc = GetQueuedCompletionStatus(hComplPort, &BytesRead, &CompKey,
&pol, 1000);
if (!rc) {
- rc = GetLastError();
- if (rc == ERROR_OPERATION_ABORTED) {
+ rc = apr_get_os_error();
+ if (rc == APR_FROM_OS_ERROR(ERROR_OPERATION_ABORTED)) {
ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, server_conf,
"Child %d: - Draining an ABORTED packet off "
"the AcceptEx completion port.", my_pid);
/* allocate the completion context */
context = apr_pcalloc(_pconf, sizeof(COMP_CONTEXT));
if (!context) {
- ap_log_error(APLOG_MARK,APLOG_ERR, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK,APLOG_ERR, apr_get_os_error(), server_conf,
"create_acceptex_context: apr_pcalloc() failed. Process will exit.");
return -1;
}
context->lr = lr;
context->Overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (context->Overlapped.hEvent == NULL) {
- ap_log_error(APLOG_MARK,APLOG_ERR, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK,APLOG_ERR, apr_get_os_error(), server_conf,
"create_acceptex_context: CreateEvent() failed. Process will exit.");
return -1;
}
apr_get_os_sock(&nsd, context->lr->sd);
context->accept_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (context->accept_socket == INVALID_SOCKET) {
- ap_log_error(APLOG_MARK,APLOG_ERR, WSAGetLastError(), server_conf,
+ ap_log_error(APLOG_MARK,APLOG_ERR, apr_get_netos_error(), server_conf,
"create_acceptex_context: socket() failed. Process will exit.");
return -1;
}
if (setsockopt(context->accept_socket, SOL_SOCKET,
SO_UPDATE_ACCEPT_CONTEXT, (char *)&nsd,
sizeof(nsd))) {
- ap_log_error(APLOG_MARK, APLOG_ERR, WSAGetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_netos_error(), server_conf,
"setsockopt(SO_UPDATE_ACCEPT_CONTEXT) failed.");
/* Not a failure condition. Keep running. */
}
PADDED_ADDR_SIZE, PADDED_ADDR_SIZE,
&BytesRead,
(LPOVERLAPPED) context)) {
- lasterror = WSAGetLastError();
- if (lasterror != ERROR_IO_PENDING) {
- ap_log_error(APLOG_MARK,APLOG_ERR, WSAGetLastError(), server_conf,
+ lasterror = apr_get_netos_error();
+ if (lasterror != APR_FROM_OS_ERROR(ERROR_IO_PENDING)) {
+ ap_log_error(APLOG_MARK,APLOG_ERR, lasterror, server_conf,
"create_acceptex_context: AcceptEx failed. Process will exit.");
return -1;
}
if (context->accept_socket == INVALID_SOCKET) {
context->accept_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (context->accept_socket == INVALID_SOCKET) {
- rc = WSAGetLastError();
+ rc = apr_get_netos_error();
ap_log_error(APLOG_MARK,APLOG_ERR, rc, server_conf,
"reset_acceptex_context: socket() failed. Process will exit.");
return rc;
/* SO_UPDATE_ACCEPT_CONTEXT is required for shutdown() to work */
if (setsockopt(context->accept_socket, SOL_SOCKET,
SO_UPDATE_ACCEPT_CONTEXT, (char *)&nsd, sizeof(nsd))) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, WSAGetLastError(),
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_netos_error(),
server_conf,
"setsockopt(SO_UPDATE_ACCEPT_CONTEXT) failed.");
}
if (!AcceptEx(nsd, context->accept_socket, context->recv_buf, 0,
PADDED_ADDR_SIZE, PADDED_ADDR_SIZE, &BytesRead,
(LPOVERLAPPED) context)) {
- rc = WSAGetLastError();
- if (rc != ERROR_IO_PENDING) {
+ rc = apr_get_netos_error();
+ if (rc != APR_FROM_OS_ERROR(ERROR_IO_PENDING)) {
ap_log_error(APLOG_MARK, APLOG_INFO, rc, server_conf,
"reset_acceptex_context: AcceptEx failed for "
"listening socket: %d and accept socket: %d",
rc = GetQueuedCompletionStatus(AcceptExCompPort, &BytesRead, &CompKey,
&pol, INFINITE);
if (!rc) {
- rc = GetLastError();
- if (rc != ERROR_OPERATION_ABORTED) {
+ rc = apr_get_os_error();
+ if (rc != APR_FROM_OS_ERROR(ERROR_OPERATION_ABORTED)) {
/* Is this a deadly condition?
* We sometimes get ERROR_NETNAME_DELETED when a client
* disconnects when attempting to reuse sockets. Not sure why
for (lr = ap_listeners; lr != NULL; lr = lr->next) {
while (lr->count < NUM_LISTENERS) {
if (create_acceptex_context(pconf, lr) == -1) {
- ap_log_error(APLOG_MARK,APLOG_ERR, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK,APLOG_ERR, apr_get_os_error(), server_conf,
"Unable to create an AcceptEx completion context -- process will exit");
signal_parent(0); /* tell parent to die */
}
cld = rv - WAIT_OBJECT_0;
if (rv == WAIT_FAILED) {
/* Something serious is wrong */
- ap_log_error(APLOG_MARK, APLOG_CRIT, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), server_conf,
"Child %d: WAIT_FAILED -- shutting down server");
break;
}
"Parent: Path to Apache process too long");
return -1;
} else if (rv == 0) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), server_conf,
"Parent: GetModuleFileName() returned NULL for current process.");
return -1;
}
pEnvVar = '\0';
/* Create a pipe to send socket info to the child */
if (!CreatePipe(&hPipeRead, &hPipeWrite, &sa, 0)) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), server_conf,
"Parent: Unable to create pipe to child process.");
return -1;
}
pEnvBlock, /* Environment block */
NULL,
&si, &pi)) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), server_conf,
"Parent: Not able to create the child process.");
/*
* We must close the handles to the new process and its main thread
sa.lpSecurityDescriptor = NULL;
kill_event = CreateEvent(&sa, TRUE, FALSE, apr_psprintf(pconf,"apC%d", pi.dwProcessId));
if (!kill_event) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), server_conf,
"Parent: Could not create exit event for child process");
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
if (!WriteFile(hPipeWrite, lpWSAProtocolInfo, (DWORD) sizeof(WSAPROTOCOL_INFO),
&BytesWritten,
(LPOVERLAPPED) NULL)) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), server_conf,
"Parent: Unable to write duplicated socket %d to the child.", lr->sd );
return -1;
}
if (!DuplicateHandle(GetCurrentProcess(), AcceptExCompPort,
pi.hProcess, &hDupedCompPort, 0,
TRUE, DUPLICATE_SAME_ACCESS)) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), server_conf,
"Parent: Unable to duplicate AcceptEx completion port. Shutting down.");
return -1;
}
while (remaining_children_to_start--) {
if (create_process(pconf, process_handles, process_kill_events,
¤t_live_processes) < 0) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), server_conf,
"master_main: create child process failed. Exiting.");
shutdown_pending = 1;
goto die_now;
cld = rv - WAIT_OBJECT_0;
if (rv == WAIT_FAILED) {
/* Something serious is wrong */
- ap_log_error(APLOG_MARK,APLOG_CRIT, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK,APLOG_CRIT, apr_get_os_error(), server_conf,
"master_main: WaitForMultipeObjects WAIT_FAILED -- doing server shutdown");
shutdown_pending = 1;
}
else if (rv == WAIT_TIMEOUT) {
/* Hey, this cannot happen */
- ap_log_error(APLOG_MARK, APLOG_ERR, GetLastError(), s,
+ ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), s,
"master_main: WaitForMultipeObjects with INFINITE wait exited with WAIT_TIMEOUT");
shutdown_pending = 1;
}
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, APR_SUCCESS, s,
"master_main: Shutdown event signaled -- doing server shutdown.");
if (ResetEvent(shutdown_event) == 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, GetLastError(), s,
+ ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), s,
"ResetEvent(shutdown_event)");
}
ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, s,
"master_main: Restart event signaled. Doing a graceful restart.");
if (ResetEvent(restart_event) == 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, GetLastError(), s,
+ ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), s,
"master_main: ResetEvent(restart_event) failed.");
}
/* Signal each child process to die
*/
for (i = 0; i < children_to_kill; i++) {
if (SetEvent(process_kill_events[i]) == 0)
- ap_log_error(APLOG_MARK, APLOG_ERR, GetLastError(), s,
+ ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), s,
"master_main: SetEvent for child process in slot #%d failed", i);
cleanup_process(process_handles, process_kill_events, i, ¤t_live_processes);
}
for (i = 0; i < current_live_processes; i++) {
printf("SetEvent handle = %d\n", process_kill_events[i]);
if (SetEvent(process_kill_events[i]) == 0)
- ap_log_error(APLOG_MARK,APLOG_ERR, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK,APLOG_ERR, apr_get_os_error(), server_conf,
"master_main: SetEvent for child process in slot #%d failed", i);
}
/* WARNING: There is an implict assumption here that the
* executable resides in the ServerRoot!
*/
- rv = GetLastError();
+ rv = apr_get_os_error();
ap_log_error(APLOG_MARK,APLOG_ERR, rv, NULL,
"Failed to get the running module's file name");
exit(1);
0,
0); /* CONCURRENT ACTIVE THREADS */
if (AcceptExCompPort == NULL) {
- ap_log_error(APLOG_MARK,APLOG_ERR, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK,APLOG_ERR, apr_get_os_error(), server_conf,
"Parent: Unable to create the AcceptExCompletionPort -- process will exit");
exit(1);
}
*/
shutdown_event = CreateEvent(sa, FALSE, FALSE, signal_shutdown_name);
if (!shutdown_event) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_EMERG, apr_get_os_error(), server_conf,
"Parent: Cannot create shutdown event %s", signal_shutdown_name);
CleanNullACL((void *)sa);
exit(1);
restart_event = CreateEvent(sa, FALSE, FALSE, signal_restart_name);
if (!restart_event) {
CloseHandle(shutdown_event);
- ap_log_error(APLOG_MARK, APLOG_EMERG, GetLastError(), server_conf,
+ ap_log_error(APLOG_MARK, APLOG_EMERG, apr_get_os_error(), server_conf,
"Parent: Cannot create restart event %s", signal_restart_name);
CleanNullACL((void *)sa);
exit(1);
if (!RegisterClass(&wc))
{
- ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, GetLastError(),
+ ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, apr_get_os_error(),
NULL, "Could not register window class for WatchWindow");
SetEvent(globdat.signal_monitor);
globdat.service_thread_id = 0;
if (!hwndMain)
{
- ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, GetLastError(),
+ ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, apr_get_os_error(),
NULL, "Could not create WatchWindow");
SetEvent(globdat.signal_monitor);
globdat.service_thread_id = 0;
if(!(globdat.hServiceStatus = RegisterServiceCtrlHandler(argv[0], service_nt_ctrl)))
{
- ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, GetLastError(),
+ ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, apr_get_os_error(),
NULL, "Failure registering service handler");
PulseEvent(globdat.signal_monitor);
return;
if (!StartServiceCtrlDispatcher(dispatchTable))
{
/* This is a genuine failure of the SCM. */
- rv = GetLastError();
+ rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"Error starting service control dispatcher");
}
if (GetModuleFileName(NULL, exe_path, sizeof(exe_path)) == 0)
{
- apr_status_t rv = GetLastError();
+ apr_status_t rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"GetModuleFileName failed");
return rv;
schSCManager = OpenSCManager(NULL, NULL, /* local, default database */
SC_MANAGER_ALL_ACCESS);
if (!schSCManager) {
- rv = GetLastError();
+ rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"Failed to open the WinNT service manager");
return (rv);
if (!schService)
{
- rv = GetLastError();
+ rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"Failed to create WinNT Service Profile");
CloseServiceHandle(schSCManager);
schSCManager = OpenSCManager(NULL, NULL, /* local, default database */
SC_MANAGER_ALL_ACCESS);
if (!schSCManager) {
- rv = GetLastError();
+ rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"Failed to open the WinNT service manager.");
return (rv);
schService = OpenService(schSCManager, service_name, SERVICE_ALL_ACCESS);
if (!schService) {
- rv = GetLastError();
+ rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"%s: OpenService failed", display_name);
return (rv);
// ap_stop_service(schService);
if (DeleteService(schService) == 0) {
- rv = GetLastError();
+ rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"%s: Failed to delete the service.", display_name);
return (rv);
/* TODO: assure the service is stopped before continuing */
if (ap_registry_delete_value(SERVICECONFIG9X, service_name)) {
- rv = GetLastError();
+ rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"%s: Failed to remove the RunServices registry "
"entry.", display_name);
apr_snprintf(key_name, sizeof(key_name), SERVICECONFIG, service_name);
if (ap_registry_delete_key(key_name))
{
- rv = GetLastError();
+ rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"%s: Failed to remove the service config from the "
"registry.", display_name);
schSCManager = OpenSCManager(NULL, NULL, /* local, default database */
SC_MANAGER_ALL_ACCESS);
if (!schSCManager) {
- rv = GetLastError();
+ rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"Failed to open the WinNT service manager");
return (rv);
schService = OpenService(schSCManager, service_name,
SERVICE_START | SERVICE_QUERY_STATUS);
if (!schService) {
- rv = GetLastError();
+ rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"%s: Failed to open the service.", display_name);
CloseServiceHandle(schSCManager);
rv = APR_SUCCESS;
if (rv != APR_SUCCESS)
- rv = GetLastError();
+ rv = apr_get_os_error();
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
if (GetModuleFileName(NULL, exe_path, sizeof(exe_path)) == 0)
{
- apr_status_t rv = GetLastError();
+ apr_status_t rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"GetModuleFileName failed");
return rv;
}
if (rv != APR_SUCCESS)
- rv = GetLastError();
+ rv = apr_get_os_error();
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
SC_MANAGER_ALL_ACCESS);
if (!schSCManager) {
- ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, GetLastError(), NULL,
+ ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, apr_get_os_error(), NULL,
"Failed to open the NT Service Manager");
return;
}
if (schService == NULL) {
/* Could not open the service */
- ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, GetLastError(), NULL,
+ ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, apr_get_os_error(), NULL,
"Failed to open the %s Service", display_name);
CloseServiceHandle(schSCManager);
return;
}
if (!QueryServiceStatus(schService, &globdat.ssStatus)) {
- ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, GetLastError(), NULL,
+ ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, apr_get_os_error(), NULL,
"Query of Service %s failed", display_name);
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);