[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Consoles and d-i



On Sun, Apr  3, 2011 at 15:03:32 +0100, Jurij Smakov wrote:

> >From d3f29283db9d58ad5b1702f66f9da15df6881526 Mon Sep 17 00:00:00 2001
> From: Jurij Smakov <jurij@debian.org>
> Date: Sun, 27 Mar 2011 20:14:56 +0100
> Subject: [PATCH] Use TIOCGDEV ioctl to find real serial console device on Linux.
> 
> Kernels >= 2.6.38 support TIOCGDEV ioctl, which allows to unambigously
> determine the real device corresponding to /dev/console. This change
> adds support to using if for real console device detection to
> rootskel.
> ---
>  debian/changelog                  |    2 ++
>  src/sbin/Makefile                 |   10 +++++++---
>  src/sbin/get-real-console-linux.c |   34 ++++++++++++++++++++++++++++++++++
>  src/sbin/reopen-console-linux     |    8 +++++++-
>  4 files changed, 50 insertions(+), 4 deletions(-)
>  create mode 100644 src/sbin/get-real-console-linux.c
> 
> diff --git a/debian/changelog b/debian/changelog
> index 487f4c0..e7e31f7 100644
> --- a/debian/changelog
> +++ b/debian/changelog
> @@ -7,6 +7,8 @@ rootskel (1.94) UNRELEASED; urgency=low
>    [ Jurij Smakov ]
>    * Set DEB_HOST_ARCH_OS in src/Makefile to make sure that everything builds
>      correctly without help from dpkg-buildpackage.
> +  * Switch to using TIOCGDEV ioctl for detection of the real console for
> +    kernels >= 2.6.38.
>  
>   -- Samuel Thibault <sthibault@debian.org>  Sat, 19 Mar 2011 20:21:40 +0100
>  
> diff --git a/src/sbin/Makefile b/src/sbin/Makefile
> index 64c91d3..dec554e 100644
> --- a/src/sbin/Makefile
> +++ b/src/sbin/Makefile
> @@ -13,22 +13,26 @@ files_exec = \
>  
>  ifeq ($(DEB_HOST_ARCH_OS),linux)
>    files_exec += \
> -	console-type
> +	console-type \
> +	get-real-console-linux
>  endif
>  
>  console-type: console-type.c
>  	gcc -Os -Wall console-type.c -o console-type
>  
> +get-real-console-linux:
> +	gcc -Os -Wall get-real-console-linux.c -o get-real-console-linux
> +
>  steal-ctty: steal-ctty.c
>  	gcc -Os -Wall steal-ctty.c -o steal-ctty
>  
>  ifeq ($(DEB_HOST_ARCH_OS),linux)
> -build: console-type steal-ctty
> +build: console-type get-real-console-linux steal-ctty
>  else
>  build: steal-ctty
>  endif
>  
>  clean:
> -	rm -f console-type steal-ctty
> +	rm -f console-type get-real-console-linux steal-ctty
>  
>  include ../../Makefile.inc
> diff --git a/src/sbin/get-real-console-linux.c b/src/sbin/get-real-console-linux.c
> new file mode 100644
> index 0000000..89c3a24
> --- /dev/null
> +++ b/src/sbin/get-real-console-linux.c
> @@ -0,0 +1,34 @@
> +/*
> + * Licensed under GPLv2
> + *
> + * Print out major:minor number of the real console device,
> + * using the TIOCGDEV ioctl (only works on kernels >= 2.6.38).
> + * 
> + * Copyright (c) 2011 Jurij Smakov <jurij@debian.org>
> + */
> +
> +#include <stdio.h>
> +#include <sys/ioctl.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +
> +#define TIOCGDEV        _IOR('T', 0x32, unsigned int)
> +

the define shouldn't be needed if you build-depend on
'linux-libc-dev (>= 2.6.38) [linux-any]'.

> +int main()
> +{
> +    int fd = 0;
> +    unsigned int dev;
> +       
> +    fd = open("/dev/console", O_WRONLY, 0);
> +    if (fd < 0) {
> +        perror("open");
> +        return(1);
> +    }
> +    if (ioctl(fd, TIOCGDEV, &dev) < 0) {
> +        perror("ioctl");
> +        return(2);
> +    }
> +    printf("%d:%d\n", major(dev), minor(dev));
> +    return(0);
> +}
> diff --git a/src/sbin/reopen-console-linux b/src/sbin/reopen-console-linux
> index 4e65a13..9062a8a 100755
> --- a/src/sbin/reopen-console-linux
> +++ b/src/sbin/reopen-console-linux
> @@ -14,9 +14,15 @@ if ! [ -f /var/run/console-device ]; then
>  		console="$(dmesg -s 65535 |
>  			sed -n -r -e 's/(.*\])? *console handover: boot \[.*\] -> real \[(.*)\]$/\2/p')"
>  		;;
> -	    *) # >=2.6.32
> +	    2.6.3[234567]*)
>  		console="$(dmesg -s 65535 |
>  			sed -n -r -e 's/(.*\])? *console \[(.*)\] enabled, bootconsole disabled$/\2/p')"
> +		;;
> +	    *) # >= 2.6.38
> +		console_major_minor="$(get-real-console-linux)"
> +		console_raw="$(readlink "/sys/dev/char/${console_major_minor}")"
> +		console="${console_raw##*/}"
> +		;;
>  	esac
>  
>  	# Except if it is the wrong type...

Looks sane to me other than that minor nit, fwiw.

Cheers,
Julien


Reply to: