diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-10-31 19:57:04 +0400 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-10-31 19:57:04 +0400 |
commit | f8a5b792ba3cb0d11531902a04600fc274dff69e (patch) | |
tree | 69dbd76a465a225db03b4b5fa44be49f4ac78cda /shell | |
parent | 156840c249ddf761d9e60b06ca6d8aaa1bf88402 (diff) |
cttyhack: move /sys/class/tty/console/active check to the front
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/cttyhack.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/shell/cttyhack.c b/shell/cttyhack.c index 640f5b1fb..6ff867413 100644 --- a/shell/cttyhack.c +++ b/shell/cttyhack.c @@ -117,7 +117,24 @@ int cttyhack_main(int argc UNUSED_PARAM, char **argv) /* We don't have ctty (or don't have "/dev/tty" node...) */ do { #ifdef __linux__ - int s; + /* Note that this method does not use _stdin_. + * Thus, "cttyhack </dev/something" can't be used. + * However, this method is more reliable than + * TIOCGSERIAL check, which assumes that all + * serial lines follow /dev/ttySn convention - + * which is not always the case. + * Therefore, we use this methos first: + */ + int s = open_read_close("/sys/class/tty/console/active", + console + 5, sizeof(console) - 5); + if (s > 0) { + /* found active console via sysfs (Linux 2.6.38+) + * sysfs string looks like "ttyS0\n" so zap the newline: + */ + console[4 + s] = '\0'; + break; + } + if (ioctl(0, VT_GETSTATE, &u.vt) == 0) { /* this is linux virtual tty */ sprintf(console + 8, "S%u" + 1, (int)u.vt.v_active); @@ -131,18 +148,6 @@ int cttyhack_main(int argc UNUSED_PARAM, char **argv) break; } #endif -#ifdef __linux__ - /* Note that this method is not related to _stdin_ */ - s = open_read_close("/sys/class/tty/console/active", - console + 5, sizeof(console) - 5); - if (s > 0) { - /* found active console via sysfs (Linux 2.6.38+) - * sysfs string looks like "ttyS0\n" so zap the newline: - */ - console[4 + s] = '\0'; - break; - } -#endif /* nope, could not find it */ console[0] = '\0'; } while (0); |