service.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef SERVICE_H
  2. #define SERVICE_H
  3. /*
  4. MSDN says the commandline in CreateProcess() is limited to 32768 characters
  5. and the application name to MAX_PATH.
  6. A registry key is limited to 255 characters.
  7. A registry value is limited to 16383 characters.
  8. Therefore we limit the service name to accommodate the path under HKLM.
  9. */
  10. #define EXE_LENGTH MAX_PATH
  11. #define CMD_LENGTH 32768
  12. #define KEY_LENGTH 255
  13. #define VALUE_LENGTH 16383
  14. #define SERVICE_NAME_LENGTH KEY_LENGTH - 55
  15. #define ACTION_LEN 16
  16. typedef struct {
  17. TCHAR name[SERVICE_NAME_LENGTH];
  18. TCHAR exe[EXE_LENGTH];
  19. TCHAR flags[VALUE_LENGTH];
  20. TCHAR dir[MAX_PATH];
  21. TCHAR *env;
  22. unsigned long envlen;
  23. TCHAR *env_extra;
  24. unsigned long env_extralen;
  25. TCHAR stdin_path[MAX_PATH];
  26. unsigned long stdin_sharing;
  27. unsigned long stdin_disposition;
  28. unsigned long stdin_flags;
  29. TCHAR stdout_path[MAX_PATH];
  30. unsigned long stdout_sharing;
  31. unsigned long stdout_disposition;
  32. unsigned long stdout_flags;
  33. TCHAR stderr_path[MAX_PATH];
  34. unsigned long stderr_sharing;
  35. unsigned long stderr_disposition;
  36. unsigned long stderr_flags;
  37. bool rotate_files;
  38. unsigned long rotate_seconds;
  39. unsigned long rotate_bytes_low;
  40. unsigned long rotate_bytes_high;
  41. unsigned long default_exit_action;
  42. unsigned long throttle_delay;
  43. unsigned long stop_method;
  44. unsigned long kill_console_delay;
  45. unsigned long kill_window_delay;
  46. unsigned long kill_threads_delay;
  47. SC_HANDLE handle;
  48. SERVICE_STATUS status;
  49. SERVICE_STATUS_HANDLE status_handle;
  50. HANDLE process_handle;
  51. unsigned long pid;
  52. HANDLE wait_handle;
  53. bool stopping;
  54. bool allow_restart;
  55. unsigned long throttle;
  56. CRITICAL_SECTION throttle_section;
  57. bool throttle_section_initialised;
  58. CONDITION_VARIABLE throttle_condition;
  59. HANDLE throttle_timer;
  60. LARGE_INTEGER throttle_duetime;
  61. FILETIME creation_time;
  62. FILETIME exit_time;
  63. } nssm_service_t;
  64. void WINAPI service_main(unsigned long, TCHAR **);
  65. TCHAR *service_control_text(unsigned long);
  66. void log_service_control(TCHAR *, unsigned long, bool);
  67. unsigned long WINAPI service_control_handler(unsigned long, unsigned long, void *, void *);
  68. nssm_service_t *alloc_nssm_service();
  69. void set_nssm_service_defaults(nssm_service_t *);
  70. void cleanup_nssm_service(nssm_service_t *);
  71. SC_HANDLE open_service_manager();
  72. int pre_install_service(int, TCHAR **);
  73. int pre_remove_service(int, TCHAR **);
  74. int install_service(nssm_service_t *);
  75. int remove_service(nssm_service_t *);
  76. void set_service_recovery(nssm_service_t *);
  77. int monitor_service(nssm_service_t *);
  78. int start_service(nssm_service_t *);
  79. int stop_service(nssm_service_t *, unsigned long, bool, bool);
  80. void CALLBACK end_service(void *, unsigned char);
  81. void throttle_restart(nssm_service_t *);
  82. int await_shutdown(nssm_service_t *, TCHAR *, unsigned long);
  83. #endif