service.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. char stdout_path[MAX_PATH];
  27. char stderr_path[MAX_PATH];
  28. unsigned long default_exit_action;
  29. unsigned long throttle_delay;
  30. unsigned long stop_method;
  31. unsigned long kill_console_delay;
  32. unsigned long kill_window_delay;
  33. unsigned long kill_threads_delay;
  34. SC_HANDLE handle;
  35. SERVICE_STATUS status;
  36. SERVICE_STATUS_HANDLE status_handle;
  37. HANDLE process_handle;
  38. unsigned long pid;
  39. HANDLE wait_handle;
  40. bool stopping;
  41. bool allow_restart;
  42. unsigned long throttle;
  43. CRITICAL_SECTION throttle_section;
  44. bool throttle_section_initialised;
  45. CONDITION_VARIABLE throttle_condition;
  46. HANDLE throttle_timer;
  47. LARGE_INTEGER throttle_duetime;
  48. FILETIME creation_time;
  49. FILETIME exit_time;
  50. } nssm_service_t;
  51. void WINAPI service_main(unsigned long, char **);
  52. char *service_control_text(unsigned long);
  53. void log_service_control(char *, unsigned long, bool);
  54. unsigned long WINAPI service_control_handler(unsigned long, unsigned long, void *, void *);
  55. nssm_service_t *alloc_nssm_service();
  56. void cleanup_nssm_service(nssm_service_t *);
  57. SC_HANDLE open_service_manager();
  58. int pre_install_service(int, char **);
  59. int pre_remove_service(int, char **);
  60. int install_service(nssm_service_t *);
  61. int remove_service(nssm_service_t *);
  62. void set_service_recovery(nssm_service_t *);
  63. int monitor_service(nssm_service_t *);
  64. int start_service(nssm_service_t *);
  65. int stop_service(nssm_service_t *, unsigned long, bool, bool);
  66. void CALLBACK end_service(void *, unsigned char);
  67. void throttle_restart(nssm_service_t *);
  68. int await_shutdown(nssm_service_t *, char *, unsigned long);
  69. #endif