tty_register(): Fix parser for external getty

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