From: Iain Patterson Date: Sat, 23 Nov 2013 15:43:59 +0000 (+0000) Subject: Fixed bug when installing from the command line. X-Git-Tag: v2.20~1 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=470de9224d9473853d24006d7ae13eba818ecf0f;p=nssm.git Fixed bug when installing from the command line. We forgot to set default values when installing from the command line. Installing from the GUI worked. Thanks Paul Spause. --- diff --git a/ChangeLog.txt b/ChangeLog.txt index e7cff08..08188a6 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,9 @@ +Changes since 2.19 +----------------- + * Services installed from the commandline without using the + GUI no longer have incorrect AppStopMethod* registry + entries set. + Changes since 2.18 ----------------- * Support AppEnvironmentExtra to append to the environment diff --git a/README.txt b/README.txt index bc18637..f218e83 100644 --- a/README.txt +++ b/README.txt @@ -323,6 +323,7 @@ Thanks to Eric Cheldelin for the inspiration to generate a Control-C event on shutdown. Thanks to Brian Baxter for suggesting how to escape quotes from the command prompt. Thanks to Russ Holmann for suggesting that the shutdown timeout be configurable. +Thanks to Paul Spause for spotting a bug with default registry entries. Licence ------- diff --git a/gui.cpp b/gui.cpp index 7cc5bc4..ca21ace 100644 --- a/gui.cpp +++ b/gui.cpp @@ -87,6 +87,8 @@ int install(HWND window) { nssm_service_t *service = alloc_nssm_service(); if (service) { + set_nssm_service_defaults(service); + /* Get service name. */ if (! GetDlgItemText(window, IDC_NAME, service->name, sizeof(service->name))) { popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_SERVICE_NAME); @@ -115,7 +117,6 @@ int install(HWND window) { } /* Get stop method stuff. */ - service->stop_method = ~0; check_stop_method(service, NSSM_STOP_METHOD_CONSOLE, IDC_METHOD_CONSOLE); check_stop_method(service, NSSM_STOP_METHOD_WINDOW, IDC_METHOD_WINDOW); check_stop_method(service, NSSM_STOP_METHOD_THREADS, IDC_METHOD_THREADS); @@ -134,16 +135,6 @@ int install(HWND window) { check_io("stdin", service->stdin_path, sizeof(service->stdin_path), IDC_STDIN); check_io("stdout", service->stdout_path, sizeof(service->stdout_path), IDC_STDOUT); check_io("stderr", service->stderr_path, sizeof(service->stderr_path), IDC_STDERR); - /* I/O defaults. */ - service->stdin_sharing = NSSM_STDIN_SHARING; - service->stdin_disposition = NSSM_STDIN_DISPOSITION; - service->stdin_flags = NSSM_STDIN_FLAGS; - service->stdout_sharing = NSSM_STDOUT_SHARING; - service->stdout_disposition = NSSM_STDOUT_DISPOSITION; - service->stdout_flags = NSSM_STDOUT_FLAGS; - service->stderr_sharing = NSSM_STDERR_SHARING; - service->stderr_disposition = NSSM_STDERR_DISPOSITION; - service->stderr_flags = NSSM_STDERR_FLAGS; /* Override stdout and/or stderr. */ if (SendDlgItemMessage(tablist[NSSM_TAB_IO], IDC_TRUNCATE, BM_GETCHECK, 0, 0) & BST_CHECKED) { if (service->stdout_path[0]) service->stdout_disposition = CREATE_ALWAYS; diff --git a/service.cpp b/service.cpp index 077c1e8..0a95ccf 100644 --- a/service.cpp +++ b/service.cpp @@ -32,6 +32,26 @@ SC_HANDLE open_service_manager() { return ret; } +/* Set default values which aren't zero. */ +void set_nssm_service_defaults(nssm_service_t *service) { + if (! service) return; + + service->stdin_sharing = NSSM_STDIN_SHARING; + service->stdin_disposition = NSSM_STDIN_DISPOSITION; + service->stdin_flags = NSSM_STDIN_FLAGS; + service->stdout_sharing = NSSM_STDOUT_SHARING; + service->stdout_disposition = NSSM_STDOUT_DISPOSITION; + service->stdout_flags = NSSM_STDOUT_FLAGS; + service->stderr_sharing = NSSM_STDERR_SHARING; + service->stderr_disposition = NSSM_STDERR_DISPOSITION; + service->stderr_flags = NSSM_STDERR_FLAGS; + service->throttle_delay = NSSM_RESET_THROTTLE_RESTART; + service->stop_method = ~0; + service->kill_console_delay = NSSM_KILL_CONSOLE_GRACE_PERIOD; + service->kill_window_delay = NSSM_KILL_WINDOW_GRACE_PERIOD; + service->kill_threads_delay = NSSM_KILL_THREADS_GRACE_PERIOD; +} + /* Allocate and zero memory for a service. */ nssm_service_t *alloc_nssm_service() { nssm_service_t *service = (nssm_service_t *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(nssm_service_t)); @@ -63,6 +83,7 @@ int pre_install_service(int argc, char **argv) { return 1; } + set_nssm_service_defaults(service); memmove(service->name, argv[0], strlen(argv[0])); memmove(service->exe, argv[1], strlen(argv[1])); diff --git a/service.h b/service.h index 9c596f1..bb44a41 100644 --- a/service.h +++ b/service.h @@ -67,6 +67,7 @@ void log_service_control(char *, unsigned long, bool); unsigned long WINAPI service_control_handler(unsigned long, unsigned long, void *, void *); nssm_service_t *alloc_nssm_service(); +void set_nssm_service_defaults(nssm_service_t *); void cleanup_nssm_service(nssm_service_t *); SC_HANDLE open_service_manager(); int pre_install_service(int, char **);