Browse Source

Added fake NSSM_SERVICE_CONTROL_START constant.

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.
Iain Patterson 8 years ago
parent
commit
f1d6394333
3 changed files with 4 additions and 3 deletions
  1. 1 1
      nssm.cpp
  2. 1 0
      nssm.h
  3. 2 2
      service.cpp

+ 1 - 1
nssm.cpp

@@ -103,7 +103,7 @@ int _tmain(int argc, TCHAR **argv) {
       Valid commands are:
       start, stop, pause, continue, install, edit, get, set, reset, unset, remove
     */
-    if (str_equiv(argv[1], _T("start"))) exit(control_service(0, argc - 2, argv + 2));
+    if (str_equiv(argv[1], _T("start"))) exit(control_service(NSSM_SERVICE_CONTROL_START, argc - 2, argv + 2));
     if (str_equiv(argv[1], _T("stop"))) exit(control_service(SERVICE_CONTROL_STOP, argc - 2, argv + 2));
     if (str_equiv(argv[1], _T("pause"))) exit(control_service(SERVICE_CONTROL_PAUSE, argc - 2, argv + 2));
     if (str_equiv(argv[1], _T("continue"))) exit(control_service(SERVICE_CONTROL_CONTINUE, argc - 2, argv + 2));

+ 1 - 0
nssm.h

@@ -96,6 +96,7 @@ int usage(int);
 #define NSSM_SERVICE_STATUS_DEADLINE 20000
 
 /* User-defined service controls can be in the range 128-255. */
+#define NSSM_SERVICE_CONTROL_START 0
 #define NSSM_SERVICE_CONTROL_ROTATE 128
 
 #endif

+ 2 - 2
service.cpp

@@ -1059,7 +1059,7 @@ int control_service(unsigned long control, int argc, TCHAR **argv) {
   int ret;
   unsigned long error;
   SERVICE_STATUS service_status;
-  if (control == 0) {
+  if (control == NSSM_SERVICE_CONTROL_START) {
     ret = StartService(service_handle, (unsigned long) argc, (const TCHAR **) argv);
     error = GetLastError();
     CloseHandle(service_handle);
@@ -1281,7 +1281,7 @@ int monitor_service(nssm_service_t *service) {
 TCHAR *service_control_text(unsigned long control) {
   switch (control) {
     /* HACK: there is no SERVICE_CONTROL_START constant */
-    case 0: return _T("START");
+    case NSSM_SERVICE_CONTROL_START: return _T("START");
     case SERVICE_CONTROL_STOP: return _T("STOP");
     case SERVICE_CONTROL_SHUTDOWN: return _T("SHUTDOWN");
     case SERVICE_CONTROL_PAUSE: return _T("PAUSE");