}
/* Give the process a chance to die gracefully. */
-int kill_process(char *service_name, unsigned long stop_method, HANDLE process_handle, unsigned long pid, unsigned long exitcode) {
+int kill_process(char *service_name, SERVICE_STATUS_HANDLE service_handle, SERVICE_STATUS *service_status, unsigned long stop_method, HANDLE process_handle, unsigned long pid, unsigned long exitcode) {
/* Shouldn't happen. */
if (! pid) return 1;
if (! process_handle) return 1;
/* Try to send a Control-C event to the console. */
if (stop_method & NSSM_STOP_METHOD_CONSOLE) {
- if (! kill_console(service_name, process_handle, pid)) return 1;
+ if (! kill_console(service_name, service_handle, service_status, process_handle, pid)) return 1;
}
/*
if (stop_method & NSSM_STOP_METHOD_WINDOW) {
EnumWindows((WNDENUMPROC) kill_window, (LPARAM) &k);
if (k.signalled) {
- if (! WaitForSingleObject(process_handle, kill_window_delay)) return 1;
+ if (! await_shutdown(__FUNCTION__, service_name, service_handle, service_status, process_handle, kill_window_delay)) return 1;
}
}
*/
if (stop_method & NSSM_STOP_METHOD_THREADS) {
if (kill_threads(service_name, &k)) {
- if (! WaitForSingleObject(process_handle, kill_threads_delay)) return 1;
+ if (! await_shutdown(__FUNCTION__, service_name, service_handle, service_status, process_handle, kill_threads_delay)) return 1;
}
}
}
/* Simulate a Control-C event to our console (shared with the app). */
-int kill_console(char *service_name, HANDLE process_handle, unsigned long pid) {
+int kill_console(char *service_name, SERVICE_STATUS_HANDLE service_handle, SERVICE_STATUS *service_status, HANDLE process_handle, unsigned long pid) {
unsigned long ret;
/* Check we loaded AttachConsole(). */
}
/* Wait for process to exit. */
- if (WaitForSingleObject(process_handle, kill_console_delay)) return 6;
+ if (await_shutdown(__FUNCTION__, service_name, service_handle, service_status, process_handle, kill_console_delay)) ret = 6;
return ret;
}
-void kill_process_tree(char *service_name, unsigned long stop_method, unsigned long pid, unsigned long exitcode, unsigned long ppid, FILETIME *parent_creation_time, FILETIME *parent_exit_time) {
+void kill_process_tree(char *service_name, SERVICE_STATUS_HANDLE service_handle, SERVICE_STATUS *service_status, unsigned long stop_method, unsigned long pid, unsigned long exitcode, unsigned long ppid, FILETIME *parent_creation_time, FILETIME *parent_exit_time) {
/* Shouldn't happen unless the service failed to start. */
if (! pid) return;
}
/* This is a child of the doomed process so kill it. */
- if (! check_parent(service_name, &pe, pid, parent_creation_time, parent_exit_time)) kill_process_tree(service_name, stop_method, pe.th32ProcessID, exitcode, ppid, parent_creation_time, parent_exit_time);
+ if (! check_parent(service_name, &pe, pid, parent_creation_time, parent_exit_time)) kill_process_tree(service_name, service_handle, service_status, stop_method, pe.th32ProcessID, exitcode, ppid, parent_creation_time, parent_exit_time);
while (true) {
/* Try to get the next process. */
return;
}
- if (! check_parent(service_name, &pe, pid, parent_creation_time, parent_exit_time)) kill_process_tree(service_name, stop_method, pe.th32ProcessID, exitcode, ppid, parent_creation_time, parent_exit_time);
+ if (! check_parent(service_name, &pe, pid, parent_creation_time, parent_exit_time)) kill_process_tree(service_name, service_handle, service_status, stop_method, pe.th32ProcessID, exitcode, ppid, parent_creation_time, parent_exit_time);
}
CloseHandle(snapshot);
char ppid_string[16];
_snprintf_s(ppid_string, sizeof(ppid_string), _TRUNCATE, "%lu", ppid);
log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_KILL_PROCESS_TREE, pid_string, ppid_string, service_name, 0);
- if (! kill_process(service_name, stop_method, process_handle, pid, exitcode)) {
+ if (! kill_process(service_name, service_handle, service_status, stop_method, process_handle, pid, exitcode)) {
/* Maybe it already died. */
unsigned long ret;
if (! GetExitCodeProcess(process_handle, &ret) || ret == STILL_ACTIVE) {
int get_process_exit_time(HANDLE, FILETIME *);
int check_parent(char *, PROCESSENTRY32 *, unsigned long, FILETIME *, FILETIME *);
int CALLBACK kill_window(HWND, LPARAM);
-int kill_threads(char *, kill_t *);
-int kill_console(char *, HANDLE, unsigned long);
-int kill_process(char *, unsigned long, HANDLE, unsigned long, unsigned long);
-void kill_process_tree(char *, unsigned long, unsigned long, unsigned long, unsigned long, FILETIME *, FILETIME *);
+int kill_threads(char *, SERVICE_STATUS_HANDLE, SERVICE_STATUS *, kill_t *);
+int kill_console(char *, SERVICE_STATUS_HANDLE, SERVICE_STATUS *, HANDLE, unsigned long);
+int kill_process(char *, SERVICE_STATUS_HANDLE, SERVICE_STATUS *, unsigned long, HANDLE, unsigned long, unsigned long);
+void kill_process_tree(char *, SERVICE_STATUS_HANDLE, SERVICE_STATUS *, unsigned long, unsigned long, unsigned long, unsigned long, FILETIME *, FILETIME *);
#endif
if (pid) {\r
/* Shut down service */\r
log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_TERMINATEPROCESS, service_name, exe, 0);\r
- kill_process(service_name, stop_method, process_handle, pid, 0);\r
+ kill_process(service_name, service_handle, &service_status, stop_method, process_handle, pid, 0);\r
}\r
else log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_PROCESS_ALREADY_STOPPED, service_name, exe, 0);\r
\r
\r
/* Clean up. */\r
if (exitcode == STILL_ACTIVE) exitcode = 0;\r
- kill_process_tree(service_name, stop_method, pid, exitcode, pid, &creation_time, &exit_time);\r
+ kill_process_tree(service_name, service_handle, &service_status, stop_method, pid, exitcode, pid, &creation_time, &exit_time);\r
\r
/*\r
The why argument is true if our wait timed out or false otherwise.\r