aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-05-14 04:08:20 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-05-14 04:08:20 +0200
commit5055a9f98999d3a6c2f4d043a85f6c2d6fb7eaf2 (patch)
tree0422ae543b6182b918f5f0c97e83a7d841436f9f
parente82cf339e476126e4016e417aee3c6eb52c702c9 (diff)
downloadbusybox-w32-5055a9f98999d3a6c2f4d043a85f6c2d6fb7eaf2.tar.gz
busybox-w32-5055a9f98999d3a6c2f4d043a85f6c2d6fb7eaf2.tar.bz2
busybox-w32-5055a9f98999d3a6c2f4d043a85f6c2d6fb7eaf2.zip
cttyhack: don't do anything if ctty is already available
function old new delta cttyhack_main 244 269 +25 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/cttyhack.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/shell/cttyhack.c b/shell/cttyhack.c
index 572a3af03..bde2acdc9 100644
--- a/shell/cttyhack.c
+++ b/shell/cttyhack.c
@@ -53,23 +53,32 @@ int cttyhack_main(int argc UNUSED_PARAM, char **argv)
53 } 53 }
54 54
55 strcpy(console, "/dev/tty"); 55 strcpy(console, "/dev/tty");
56 if (ioctl(0, TIOCGSERIAL, &u.sr) == 0) { 56 fd = open(console, O_RDWR);
57 /* this is a serial console */ 57 if (fd >= 0) {
58 sprintf(console + 8, "S%d", u.sr.line); 58 /* We already have ctty, nothing to do */
59 } else if (ioctl(0, VT_GETSTATE, &u.vt) == 0) { 59 close(fd);
60 /* this is linux virtual tty */ 60 } else {
61 sprintf(console + 8, "S%d" + 1, u.vt.v_active); 61 /* We don't have ctty (or don't have "/dev/tty" node...) */
62 } 62 if (ioctl(0, TIOCGSERIAL, &u.sr) == 0) {
63 63 /* this is a serial console */
64 if (console[8]) { 64 sprintf(console + 8, "S%d", u.sr.line);
65 fd = xopen(console, O_RDWR); 65 } else if (ioctl(0, VT_GETSTATE, &u.vt) == 0) {
66 //bb_error_msg("switching to '%s'", console); 66 /* this is linux virtual tty */
67 dup2(fd, 0); 67 sprintf(console + 8, "S%d" + 1, u.vt.v_active);
68 dup2(fd, 1); 68 }
69 dup2(fd, 2); 69 if (console[8]) {
70 while (fd > 2) close(fd--); 70 fd = xopen(console, O_RDWR);
71 /* Some other session may have it as ctty. Steal it from them */ 71 //bb_error_msg("switching to '%s'", console);
72 ioctl(0, TIOCSCTTY, 1); 72 dup2(fd, 0);
73 dup2(fd, 1);
74 dup2(fd, 2);
75 while (fd > 2)
76 close(fd--);
77 /* Some other session may have it as ctty,
78 * steal it from them:
79 */
80 ioctl(0, TIOCSCTTY, 1);
81 }
73 } 82 }
74 83
75 BB_EXECVP(argv[0], argv); 84 BB_EXECVP(argv[0], argv);