Added fake NSSM_SERVICE_CONTROL_START constant.
authorIain Patterson <me@iain.cx>
Mon, 13 Jan 2014 09:33:30 +0000 (09:33 +0000)
committerIain Patterson <me@iain.cx>
Mon, 13 Jan 2014 11:04:59 +0000 (11:04 +0000)
There's no SERVICE_CONTROL_START constant so we were explicitly checking
for a fake control code of 0 when handling service start.  Now that we
have defined a custom control code (NSSM_SERVICE_CONTROL_ROTATE) we can
add NSSM_SERVICE_CONTROL_START for readability and consistency.

nssm.cpp
nssm.h
service.cpp

index 498a213..37f3aea 100644 (file)
--- a/nssm.cpp
+++ b/nssm.cpp
@@ -103,7 +103,7 @@ int _tmain(int argc, TCHAR **argv) {
       Valid commands are:\r
       start, stop, pause, continue, install, edit, get, set, reset, unset, remove\r
     */\r
-    if (str_equiv(argv[1], _T("start"))) exit(control_service(0, argc - 2, argv + 2));\r
+    if (str_equiv(argv[1], _T("start"))) exit(control_service(NSSM_SERVICE_CONTROL_START, argc - 2, argv + 2));\r
     if (str_equiv(argv[1], _T("stop"))) exit(control_service(SERVICE_CONTROL_STOP, argc - 2, argv + 2));\r
     if (str_equiv(argv[1], _T("pause"))) exit(control_service(SERVICE_CONTROL_PAUSE, argc - 2, argv + 2));\r
     if (str_equiv(argv[1], _T("continue"))) exit(control_service(SERVICE_CONTROL_CONTINUE, argc - 2, argv + 2));\r
diff --git a/nssm.h b/nssm.h
index 79c2065..8e82d59 100644 (file)
--- a/nssm.h
+++ b/nssm.h
@@ -96,6 +96,7 @@ int usage(int);
 #define NSSM_SERVICE_STATUS_DEADLINE 20000\r
 \r
 /* User-defined service controls can be in the range 128-255. */\r
+#define NSSM_SERVICE_CONTROL_START 0\r
 #define NSSM_SERVICE_CONTROL_ROTATE 128\r
 \r
 #endif\r
index 8074227..51c3937 100644 (file)
@@ -1059,7 +1059,7 @@ int control_service(unsigned long control, int argc, TCHAR **argv) {
   int ret;\r
   unsigned long error;\r
   SERVICE_STATUS service_status;\r
-  if (control == 0) {\r
+  if (control == NSSM_SERVICE_CONTROL_START) {\r
     ret = StartService(service_handle, (unsigned long) argc, (const TCHAR **) argv);\r
     error = GetLastError();\r
     CloseHandle(service_handle);\r
@@ -1281,7 +1281,7 @@ int monitor_service(nssm_service_t *service) {
 TCHAR *service_control_text(unsigned long control) {\r
   switch (control) {\r
     /* HACK: there is no SERVICE_CONTROL_START constant */\r
-    case 0: return _T("START");\r
+    case NSSM_SERVICE_CONTROL_START: return _T("START");\r
     case SERVICE_CONTROL_STOP: return _T("STOP");\r
     case SERVICE_CONTROL_SHUTDOWN: return _T("SHUTDOWN");\r
     case SERVICE_CONTROL_PAUSE: return _T("PAUSE");\r