hook.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef HOOK_H
  2. #define HOOK_H
  3. #define NSSM_HOOK_EVENT_START _T("Start")
  4. #define NSSM_HOOK_EVENT_STOP _T("Stop")
  5. #define NSSM_HOOK_EVENT_EXIT _T("Exit")
  6. #define NSSM_HOOK_EVENT_POWER _T("Power")
  7. #define NSSM_HOOK_EVENT_ROTATE _T("Rotate")
  8. #define NSSM_HOOK_ACTION_PRE _T("Pre")
  9. #define NSSM_HOOK_ACTION_POST _T("Post")
  10. #define NSSM_HOOK_ACTION_CHANGE _T("Change")
  11. #define NSSM_HOOK_ACTION_RESUME _T("Resume")
  12. /* Hook name will be "<service> (<event>/<action>)" */
  13. #define HOOK_NAME_LENGTH SERVICE_NAME_LENGTH * 2
  14. #define NSSM_HOOK_VERSION 1
  15. /* Hook ran successfully. */
  16. #define NSSM_HOOK_STATUS_SUCCESS 0
  17. /* No hook configured. */
  18. #define NSSM_HOOK_STATUS_NOTFOUND 1
  19. /* Hook requested abort. */
  20. #define NSSM_HOOK_STATUS_ABORT 99
  21. /* Internal error launching hook. */
  22. #define NSSM_HOOK_STATUS_ERROR 100
  23. /* Hook was not run. */
  24. #define NSSM_HOOK_STATUS_NOTRUN 101
  25. /* Hook timed out. */
  26. #define NSSM_HOOK_STATUS_TIMEOUT 102
  27. /* Hook returned non-zero. */
  28. #define NSSM_HOOK_STATUS_FAILED 111
  29. /* Version 1. */
  30. #define NSSM_HOOK_ENV_VERSION _T("NSSM_HOOK_VERSION")
  31. #define NSSM_HOOK_ENV_IMAGE_PATH _T("NSSM_EXE")
  32. #define NSSM_HOOK_ENV_NSSM_CONFIGURATION _T("NSSM_CONFIGURATION")
  33. #define NSSM_HOOK_ENV_NSSM_VERSION _T("NSSM_VERSION")
  34. #define NSSM_HOOK_ENV_BUILD_DATE _T("NSSM_BUILD_DATE")
  35. #define NSSM_HOOK_ENV_PID _T("NSSM_PID")
  36. #define NSSM_HOOK_ENV_DEADLINE _T("NSSM_DEADLINE")
  37. #define NSSM_HOOK_ENV_SERVICE_NAME _T("NSSM_SERVICE_NAME")
  38. #define NSSM_HOOK_ENV_SERVICE_DISPLAYNAME _T("NSSM_SERVICE_DISPLAYNAME")
  39. #define NSSM_HOOK_ENV_COMMAND_LINE _T("NSSM_COMMAND_LINE")
  40. #define NSSM_HOOK_ENV_APPLICATION_PID _T("NSSM_APPLICATION_PID")
  41. #define NSSM_HOOK_ENV_EVENT _T("NSSM_EVENT")
  42. #define NSSM_HOOK_ENV_ACTION _T("NSSM_ACTION")
  43. #define NSSM_HOOK_ENV_TRIGGER _T("NSSM_TRIGGER")
  44. #define NSSM_HOOK_ENV_LAST_CONTROL _T("NSSM_LAST_CONTROL")
  45. #define NSSM_HOOK_ENV_START_REQUESTED_COUNT _T("NSSM_START_REQUESTED_COUNT")
  46. #define NSSM_HOOK_ENV_START_COUNT _T("NSSM_START_COUNT")
  47. #define NSSM_HOOK_ENV_THROTTLE_COUNT _T("NSSM_THROTTLE_COUNT")
  48. #define NSSM_HOOK_ENV_EXIT_COUNT _T("NSSM_EXIT_COUNT")
  49. #define NSSM_HOOK_ENV_EXITCODE _T("NSSM_EXITCODE")
  50. #define NSSM_HOOK_ENV_RUNTIME _T("NSSM_RUNTIME")
  51. #define NSSM_HOOK_ENV_APPLICATION_RUNTIME _T("NSSM_APPLICATION_RUNTIME")
  52. typedef struct {
  53. TCHAR name[HOOK_NAME_LENGTH];
  54. HANDLE thread_handle;
  55. } hook_thread_data_t;
  56. typedef struct {
  57. hook_thread_data_t *data;
  58. int num_threads;
  59. } hook_thread_t;
  60. bool valid_hook_name(const TCHAR *, const TCHAR *, bool);
  61. void await_hook_threads(hook_thread_t *, SERVICE_STATUS_HANDLE, SERVICE_STATUS *, unsigned long);
  62. int nssm_hook(hook_thread_t *, nssm_service_t *, TCHAR *, TCHAR *, unsigned long *, unsigned long, bool);
  63. int nssm_hook(hook_thread_t *, nssm_service_t *, TCHAR *, TCHAR *, unsigned long *, unsigned long);
  64. int nssm_hook(hook_thread_t *, nssm_service_t *, TCHAR *, TCHAR *, unsigned long *);
  65. #endif