tty_register(): Fix parser for external getty

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2017-08-27 16:43:01 +02:00
parent 675f82a6b9
commit 74affb32d3
+22 -11
View File
@@ -107,7 +107,7 @@ void tty_sweep(void)
int tty_register(char *line, struct timeval *mtime)
{
tty_node_t *entry;
int i, num = 0, insert = 0, noclear = 0;
int i, num = 1, insert = 0, noclear = 0;
char *tok, *cmd = NULL, *args[10];
char *dev = NULL, *baud = NULL;
char *runlevels = NULL, *term = NULL;
@@ -122,19 +122,30 @@ int tty_register(char *line, struct timeval *mtime)
/* External getty */
cmd = tok;
tok = strtok(line, " ");
while (tok) {
if (tok[0] == '[') {
runlevels = &tok[0];
} else if (tok[0] == '/' && tok != cmd) {
dev = strdup(tok);
args[num++] = tok;
} else {
args[num++] = tok;
for (tok = strtok(line, " "); tok; tok = strtok(NULL, " ")) {
if (cmd == tok) {
cmd = strdup(tok);
continue;
}
tok = strtok(NULL, " ");
if (tok[0] == '[') {
runlevels = &tok[0];
continue;
}
if (tok[0] == '/' && tok != cmd)
dev = strdup(tok);
args[num++] = strdup(tok);
}
cmd = strdup(cmd);
tok = strrchr(cmd, '/');
if (!tok)
tok = cmd;
else
tok++;
args[0] = strdup(tok);
} else {
/* Built-in getty */
tok = strtok(line, " ");