nssm.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #ifndef NSSM_H
  2. #define NSSM_H
  3. /*
  4. MSDN says, basically, that the maximum length of a path is 260 characters,
  5. which is represented by the constant MAX_PATH. Except when it isn't.
  6. The maximum length of a directory path is MAX_PATH - 12 because it must be
  7. possible to create a file in 8.3 format under any valid directory.
  8. Unicode versions of filesystem API functions accept paths up to 32767
  9. characters if the first four (wide) characters are L"\\?\" and each component
  10. of the path, separated by L"\", does not exceed the value of
  11. lpMaximumComponentLength returned by GetVolumeInformation(), which is
  12. probably 255. But might not be.
  13. Relative paths are always limited to MAX_PATH because the L"\\?\" prefix
  14. is not valid for a relative path.
  15. Note that we don't care about the last two paragraphs because we're only
  16. concerned with allocating buffers big enough to store valid paths. If the
  17. user tries to store invalid paths they will fit in the buffers but the
  18. application will fail. The reason for the failure will end up in the
  19. event log and the user will realise the mistake.
  20. So that's that cleared up, then.
  21. */
  22. #ifdef UNICODE
  23. #define PATH_LENGTH 32767
  24. #else
  25. #define PATH_LENGTH MAX_PATH
  26. #endif
  27. #define DIR_LENGTH PATH_LENGTH - 12
  28. #define _WIN32_WINNT 0x0500
  29. #define APSTUDIO_HIDDEN_SYMBOLS
  30. #include <windows.h>
  31. #include <prsht.h>
  32. #undef APSTUDIO_HIDDEN_SYMBOLS
  33. #include <commctrl.h>
  34. #include <tchar.h>
  35. #ifndef NSSM_COMPILE_RC
  36. #include <fcntl.h>
  37. #include <io.h>
  38. #include <shlwapi.h>
  39. #include <stdarg.h>
  40. #include <stdio.h>
  41. #include "service.h"
  42. #include "account.h"
  43. #include "console.h"
  44. #include "env.h"
  45. #include "event.h"
  46. #include "hook.h"
  47. #include "imports.h"
  48. #include "messages.h"
  49. #include "process.h"
  50. #include "registry.h"
  51. #include "settings.h"
  52. #include "io.h"
  53. #include "gui.h"
  54. #endif
  55. int str_equiv(const TCHAR *, const TCHAR *);
  56. void strip_basename(TCHAR *);
  57. int str_number(const TCHAR *, unsigned long *, TCHAR **);
  58. int str_number(const TCHAR *, unsigned long *);
  59. int num_cpus();
  60. int usage(int);
  61. const TCHAR *nssm_unquoted_imagepath();
  62. const TCHAR *nssm_imagepath();
  63. #define NSSM _T("NSSM")
  64. #ifdef _WIN64
  65. #define NSSM_ARCHITECTURE _T("64-bit")
  66. #else
  67. #define NSSM_ARCHITECTURE _T("32-bit")
  68. #endif
  69. #ifdef _DEBUG
  70. #define NSSM_DEBUG _T(" debug")
  71. #else
  72. #define NSSM_DEBUG _T("")
  73. #endif
  74. #define NSSM_CONFIGURATION NSSM_ARCHITECTURE NSSM_DEBUG
  75. #include "version.h"
  76. /*
  77. Throttle the restart of the service if it stops before this many
  78. milliseconds have elapsed since startup. Override in registry.
  79. */
  80. #define NSSM_RESET_THROTTLE_RESTART 1500
  81. /*
  82. How many milliseconds to wait for the application to die after sending
  83. a Control-C event to its console. Override in registry.
  84. */
  85. #define NSSM_KILL_CONSOLE_GRACE_PERIOD 1500
  86. /*
  87. How many milliseconds to wait for the application to die after posting to
  88. its windows' message queues. Override in registry.
  89. */
  90. #define NSSM_KILL_WINDOW_GRACE_PERIOD 1500
  91. /*
  92. How many milliseconds to wait for the application to die after posting to
  93. its threads' message queues. Override in registry.
  94. */
  95. #define NSSM_KILL_THREADS_GRACE_PERIOD 1500
  96. /* How many milliseconds to pause after rotating logs. */
  97. #define NSSM_ROTATE_DELAY 0
  98. /* Margin of error for service status wait hints in milliseconds. */
  99. #define NSSM_WAITHINT_MARGIN 2000
  100. /* Methods used to try to stop the application. */
  101. #define NSSM_STOP_METHOD_CONSOLE (1 << 0)
  102. #define NSSM_STOP_METHOD_WINDOW (1 << 1)
  103. #define NSSM_STOP_METHOD_THREADS (1 << 2)
  104. #define NSSM_STOP_METHOD_TERMINATE (1 << 3)
  105. /* Startup types. */
  106. #define NSSM_STARTUP_AUTOMATIC 0
  107. #define NSSM_STARTUP_DELAYED 1
  108. #define NSSM_STARTUP_MANUAL 2
  109. #define NSSM_STARTUP_DISABLED 3
  110. /* Exit actions. */
  111. #define NSSM_EXIT_RESTART 0
  112. #define NSSM_EXIT_IGNORE 1
  113. #define NSSM_EXIT_REALLY 2
  114. #define NSSM_EXIT_UNCLEAN 3
  115. #define NSSM_NUM_EXIT_ACTIONS 4
  116. /* Process priority. */
  117. #define NSSM_REALTIME_PRIORITY 0
  118. #define NSSM_HIGH_PRIORITY 1
  119. #define NSSM_ABOVE_NORMAL_PRIORITY 2
  120. #define NSSM_NORMAL_PRIORITY 3
  121. #define NSSM_BELOW_NORMAL_PRIORITY 4
  122. #define NSSM_IDLE_PRIORITY 5
  123. /* How many milliseconds to wait before updating service status. */
  124. #define NSSM_SERVICE_STATUS_DEADLINE 20000
  125. /* User-defined service controls can be in the range 128-255. */
  126. #define NSSM_SERVICE_CONTROL_START 0
  127. #define NSSM_SERVICE_CONTROL_ROTATE 128
  128. /* How many milliseconds to wait for a hook. */
  129. #define NSSM_HOOK_DEADLINE 60000
  130. /* How many milliseconds to wait for outstanding hooks. */
  131. #define NSSM_HOOK_THREAD_DEADLINE 80000
  132. #endif