X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=service.h;h=994a7ce821e45add03369744d84ef21ff65d081b;hb=fce252d07bdf443e3b283c26a940d3b0f26fd440;hp=49760baa16a7d035780a7b6e7473016f26930834;hpb=0f64692bef62a3be6f9352cfdee05d73130d06f4;p=nssm.git diff --git a/service.h b/service.h index 49760ba..994a7ce 100644 --- a/service.h +++ b/service.h @@ -1,24 +1,68 @@ #ifndef SERVICE_H #define SERVICE_H +/* + MSDN says the commandline in CreateProcess() is limited to 32768 characters + and the application name to MAX_PATH. + A registry key is limited to 255 characters. + A registry value is limited to 16383 characters. + Therefore we limit the service name to accommodate the path under HKLM. +*/ +#define EXE_LENGTH MAX_PATH +#define CMD_LENGTH 32768 +#define KEY_LENGTH 255 +#define VALUE_LENGTH 16383 +#define SERVICE_NAME_LENGTH KEY_LENGTH - 55 + #define ACTION_LEN 16 +typedef struct { + char name[SERVICE_NAME_LENGTH]; + char exe[EXE_LENGTH]; + char flags[VALUE_LENGTH]; + char dir[MAX_PATH]; + char *env; + unsigned long throttle_delay; + unsigned long stop_method; + unsigned long kill_console_delay; + unsigned long kill_window_delay; + unsigned long kill_threads_delay; + SC_HANDLE handle; + SERVICE_STATUS status; + SERVICE_STATUS_HANDLE status_handle; + HANDLE process_handle; + unsigned long pid; + HANDLE wait_handle; + bool stopping; + bool allow_restart; + unsigned long throttle; + CRITICAL_SECTION throttle_section; + bool throttle_section_initialised; + CONDITION_VARIABLE throttle_condition; + HANDLE throttle_timer; + LARGE_INTEGER throttle_duetime; + FILETIME creation_time; + FILETIME exit_time; +} nssm_service_t; + void WINAPI service_main(unsigned long, char **); char *service_control_text(unsigned long); void log_service_control(char *, unsigned long, bool); unsigned long WINAPI service_control_handler(unsigned long, unsigned long, void *, void *); +nssm_service_t *alloc_nssm_service(); +void cleanup_nssm_service(nssm_service_t *); SC_HANDLE open_service_manager(); int pre_install_service(int, char **); int pre_remove_service(int, char **); -int install_service(char *, char *, char *); -int remove_service(char *); -void set_service_recovery(SC_HANDLE, char *); -int monitor_service(); -int start_service(); -int stop_service(unsigned long, bool, bool); +int install_service(nssm_service_t *); +int remove_service(nssm_service_t *); +void set_service_recovery(nssm_service_t *); +int monitor_service(nssm_service_t *); +int start_service(nssm_service_t *); +int stop_service(nssm_service_t *, unsigned long, bool, bool); void CALLBACK end_service(void *, unsigned char); -void throttle_restart(); -int await_shutdown(char *, char *, SERVICE_STATUS_HANDLE, SERVICE_STATUS *, HANDLE, unsigned long); +void throttle_restart(nssm_service_t *); +int await_shutdown(nssm_service_t *, char *, unsigned long); #endif