1
0
Fork 0
mirror of https://github.com/pygos/init.git synced 2024-11-22 11:19:45 +01:00

initd: Hand out unique IDs to services

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2019-03-28 13:44:28 +01:00
parent d16d260181
commit c16735414b
3 changed files with 6 additions and 0 deletions

View file

@ -3,6 +3,7 @@
static service_list_t cfg; static service_list_t cfg;
static int service_id = 1;
static int target = -1; static int target = -1;
static service_t *running = NULL; static service_t *running = NULL;
static service_t *terminated = NULL; static service_t *terminated = NULL;
@ -14,6 +15,9 @@ static bool waiting = false;
static int start_service(service_t *svc) static int start_service(service_t *svc)
{ {
if (svc->id < 1)
svc->id = service_id++;
svc->pid = runsvc(svc); svc->pid = runsvc(svc);
if (svc->pid == -1) { if (svc->pid == -1) {
print_status(svc->desc, STATUS_FAIL, false); print_status(svc->desc, STATUS_FAIL, false);

View file

@ -68,6 +68,7 @@ typedef struct service_t {
pid_t pid; pid_t pid;
int status; /* process exit status */ int status; /* process exit status */
int id; /* service ID used by initd */
char name[]; /* canonical service name */ char name[]; /* canonical service name */
} service_t; } service_t;

View file

@ -261,6 +261,7 @@ service_t *rdsvc(int dirfd, const char *filename, int flags)
} }
memcpy(svc->name, filename, nlen); memcpy(svc->name, filename, nlen);
svc->id = -1;
if (rdcfg(svc, &rd, svc_params, ARRAY_SIZE(svc_params), flags)) if (rdcfg(svc, &rd, svc_params, ARRAY_SIZE(svc_params), flags))
goto fail; goto fail;