From 8ce7d986283f5ef63377a0a447850c970c5cc493 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 14 May 2020 01:41:30 +0200 Subject: Move service rt data to libinit, try to improve memory packing Signed-off-by: David Oberhollenzer --- lib/include/service.h | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'lib/include/service.h') diff --git a/lib/include/service.h b/lib/include/service.h index 05ab8de..f388f87 100644 --- a/lib/include/service.h +++ b/lib/include/service.h @@ -3,6 +3,7 @@ #define SERVICE_H #include +#include typedef struct exec_t { struct exec_t *next; @@ -10,6 +11,14 @@ typedef struct exec_t { char args[]; /* argument vectot string blob */ } exec_t; +enum { + STATE_OFF, + STATE_RUNNING, + STATE_QUEUED, + STATE_COMPLETED, + STATE_FAILED, +}; + enum { /* Start the service in the background and continue with @@ -44,17 +53,13 @@ enum { SVC_FLAG_HAS_EXEC = 0x10, }; +/* persistent service configuration read from disk */ typedef struct service_t { struct service_t *next; char *fname; /* source file name */ - - int type; /* SVC_* service type */ - int target; /* TGT_* service target */ char *desc; /* description string */ char *ctty; /* controlling tty or log file */ - int rspwn_limit; /* maximum respawn count */ - unsigned int flags; /* SVC_FLAG_* bit field */ /* linked list of command lines to execute */ exec_t *exec; @@ -62,8 +67,13 @@ typedef struct service_t { char *before; /* services that must be executed later */ char *after; /* services that must be executed first */ - int num_before; - int num_after; + uint32_t num_before; + uint32_t num_after; + + uint16_t rspwn_limit; /* maximum respawn count */ + uint16_t flags; /* SVC_FLAG_* bit field */ + uint8_t type; /* SVC_* service type */ + uint8_t target; /* TGT_* service target */ char name[]; /* canonical service name */ } service_t; @@ -72,6 +82,15 @@ typedef struct { service_t *targets[TGT_MAX]; } service_list_t; +/* run time configuration in-memory for managing services */ +typedef struct { + service_t *svc; /* the underlying service description */ + pid_t pid; /* if still running, the pid */ + uint16_t rspwn_count; /* services respawn counter */ + uint8_t state; /* what STATE_* the service is currently in */ + uint8_t status; /* if exited, process exit status */ +} svc_run_data_t; + /* Read a service from a file. */ -- cgit v1.2.3