package/finit: backport fix for tty @console

Only the first listed console in /sys/class/tty/console/active starts
properly, the remaining one(s) were registered using the wrong :ID and
no arguments to getty.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-04-25 09:20:32 +02:00
parent 45cc13ccfe
commit c21c94f851
@@ -0,0 +1,117 @@
From 6a89e60fc84b90e5f09f61d37892f3b17bd14631 Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Wed, 24 Apr 2024 11:33:35 +0200
Subject: [PATCH 10/11] Fix #405: parsing >1 active consoles in tty @console
setups
Organization: Addiva Elektronik
Systems that have the following tty setup and multiple consoles listed
in /sys/class/tty/console/active misbehave:
tty [12345789] @console 0 xterm noclear passenv
Only the first listed console is started properly, the remaining ones
were registered using the wrong :ID and no arguments to getty.
This patch fixes the parsing and re-use of the base paramenters for
all consoles listed in the active file.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
---
src/service.c | 45 +++++++++++++++++++++++----------------------
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/src/service.c b/src/service.c
index eca9ed0..95a04b8 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1633,10 +1633,16 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
if (type == SVC_TYPE_TTY) {
size_t i, len = 0;
+ char *ptr;
if (tty_parse_args(&tty, cmd, &args))
return errno;
+ if (tty_isatcon(tty.dev))
+ dev = tty_atcon();
+ else
+ dev = tty.dev;
+ next:
if (tty.cmd)
len += strlen(tty.cmd);
else
@@ -1659,14 +1665,22 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
if (!cmd)
return errno;
- if (tty_isatcon(tty.dev))
- dev = tty_atcon();
- else
- dev = tty.dev;
-
/* tty's always respawn, never incr. restart_cnt */
respawn = 1;
- next:
+
+ /* Create name:id tuple for identity, e.g., tty:S0 */
+ ptr = strrchr(dev, '/');
+ if (ptr)
+ ptr++;
+ else
+ ptr = dev;
+ if (!strncmp(ptr, "tty", 3))
+ ptr += 3;
+
+ name = "tty";
+ if (!id || id[0] == 0)
+ id = ptr;
+
svc = svc_find_by_tty(dev);
} else
svc = svc_find(name, id);
@@ -1722,8 +1736,6 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
conf_parse_cond(svc, cond);
if (type == SVC_TYPE_TTY) {
- char *ptr;
-
if (dev)
strlcpy(svc->dev, dev, sizeof(svc->dev));
if (tty.baud)
@@ -1738,19 +1750,6 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
/* TTYs cannot be redirected */
log = NULL;
-
- /* Create name:id tuple for identity, e.g., tty:S0 */
- ptr = strrchr(svc->dev, '/');
- if (ptr)
- ptr++;
- else
- ptr = svc->dev;
- if (!strncmp(ptr, "tty", 3))
- ptr += 3;
- if (!id || id[0] == 0)
- id = ptr;
- strlcpy(svc->name, "tty", sizeof(svc->name));
- strlcpy(svc->id, id, sizeof(svc->id));
}
parse_cmdline_args(svc, cmd, &args);
@@ -1870,8 +1869,10 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
/* continue expanding any 'tty @console ...' */
if (tty_isatcon(tty.dev)) {
dev = tty_atcon();
- if (dev)
+ if (dev) {
+ id = NULL; /* reset for next tty:ID */
goto next;
+ }
}
return 0;
--
2.34.1