mirror of
https://github.com/troglobit/finit.git
synced 2026-11-08 16:11:10 +00:00
Add support for @console to external getty in tty_register()
- Refactor code to figure out device so it works for both the built-in and external getty code paths - Fix memory leak when user edits an existing tty device - Replace @console in argument list to external getty Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
00a2840853
commit
c19489d6c3
1 file changed
+27
-17
@@ -153,8 +153,12 @@ int tty_register(char *line, struct rlimit rlimit[], char *file)
|
|||||||
|
|
||||||
/* Iterate over all args */
|
/* Iterate over all args */
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
/* First, figure out if built-in or external */
|
/*
|
||||||
if (!dev && !cmd) {
|
* First, figure out if built-in or external getty
|
||||||
|
* tty [12345] /dev/ttyAMA0 115200 noclear vt220 # built-in
|
||||||
|
* tty [12345] /sbin/getty -L 115200 @console vt100 noclear # external
|
||||||
|
*/
|
||||||
|
if ((!cmd && !dev) || (cmd && !dev)) {
|
||||||
if (args[i][0] == '[')
|
if (args[i][0] == '[')
|
||||||
runlevels = line;
|
runlevels = line;
|
||||||
if (!strcmp(args[i], "@console"))
|
if (!strcmp(args[i], "@console"))
|
||||||
@@ -171,7 +175,7 @@ int tty_register(char *line, struct rlimit rlimit[], char *file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Built-in getty args */
|
/* Built-in getty args */
|
||||||
if (dev) {
|
if (!cmd && dev) {
|
||||||
if (isdigit(args[i][0])) {
|
if (isdigit(args[i][0])) {
|
||||||
baud = args[i];
|
baud = args[i];
|
||||||
continue;
|
continue;
|
||||||
@@ -184,15 +188,6 @@ int tty_register(char *line, struct rlimit rlimit[], char *file)
|
|||||||
if (i + 1 == num)
|
if (i + 1 == num)
|
||||||
term = args[i];
|
term = args[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* External getty, figure out the device */
|
|
||||||
if (cmd) {
|
|
||||||
if (!strncmp(args[i], "/dev", 4))
|
|
||||||
dev = args[i];
|
|
||||||
|
|
||||||
if (!strncmp(args[i], "tty", 3))
|
|
||||||
dev = args[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
@@ -226,18 +221,27 @@ again:
|
|||||||
dev = canonicalize(dev);
|
dev = canonicalize(dev);
|
||||||
if (!dev)
|
if (!dev)
|
||||||
goto error;
|
goto error;
|
||||||
dev = strdup(dev);
|
|
||||||
|
|
||||||
entry = tty_find(dev);
|
entry = tty_find(dev);
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
insert = 1;
|
|
||||||
entry = calloc(1, sizeof(*entry));
|
entry = calloc(1, sizeof(*entry));
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
free(dev);
|
|
||||||
if (cmd)
|
if (cmd)
|
||||||
free(cmd);
|
free(cmd);
|
||||||
return errno = ENOMEM;
|
return errno = ENOMEM;
|
||||||
}
|
}
|
||||||
|
insert = 1;
|
||||||
|
} else {
|
||||||
|
if (entry->cmd) {
|
||||||
|
free(entry->cmd);
|
||||||
|
entry->cmd = NULL;
|
||||||
|
for (i = 0; i < TTY_MAX_ARGS; i++) {
|
||||||
|
if (entry->args[i])
|
||||||
|
free(entry->args[i]);
|
||||||
|
entry->args[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
insert = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
strlcpy(entry->name, dev, sizeof(entry->name));
|
strlcpy(entry->name, dev, sizeof(entry->name));
|
||||||
@@ -260,8 +264,14 @@ again:
|
|||||||
entry->cmd = cmd;
|
entry->cmd = cmd;
|
||||||
args[1] = strdup(tok);
|
args[1] = strdup(tok);
|
||||||
|
|
||||||
for (i = 1; i < num; i++)
|
for (i = 1; i < num; i++) {
|
||||||
entry->args[j++] = strdup(args[i]);
|
char *arg = args[i];
|
||||||
|
|
||||||
|
/* Replace @console with actual device */
|
||||||
|
if (arg && !strcmp(arg, "@console"))
|
||||||
|
arg = dev;
|
||||||
|
entry->args[j++] = strdup(arg);
|
||||||
|
}
|
||||||
entry->args[++j] = NULL;
|
entry->args[++j] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user