Refactor tty handling to use service backend enabling conditions etc.

Initial refactor of the tty implementation to use the service/run/task
general backend.  This enables all the features of services also for
ttys, except logging because it makes no sense.

Work in progress:

 - plugins/tty.c does not work anymore, could possibly be removed in
   favor of usinga (a new) condition instead (if-tty-exists)
 - fallback tty does not work anymore, should we remove it, or can we
   handle it as an optional built-in with (a new) condition?
 - @console does not work anymore, needs to generate N cloned services

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2021-04-14 16:29:19 +02:00
1 parent 3cf5d36972
commit 30020263ba
12 files changed
+285 -497

No files matched your search

+27 -4
View File
@@ -114,7 +114,7 @@ svc_t *svc_new(char *cmd, char *id, int type)
/* Find first job n:o if registering multiple instances */
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
if (!strcmp(svc->cmd, cmd)) {
if (cmd && !strcmp(svc->cmd, cmd)) {
job = svc->job;
break;
}
@@ -130,13 +130,17 @@ svc_t *svc_new(char *cmd, char *id, int type)
svc->job = job;
if (id && id[0])
strlcpy(svc->id, id, sizeof(svc->id));
strlcpy(svc->cmd, cmd, sizeof(svc->cmd));
if (cmd)
strlcpy(svc->cmd, cmd, sizeof(svc->cmd));
/* Default description, if missing */
strlcpy(svc->desc, svc->name, sizeof(svc->desc));
/* Default HALT signal to send */
svc->sighalt = SIGTERM;
if (svc_is_tty(svc))
svc->sighalt = SIGHUP;
else
svc->sighalt = SIGTERM;
/* Default delay between SIGTERM and SIGKILL */
svc->killdelay = SVC_TERM_TIMEOUT;
@@ -327,7 +331,7 @@ svc_t *svc_stop_completed(void)
svc_t *svc, *iter = NULL;
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
if (svc->state == SVC_STOPPING_STATE)
if (svc->state == SVC_STOPPING_STATE && svc->pid > 1)
return svc;
}
@@ -422,6 +426,22 @@ svc_t *svc_find_by_nameid(char *name, char *id)
return NULL;
}
svc_t *svc_find_by_tty(char *dev)
{
svc_t *svc, *iter = NULL;
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
if (!svc_is_tty(svc))
continue;
if (!strcmp(dev, svc->name))
return svc;
}
return NULL;
}
/**
* svc_find_by_plidfile - Find a service by its PID file
* @fn: PID file, can be absolute path or relative to /run
@@ -581,6 +601,9 @@ int svc_enabled(svc_t *svc)
if (svc_is_missing(svc))
return 0;
if (svc_is_tty(svc) && bootstrap)
return 0;
return 1;
}