From e9670b87b334f0db604b2ef60ed58394f5fc922c Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 18 Mar 2018 18:58:19 +0100 Subject: [PATCH] Refactor, convert struct tty members to static strings Signed-off-by: Joachim Nilsson --- src/exec.c | 2 +- src/getty.c | 2 +- src/tty.c | 12 +++--------- src/tty.h | 6 +++--- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/exec.c b/src/exec.c index c4c69061..842181e1 100644 --- a/src/exec.c +++ b/src/exec.c @@ -363,7 +363,7 @@ pid_t run_getty(char *tty, char *baud, char *term, int noclear, int nowait, stru if (!pid) { speed_t speed = B38400; - if (baud) { + if (baud && baud[0]) { speed = stty_parse_speed(baud); if (B0 == speed) logit(LOG_CRIT, "TTY %s: Invalid speed %s", tty, baud); diff --git a/src/getty.c b/src/getty.c index 8852488f..58b95a1f 100644 --- a/src/getty.c +++ b/src/getty.c @@ -237,7 +237,7 @@ int getty(char *tty, speed_t speed, char *term, char *user) stty(fd, speed); close(fd); - if (term) + if (term && term[0]) setenv("TERM", term, 1); return do_login(name); diff --git a/src/tty.c b/src/tty.c index 9f60cc1a..2d63996a 100644 --- a/src/tty.c +++ b/src/tty.c @@ -238,9 +238,9 @@ int tty_register(char *line, struct rlimit rlimit[], char *file) } } - entry->name = dev; - entry->baud = baud ? strdup(baud) : NULL; - entry->term = term ? strdup(term) : NULL; + strlcpy(entry->name, dev, sizeof(entry->name)); + strlcpy(entry->baud, baud ? baud : "", sizeof(entry->baud)); + strlcpy(entry->term, term ? term : "", sizeof(entry->term)); entry->noclear = noclear; entry->nowait = nowait; entry->nologin = nologin; @@ -290,12 +290,6 @@ int tty_unregister(struct tty *tty) LIST_REMOVE(tty, link); - if (tty->name) - free(tty->name); - if (tty->baud) - free(tty->baud); - if (tty->term) - free(tty->term); if (tty->cmd) { int i; diff --git a/src/tty.h b/src/tty.h index 40c00cb4..b623917d 100644 --- a/src/tty.h +++ b/src/tty.h @@ -35,9 +35,9 @@ struct tty { LIST_ENTRY(tty) link; - char *name; - char *baud; - char *term; + char name[42]; + char baud[10]; + char term[10]; int noclear; int nowait; int nologin;