On Tue, Dec 02, 2008 at 10:50:26PM +0100, Frans Pop wrote: > Someone who can actually write in C please check the code and let me know > if anything can be removed or is missing. I may well have added unneeded > includes for example and I have no idea what the original sprintf > statements were supposed to do.
Attached is a patch with a trimmed down version of console-type.c. As we are not interested in the settings of the serial line or by the state of the VT, we can just omit the struct declarations and be fine with a dummy buffer. As printf() and ioctl() are the only functions used, we can trim down the #include's to "<sys/ioctl.h>" and "<stdio.h>". Cheers, -- Jérémy Bobbio .''`. [EMAIL PROTECTED] : :Ⓐ : # apt-get install anarchism `. `'` `-
diff --git a/packages/rootskel/src/sbin/Makefile b/packages/rootskel/src/sbin/Makefile index b5e374e..83fb4bc 100644 --- a/packages/rootskel/src/sbin/Makefile +++ b/packages/rootskel/src/sbin/Makefile @@ -6,14 +6,18 @@ files_exec = \ shutdown \ init \ reopen-console \ + console-type \ steal-ctty +console-type: console-type.c + gcc -Os -Wall console-type.c -o console-type + steal-ctty: steal-ctty.c gcc -Os -Wall steal-ctty.c -o steal-ctty -build: steal-ctty +build: console-type steal-ctty clean: - rm -f steal-ctty + rm -f console-type steal-ctty include ../../Makefile.inc diff --git a/packages/rootskel/src/sbin/console-type.c b/packages/rootskel/src/sbin/console-type.c new file mode 100644 index 0000000..6105a3e --- /dev/null +++ b/packages/rootskel/src/sbin/console-type.c @@ -0,0 +1,30 @@ +/* vi: set sw=4 ts=4: */ +/* + * + * Licensed under GPLv2 + * + * Adapted for Debian Installer by Frans Pop <fjp.debian.org> from + * cttyhack from busybox 1.11, which is + * + * Copyright (c) 2007 Denys Vlasenko <[EMAIL PROTECTED]> + */ + +#include <sys/ioctl.h> +#include <stdio.h> + +enum { VT_GETSTATE = 0x5603 }; /* get global vt state info */ + +int main(int argc, char ** argv) +{ + char buffer[256]; /* filled by ioctl */ + + if (ioctl(0, TIOCGSERIAL, buffer) == 0) { + /* this is a serial console */ + printf("serial\n"); + } else if (ioctl(0, VT_GETSTATE, buffer) == 0) { + /* this is linux virtual tty */ + printf("virtual\n"); + } + + return 0; +} diff --git a/packages/rootskel/src/sbin/reopen-console b/packages/rootskel/src/sbin/reopen-console index c6c55b5..702ddc3 100755 --- a/packages/rootskel/src/sbin/reopen-console +++ b/packages/rootskel/src/sbin/reopen-console @@ -6,11 +6,18 @@ NL=" " +console= if ! [ -f /var/run/console-device ]; then - # If the kernel emitted an "handover" message, then it's the one + # If the kernel emitted a "handover" message, then it's the one console="$(dmesg -s 65535 | sed -n -e 's/.*\] console handover: boot \[.*\] -> real \[\(.*\)\]$/\1/p')" + # Except if it is the wrong type... + if [ "$console" ] && [ "$(console-type)" = serial ] && \ + expr "$console" : "tty[0-9]" >/dev/null; then + console= + fi + consoles= if [ -z "$console" ]; then # Retrieve all enabled consoles from boot log; ignore those
signature.asc
Description: Digital signature