nssm.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 "utf8.h"
  42. #include "service.h"
  43. #include "account.h"
  44. #include "console.h"
  45. #include "env.h"
  46. #include "event.h"
  47. #include "hook.h"
  48. #include "imports.h"
  49. #include "messages.h"
  50. #include "process.h"
  51. #include "registry.h"
  52. #include "settings.h"
  53. #include "io.h"
  54. #include "gui.h"
  55. #endif
  56. void nssm_exit(int);
  57. int str_equiv(const TCHAR *, const TCHAR *);
  58. int quote(const TCHAR *, TCHAR *, size_t);
  59. void strip_basename(TCHAR *);
  60. int str_number(const TCHAR *, unsigned long *, TCHAR **);
  61. int str_number(const TCHAR *, unsigned long *);
  62. int num_cpus();
  63. int usage(int);
  64. const TCHAR *nssm_unquoted_imagepath();
  65. const TCHAR *nssm_imagepath();
  66. const TCHAR *nssm_exe();
  67. #define NSSM _T("NSSM")
  68. #ifdef _WIN64
  69. #define NSSM_ARCHITECTURE _T("64-bit")
  70. #else
  71. #define NSSM_ARCHITECTURE _T("32-bit")
  72. #endif
  73. #ifdef _DEBUG
  74. #define NSSM_DEBUG _T(" debug")
  75. #else
  76. #define NSSM_DEBUG _T("")
  77. #endif
  78. #define NSSM_CONFIGURATION NSSM_ARCHITECTURE NSSM_DEBUG
  79. #include "version.h"
  80. /*
  81. Throttle the restart of the service if it stops before this many
  82. milliseconds have elapsed since startup. Override in registry.
  83. */
  84. #define NSSM_RESET_THROTTLE_RESTART 1500
  85. /*
  86. How many milliseconds to wait for the application to die after sending
  87. a Control-C event to its console. Override in registry.
  88. */
  89. #define NSSM_KILL_CONSOLE_GRACE_PERIOD 1500
  90. /*
  91. How many milliseconds to wait for the application to die after posting to
  92. its windows' message queues. Override in registry.
  93. */
  94. #define NSSM_KILL_WINDOW_GRACE_PERIOD 1500
  95. /*
  96. How many milliseconds to wait for the application to die after posting to
  97. its threads' message queues. Override in registry.
  98. */
  99. #define NSSM_KILL_THREADS_GRACE_PERIOD 1500
  100. /* How many milliseconds to pause after rotating logs. */
  101. #define NSSM_ROTATE_DELAY 0
  102. /* Margin of error for service status wait hints in milliseconds. */
  103. #define NSSM_WAITHINT_MARGIN 2000
  104. /* Methods used to try to stop the application. */
  105. #define NSSM_STOP_METHOD_CONSOLE (1 << 0)
  106. #define NSSM_STOP_METHOD_WINDOW (1 << 1)
  107. #define NSSM_STOP_METHOD_THREADS (1 << 2)
  108. #define NSSM_STOP_METHOD_TERMINATE (1 << 3)
  109. /* Startup types. */
  110. #define NSSM_STARTUP_AUTOMATIC 0
  111. #define NSSM_STARTUP_DELAYED 1
  112. #define NSSM_STARTUP_MANUAL 2
  113. #define NSSM_STARTUP_DISABLED 3
  114. /* Exit actions. */
  115. #define NSSM_EXIT_RESTART 0
  116. #define NSSM_EXIT_IGNORE 1
  117. #define NSSM_EXIT_REALLY 2
  118. #define NSSM_EXIT_UNCLEAN 3
  119. #define NSSM_NUM_EXIT_ACTIONS 4
  120. /* Process priority. */
  121. #define NSSM_REALTIME_PRIORITY 0
  122. #define NSSM_HIGH_PRIORITY 1
  123. #define NSSM_ABOVE_NORMAL_PRIORITY 2
  124. #define NSSM_NORMAL_PRIORITY 3
  125. #define NSSM_BELOW_NORMAL_PRIORITY 4
  126. #define NSSM_IDLE_PRIORITY 5
  127. /* How many milliseconds to wait before updating service status. */
  128. #define NSSM_SERVICE_STATUS_DEADLINE 20000
  129. /* User-defined service controls can be in the range 128-255. */
  130. #define NSSM_SERVICE_CONTROL_START 0
  131. #define NSSM_SERVICE_CONTROL_ROTATE 128
  132. /* How many milliseconds to wait for a hook. */
  133. #define NSSM_HOOK_DEADLINE 60000
  134. /* How many milliseconds to wait for outstanding hooks. */
  135. #define NSSM_HOOK_THREAD_DEADLINE 80000
  136. /* How many milliseconds to wait for closing logging thread. */
  137. #define NSSM_CLEANUP_LOGGERS_DEADLINE 1500
  138. #endif