mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
cttyhack: handle multiple consoles found in sysfs
If multiple consoles are found from the sysfs file, cttyhack fails: cttyhack: can't open '/dev/tty0 ttyS0': No such file or directory In such cases take the last one as the kernel will use that one for /dev/console. Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
ef43beac63
commit
6e9d047c15
@ -123,15 +123,22 @@ int cttyhack_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
* TIOCGSERIAL check, which assumes that all
|
* TIOCGSERIAL check, which assumes that all
|
||||||
* serial lines follow /dev/ttySn convention -
|
* serial lines follow /dev/ttySn convention -
|
||||||
* which is not always the case.
|
* which is not always the case.
|
||||||
* Therefore, we use this methos first:
|
* Therefore, we use this method first:
|
||||||
*/
|
*/
|
||||||
int s = open_read_close("/sys/class/tty/console/active",
|
int s = open_read_close("/sys/class/tty/console/active",
|
||||||
console + 5, sizeof(console) - 5);
|
console + 5, sizeof(console) - 5);
|
||||||
if (s > 0) {
|
if (s > 0) {
|
||||||
/* found active console via sysfs (Linux 2.6.38+)
|
char *last;
|
||||||
* sysfs string looks like "ttyS0\n" so zap the newline:
|
/* Found active console via sysfs (Linux 2.6.38+).
|
||||||
|
* It looks like "[tty0 ]ttyS0\n" so zap the newline:
|
||||||
*/
|
*/
|
||||||
console[4 + s] = '\0';
|
console[4 + s] = '\0';
|
||||||
|
/* If there are multiple consoles,
|
||||||
|
* take the last one:
|
||||||
|
*/
|
||||||
|
last = strrchr(console + 5, ' ');
|
||||||
|
if (last)
|
||||||
|
overlapping_strcpy(console + 5, last + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user