nssm.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #include <fcntl.h>
  30. #include <io.h>
  31. #include <shlwapi.h>
  32. #include <stdarg.h>
  33. #include <stdio.h>
  34. #include <tchar.h>
  35. #include <windows.h>
  36. #include "service.h"
  37. #include "env.h"
  38. #include "event.h"
  39. #include "imports.h"
  40. #include "messages.h"
  41. #include "process.h"
  42. #include "registry.h"
  43. #include "settings.h"
  44. #include "io.h"
  45. #include "gui.h"
  46. int str_equiv(const TCHAR *, const TCHAR *);
  47. void strip_basename(TCHAR *);
  48. int str_number(const TCHAR *, unsigned long *, TCHAR **);
  49. int str_number(const TCHAR *, unsigned long *);
  50. int num_cpus();
  51. int usage(int);
  52. void banner();
  53. #define NSSM _T("NSSM")
  54. #ifdef _WIN64
  55. #define NSSM_ARCHITECTURE _T("64-bit")
  56. #else
  57. #define NSSM_ARCHITECTURE _T("32-bit")
  58. #endif
  59. #ifdef _DEBUG
  60. #define NSSM_DEBUG _T(" debug")
  61. #else
  62. #define NSSM_DEBUG _T("")
  63. #endif
  64. #define NSSM_CONFIGURATION NSSM_ARCHITECTURE NSSM_DEBUG
  65. #include "version.h"
  66. /*
  67. Throttle the restart of the service if it stops before this many
  68. milliseconds have elapsed since startup. Override in registry.
  69. */
  70. #define NSSM_RESET_THROTTLE_RESTART 1500
  71. /*
  72. How many milliseconds to wait for the application to die after sending
  73. a Control-C event to its console. Override in registry.
  74. */
  75. #define NSSM_KILL_CONSOLE_GRACE_PERIOD 1500
  76. /*
  77. How many milliseconds to wait for the application to die after posting to
  78. its windows' message queues. Override in registry.
  79. */
  80. #define NSSM_KILL_WINDOW_GRACE_PERIOD 1500
  81. /*
  82. How many milliseconds to wait for the application to die after posting to
  83. its threads' message queues. Override in registry.
  84. */
  85. #define NSSM_KILL_THREADS_GRACE_PERIOD 1500
  86. /* Margin of error for service status wait hints in milliseconds. */
  87. #define NSSM_WAITHINT_MARGIN 2000
  88. /* Methods used to try to stop the application. */
  89. #define NSSM_STOP_METHOD_CONSOLE (1 << 0)
  90. #define NSSM_STOP_METHOD_WINDOW (1 << 1)
  91. #define NSSM_STOP_METHOD_THREADS (1 << 2)
  92. #define NSSM_STOP_METHOD_TERMINATE (1 << 3)
  93. /* Startup types. */
  94. #define NSSM_STARTUP_AUTOMATIC 0
  95. #define NSSM_STARTUP_DELAYED 1
  96. #define NSSM_STARTUP_MANUAL 2
  97. #define NSSM_STARTUP_DISABLED 3
  98. /* Exit actions. */
  99. #define NSSM_EXIT_RESTART 0
  100. #define NSSM_EXIT_IGNORE 1
  101. #define NSSM_EXIT_REALLY 2
  102. #define NSSM_EXIT_UNCLEAN 3
  103. #define NSSM_NUM_EXIT_ACTIONS 4
  104. /* Process priority. */
  105. #define NSSM_REALTIME_PRIORITY 0
  106. #define NSSM_HIGH_PRIORITY 1
  107. #define NSSM_ABOVE_NORMAL_PRIORITY 2
  108. #define NSSM_NORMAL_PRIORITY 3
  109. #define NSSM_BELOW_NORMAL_PRIORITY 4
  110. #define NSSM_IDLE_PRIORITY 5
  111. /* How many milliseconds to wait before updating service status. */
  112. #define NSSM_SERVICE_STATUS_DEADLINE 20000
  113. /* User-defined service controls can be in the range 128-255. */
  114. #define NSSM_SERVICE_CONTROL_START 0
  115. #define NSSM_SERVICE_CONTROL_ROTATE 128
  116. #endif