service.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. char name[SERVICE_NAME_LENGTH];
  18. char exe[EXE_LENGTH];
  19. char flags[VALUE_LENGTH];
  20. char dir[MAX_PATH];
  21. char *env;
  22. unsigned long envlen;
  23. char *env_extra;
  24. unsigned long env_extralen;
  25. char stdin_path[MAX_PATH];
  26. unsigned long stdin_sharing;
  27. unsigned long stdin_disposition;
  28. unsigned long stdin_flags;
  29. char stdout_path[MAX_PATH];
  30. unsigned long stdout_sharing;
  31. unsigned long stdout_disposition;
  32. unsigned long stdout_flags;
  33. char stderr_path[MAX_PATH];
  34. unsigned long stderr_sharing;
  35. unsigned long stderr_disposition;
  36. unsigned long stderr_flags;
  37. unsigned long default_exit_action;
  38. unsigned long throttle_delay;
  39. unsigned long stop_method;
  40. unsigned long kill_console_delay;
  41. unsigned long kill_window_delay;
  42. unsigned long kill_threads_delay;
  43. SC_HANDLE handle;
  44. SERVICE_STATUS status;
  45. SERVICE_STATUS_HANDLE status_handle;
  46. HANDLE process_handle;
  47. unsigned long pid;
  48. HANDLE wait_handle;
  49. bool stopping;
  50. bool allow_restart;
  51. unsigned long throttle;
  52. CRITICAL_SECTION throttle_section;
  53. bool throttle_section_initialised;
  54. CONDITION_VARIABLE throttle_condition;
  55. HANDLE throttle_timer;
  56. LARGE_INTEGER throttle_duetime;
  57. FILETIME creation_time;
  58. FILETIME exit_time;
  59. } nssm_service_t;
  60. void WINAPI service_main(unsigned long, char **);
  61. char *service_control_text(unsigned long);
  62. void log_service_control(char *, unsigned long, bool);
  63. unsigned long WINAPI service_control_handler(unsigned long, unsigned long, void *, void *);
  64. nssm_service_t *alloc_nssm_service();
  65. void set_nssm_service_defaults(nssm_service_t *);
  66. void cleanup_nssm_service(nssm_service_t *);
  67. SC_HANDLE open_service_manager();
  68. int pre_install_service(int, char **);
  69. int pre_remove_service(int, char **);
  70. int install_service(nssm_service_t *);
  71. int remove_service(nssm_service_t *);
  72. void set_service_recovery(nssm_service_t *);
  73. int monitor_service(nssm_service_t *);
  74. int start_service(nssm_service_t *);
  75. int stop_service(nssm_service_t *, unsigned long, bool, bool);
  76. void CALLBACK end_service(void *, unsigned char);
  77. void throttle_restart(nssm_service_t *);
  78. int await_shutdown(nssm_service_t *, char *, unsigned long);
  79. #endif