Help wanted, setconsole problem

Denys Vlasenko vda.linux at googlemail.com
Tue Apr 17 17:36:27 UTC 2012


On Tue, Apr 3, 2012 at 11:57 PM, ralda at gmx.de <ralda at gmx.de> wrote:
> Update after some more tests ...
>
>> setconsole /dev/tty63
>>
>> echo "Test" >/dev/console
>> sh: write error: Bad file descriptor
>> (strace verified: the write call fails with Bad file descriptor)
>
> After a long search I found the right Gentoo package to install
> the upstream version of setconsole ... and that one works !
>
> setconsole /dev/tty63 </dev/console
> echo "Test" >/dev/console
> Outputs the expected "Test" on tty63
>
> So strace reveals some differences:
>
> Upstream setconsole does:
> open /dev/tty63, O_WRONLY|O_NONBLOCK -> fd 3
> ioctl 3, TCGETS
> ioctl 0, TIOCCONS
> ioctl 3, TIOCCONS
> close 3
>
> Busybox setconsole does:
> open /dev/tty63, O_RDONLY|O_LARGEFILE -> fd 3
> ioctl 3, TIOCCONS


commit 8dc6195c97e6bfc70a0158bce40c87d74d1a83d6
Author: Peter Korsgaard <jacmet at sunsite.dk>
Date:   Thu May 26 17:51:37 2011 +0200

    setconsole: open console for writing rather than reading

    The console passed to TIOCCONS has to be writable, otherwise future
    console writes will fail.

    This presumably used to work, but in current kernels (see
    drivers/tty/tty_io.c:redirected_tty_write) console writes are sent to
    vfs_write(device), which checks if the device is writable. A quick look
    in the linux git history doesn't show any recent changes to either tty_io
    or vfs_write.

    Signed-off-by: Peter Korsgaard <jacmet at sunsite.dk>
    Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>

diff --git a/console-tools/setconsole.c b/console-tools/setconsole.c
index 59c8336..771974a 100644
--- a/console-tools/setconsole.c
+++ b/console-tools/setconsole.c
@@ -41,6 +41,6 @@ int setconsole_main(int argc UNUSED_PARAM, char **argv)
                        device = DEV_CONSOLE;
        }

-       xioctl(xopen(device, O_RDONLY), TIOCCONS, NULL);
+       xioctl(xopen(device, O_WRONLY), TIOCCONS, NULL);
        return EXIT_SUCCESS;
 }


More information about the busybox mailing list