mirror of
https://github.com/troglobit/finit.git
synced 2026-11-08 16:11:10 +00:00
Fix #103: Register multiple getty if @console resolves to >1 TTY
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
682e80fed5
commit
a40858f162
1 file changed
+28
-18
@@ -45,28 +45,12 @@ static LIST_HEAD(, tty) tty_list = LIST_HEAD_INITIALIZER();
|
|||||||
|
|
||||||
static char *canonicalize(char *tty)
|
static char *canonicalize(char *tty)
|
||||||
{
|
{
|
||||||
char buf[42];
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
static char path[80];
|
static char path[80];
|
||||||
|
|
||||||
if (!tty)
|
if (!tty)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Auto-detect serial console, for embedded devices mostly */
|
|
||||||
if (!strcmp(tty, "@console")) {
|
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
fp = fopen("/sys/class/tty/console/active", "r");
|
|
||||||
if (!fp) {
|
|
||||||
_e("Cannot find system console, is sysfs not mounted?");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fgets(buf, sizeof(buf), fp))
|
|
||||||
tty = chomp(buf);
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
strlcpy(path, tty, sizeof(path));
|
strlcpy(path, tty, sizeof(path));
|
||||||
if (stat(path, &st)) {
|
if (stat(path, &st)) {
|
||||||
if (!strncmp(path, _PATH_DEV, strlen(_PATH_DEV))) {
|
if (!strncmp(path, _PATH_DEV, strlen(_PATH_DEV))) {
|
||||||
@@ -137,11 +121,11 @@ void tty_sweep(void)
|
|||||||
int tty_register(char *line, struct rlimit rlimit[], char *file)
|
int tty_register(char *line, struct rlimit rlimit[], char *file)
|
||||||
{
|
{
|
||||||
struct tty *entry;
|
struct tty *entry;
|
||||||
int insert = 0, noclear = 0, nowait = 0, nologin = 0;
|
|
||||||
size_t i, num = 0;
|
size_t i, num = 0;
|
||||||
char *tok, *cmd = NULL, *args[TTY_MAX_ARGS];
|
char *tok, *cmd = NULL, *args[TTY_MAX_ARGS], buf[256];
|
||||||
char *dev = NULL, *baud = NULL;
|
char *dev = NULL, *baud = NULL;
|
||||||
char *runlevels = NULL, *term = NULL;
|
char *runlevels = NULL, *term = NULL;
|
||||||
|
int insert = 0, noclear = 0, nowait = 0, nologin = 0, atcon = 0;
|
||||||
|
|
||||||
if (!line) {
|
if (!line) {
|
||||||
_e("Missing argument");
|
_e("Missing argument");
|
||||||
@@ -220,6 +204,24 @@ int tty_register(char *line, struct rlimit rlimit[], char *file)
|
|||||||
return errno = EINVAL;
|
return errno = EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Auto-detect serial console, for embedded devices mostly */
|
||||||
|
if (!strcmp(dev, "@console")) {
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
fp = fopen("/sys/class/tty/console/active", "r");
|
||||||
|
if (!fp) {
|
||||||
|
_e("Cannot find system console, is sysfs not mounted?");
|
||||||
|
return errno = ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
atcon = 1;
|
||||||
|
if (fgets(buf, sizeof(buf), fp))
|
||||||
|
dev = strtok(chomp(buf), " \t");
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
again:
|
||||||
/* Ensure all getty (built-in + external) are registered with absolute path */
|
/* Ensure all getty (built-in + external) are registered with absolute path */
|
||||||
dev = canonicalize(dev);
|
dev = canonicalize(dev);
|
||||||
if (!dev)
|
if (!dev)
|
||||||
@@ -278,6 +280,14 @@ int tty_register(char *line, struct rlimit rlimit[], char *file)
|
|||||||
entry->dirty = 0; /* Not modified */
|
entry->dirty = 0; /* Not modified */
|
||||||
_d("TTY %s is %sdirty", dev, entry->dirty ? "" : "NOT ");
|
_d("TTY %s is %sdirty", dev, entry->dirty ? "" : "NOT ");
|
||||||
|
|
||||||
|
if (atcon) {
|
||||||
|
dev = strtok(NULL, " \t");
|
||||||
|
if (dev) {
|
||||||
|
_d("Found another @console: %s", dev);
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user