service.h 2.3 KB

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