aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPascal Bellard <pascal.bellard@ads-lu.com>2010-07-01 07:18:41 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-07-01 07:18:41 +0200
commit81199672bed1446fa6b584728c92ecfb11bc530b (patch)
tree545f6f3bfbff6018edfcfeb14ea5d4c3549cdc1d
parent45f66167fe96de219aac91d842f3e64d857340f6 (diff)
downloadbusybox-w32-81199672bed1446fa6b584728c92ecfb11bc530b.tar.gz
busybox-w32-81199672bed1446fa6b584728c92ecfb11bc530b.tar.bz2
busybox-w32-81199672bed1446fa6b584728c92ecfb11bc530b.zip
conspy: stop losing some keyboard keys.
11 bytes shrink. Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/conspy.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/miscutils/conspy.c b/miscutils/conspy.c
index 565922ca0..3f341ce18 100644
--- a/miscutils/conspy.c
+++ b/miscutils/conspy.c
@@ -517,21 +517,23 @@ int conspy_main(int argc UNUSED_PARAM, char **argv)
517 G.key_count += bytes_read; 517 G.key_count += bytes_read;
518 handle = xopen(tty_name, O_WRONLY); 518 handle = xopen(tty_name, O_WRONLY);
519 result = ioctl(handle, KDGKBMODE, &kbd_mode); 519 result = ioctl(handle, KDGKBMODE, &kbd_mode);
520 if (result == -1) 520 if (result >= 0) {
521 /* nothing */;
522 else if (kbd_mode != K_XLATE && kbd_mode != K_UNICODE)
523 G.key_count = 0; // scan code mode
524 else {
525 char *p = keybuf; 521 char *p = keybuf;
526 for (; G.key_count != 0 && result != -1; p++, G.key_count--) { 522
523 if (kbd_mode != K_XLATE && kbd_mode != K_UNICODE) {
524 G.key_count = 0; // scan code mode
525 }
526 for (; G.key_count != 0; p++, G.key_count--) {
527 result = ioctl(handle, TIOCSTI, p); 527 result = ioctl(handle, TIOCSTI, p);
528 if (result < 0) {
529 memmove(keybuf, p, G.key_count);
530 break;
531 }
528 // If there is an application on console which reacts 532 // If there is an application on console which reacts
529 // to keypresses, we need to make our first sleep 533 // to keypresses, we need to make our first sleep
530 // shorter to quickly redraw whatever it printed there. 534 // shorter to quickly redraw whatever it printed there.
531 poll_timeout_ms = 20; 535 poll_timeout_ms = 20;
532 } 536 }
533 if (G.key_count)
534 memmove(keybuf, p, G.key_count);
535 } 537 }
536 // Close & re-open tty in case they have 538 // Close & re-open tty in case they have
537 // swapped virtual consoles 539 // swapped virtual consoles
@@ -539,7 +541,7 @@ int conspy_main(int argc UNUSED_PARAM, char **argv)
539 541
540 // We sometimes get spurious IO errors on the TTY 542 // We sometimes get spurious IO errors on the TTY
541 // as programs close and re-open it 543 // as programs close and re-open it
542 if (result != -1) 544 if (result >= 0)
543 G.ioerror_count = 0; 545 G.ioerror_count = 0;
544 else if (errno != EIO || ++G.ioerror_count > 4) 546 else if (errno != EIO || ++G.ioerror_count > 4)
545 cleanup(1); 547 cleanup(1);