| 72 | |
| 73 | |
| 74 | void WINAPI CNTL_main_thread( DWORD /*argc*/, char* /*argv*/[]) |
| 75 | { |
| 76 | /************************************** |
| 77 | * |
| 78 | * C N T L _ m a i n _ t h r e a d |
| 79 | * |
| 80 | ************************************** |
| 81 | * |
| 82 | * Functional description |
| 83 | * |
| 84 | **************************************/ |
| 85 | service_handle = RegisterServiceCtrlHandler(service_name->c_str(), control_thread); |
| 86 | if (!service_handle) |
| 87 | return; |
| 88 | |
| 89 | // start everything, and wait here for ever, or at |
| 90 | // least until we get the stop event indicating that |
| 91 | // the service is stoping. |
| 92 | |
| 93 | bool failure = true; |
| 94 | DWORD temp = 0; |
| 95 | if (report_status(SERVICE_START_PENDING, NO_ERROR, 1, 3000) && |
| 96 | (stop_event_handle = CreateEvent(NULL, TRUE, FALSE, NULL)) != NULL && |
| 97 | report_status(SERVICE_START_PENDING, NO_ERROR, 2, 3000)) |
| 98 | { |
| 99 | try |
| 100 | { |
| 101 | Thread::start(main_handler, NULL, THREAD_medium); |
| 102 | if (report_status(SERVICE_RUNNING, NO_ERROR, 0, 0)) |
| 103 | { |
| 104 | failure = false; |
| 105 | temp = WaitForSingleObject(stop_event_handle, INFINITE); |
| 106 | } |
| 107 | } |
| 108 | catch (const Firebird::Exception& ex) |
| 109 | { |
| 110 | iscLogException("CNTL: cannot start service handler thread", ex); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | DWORD last_error = 0; |
| 115 | if (failure || temp == WAIT_FAILED) |
| 116 | last_error = GetLastError(); |
| 117 | |
| 118 | if (stop_event_handle) |
| 119 | CloseHandle(stop_event_handle); |
| 120 | |
| 121 | // Once we are stopped, we will tell the server to |
| 122 | // do the same. We could not do this in the control_thread |
| 123 | // since the Services Control Manager is single threaded, |
| 124 | // and thus can only process one request at the time. |
| 125 | SERVICE_STATUS status_info; |
| 126 | SC_HANDLE hScManager = 0, hService = 0; |
| 127 | hScManager = OpenSCManager(NULL, NULL, GENERIC_READ); |
| 128 | hService = OpenService(hScManager, remote_name->c_str(), GENERIC_READ | GENERIC_EXECUTE); |
| 129 | ControlService(hService, SERVICE_CONTROL_STOP, &status_info); |
| 130 | CloseServiceHandle(hScManager); |
| 131 | CloseServiceHandle(hService); |
nothing calls this directly
no test coverage detected