X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=miscutils%2Fconspy.c;h=01928b35f5b1e399ef2164d32dc1742dfd93f01a;hb=e298ce69baef029f3951dd1d5ed50fdbc6c55c80;hp=565922ca07309af4aa6eb0e79f111e4d59fceaa2;hpb=fa5ea17b5f6457d888a30afeff87420b7fe0348a;p=oweals%2Fbusybox.git diff --git a/miscutils/conspy.c b/miscutils/conspy.c index 565922ca0..01928b35f 100644 --- a/miscutils/conspy.c +++ b/miscutils/conspy.c @@ -7,7 +7,7 @@ * Based on Russell Stuart's conspy.c * http://ace-host.stuart.id.au/russell/files/conspy.c * - * Licensed under GPLv2 or later, see file License in this tarball for details. + * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ //applet:IF_CONSPY(APPLET(conspy, _BB_DIR_BIN, _BB_SUID_DROP)) @@ -17,6 +17,7 @@ //config:config CONSPY //config: bool "conspy" //config: default n +//config: depends on PLATFORM_LINUX //config: help //config: A text-mode VNC like program for Linux virtual terminals. //config: example: conspy NUM shared access to console num @@ -309,10 +310,7 @@ static void create_cdev_if_doesnt_exist(const char* name, dev_t dev) static NOINLINE void start_shell_in_child(const char* tty_name) { - int pid = vfork(); - if (pid < 0) { - bb_perror_msg_and_die("vfork"); - } + int pid = xvfork(); if (pid == 0) { struct termios termchild; char *shell = getenv("SHELL"); @@ -517,21 +515,23 @@ int conspy_main(int argc UNUSED_PARAM, char **argv) G.key_count += bytes_read; handle = xopen(tty_name, O_WRONLY); result = ioctl(handle, KDGKBMODE, &kbd_mode); - if (result == -1) - /* nothing */; - else if (kbd_mode != K_XLATE && kbd_mode != K_UNICODE) - G.key_count = 0; // scan code mode - else { + if (result >= 0) { char *p = keybuf; - for (; G.key_count != 0 && result != -1; p++, G.key_count--) { + + if (kbd_mode != K_XLATE && kbd_mode != K_UNICODE) { + G.key_count = 0; // scan code mode + } + for (; G.key_count != 0; p++, G.key_count--) { result = ioctl(handle, TIOCSTI, p); + if (result < 0) { + memmove(keybuf, p, G.key_count); + break; + } // If there is an application on console which reacts // to keypresses, we need to make our first sleep // shorter to quickly redraw whatever it printed there. poll_timeout_ms = 20; } - if (G.key_count) - memmove(keybuf, p, G.key_count); } // Close & re-open tty in case they have // swapped virtual consoles @@ -539,7 +539,7 @@ int conspy_main(int argc UNUSED_PARAM, char **argv) // We sometimes get spurious IO errors on the TTY // as programs close and re-open it - if (result != -1) + if (result >= 0) G.ioerror_count = 0; else if (errno != EIO || ++G.ioerror_count > 4) cleanup(1);