aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-10-31 16:57:04 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-10-31 16:57:04 +0100
commitf8a5b792ba3cb0d11531902a04600fc274dff69e (patch)
tree69dbd76a465a225db03b4b5fa44be49f4ac78cda
parent156840c249ddf761d9e60b06ca6d8aaa1bf88402 (diff)
downloadbusybox-w32-f8a5b792ba3cb0d11531902a04600fc274dff69e.tar.gz
busybox-w32-f8a5b792ba3cb0d11531902a04600fc274dff69e.tar.bz2
busybox-w32-f8a5b792ba3cb0d11531902a04600fc274dff69e.zip
cttyhack: move /sys/class/tty/console/active check to the front
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/cttyhack.c31
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)
117 /* We don't have ctty (or don't have "/dev/tty" node...) */ 117 /* We don't have ctty (or don't have "/dev/tty" node...) */
118 do { 118 do {
119#ifdef __linux__ 119#ifdef __linux__
120 int s; 120 /* Note that this method does not use _stdin_.
121 * Thus, "cttyhack </dev/something" can't be used.
122 * However, this method is more reliable than
123 * TIOCGSERIAL check, which assumes that all
124 * serial lines follow /dev/ttySn convention -
125 * which is not always the case.
126 * Therefore, we use this methos first:
127 */
128 int s = open_read_close("/sys/class/tty/console/active",
129 console + 5, sizeof(console) - 5);
130 if (s > 0) {
131 /* found active console via sysfs (Linux 2.6.38+)
132 * sysfs string looks like "ttyS0\n" so zap the newline:
133 */
134 console[4 + s] = '\0';
135 break;
136 }
137
121 if (ioctl(0, VT_GETSTATE, &u.vt) == 0) { 138 if (ioctl(0, VT_GETSTATE, &u.vt) == 0) {
122 /* this is linux virtual tty */ 139 /* this is linux virtual tty */
123 sprintf(console + 8, "S%u" + 1, (int)u.vt.v_active); 140 sprintf(console + 8, "S%u" + 1, (int)u.vt.v_active);
@@ -131,18 +148,6 @@ int cttyhack_main(int argc UNUSED_PARAM, char **argv)
131 break; 148 break;
132 } 149 }
133#endif 150#endif
134#ifdef __linux__
135 /* Note that this method is not related to _stdin_ */
136 s = open_read_close("/sys/class/tty/console/active",
137 console + 5, sizeof(console) - 5);
138 if (s > 0) {
139 /* found active console via sysfs (Linux 2.6.38+)
140 * sysfs string looks like "ttyS0\n" so zap the newline:
141 */
142 console[4 + s] = '\0';
143 break;
144 }
145#endif
146 /* nope, could not find it */ 151 /* nope, could not find it */
147 console[0] = '\0'; 152 console[0] = '\0';
148 } while (0); 153 } while (0);