[Pkg-kbd-devel] Bug#618573: Needed some way to test whether we are on the console

Anton Zinoviev anton at lml.bas.bg
Wed Mar 16 16:08:10 UTC 2011


Package: kbd
Severity: wishlist

Hello,

Console-setup needs some way to test whether we are on the console or 
not (in order not to damage a running X).  Because of Debconf this 
should work when the program is detached from the actual virtual 
terminal (so /usr/bin/tty doesn't work).

For FreeBSD I found the following solution in the net 
(http://www.opennet.ru/tips/info/1448.shtml, in Russian language):

if vidcontrol -i adapter >&- 2>&-; then
   echo We are on the console
else
   echo We are not on the console.
fi

(Vidcontrol is the FreeBSD analogue of the setfont+fbset combination.)

Unfortunately I don't know if something similar can work for Linux but 
Julien Cristau contributed the following code:

#include <stdio.h>
#include <err.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/kd.h>

int main() {
	int fd;
	int rc;
	int mode;

	fd = open("/dev/tty0", O_RDONLY);
	if (fd < 0)
		err(1, "open(/dev/tty0)");
	rc = ioctl(fd, KDGETMODE, &mode);
	if (rc < 0)
		err(1, "ioctl(KDGETMODE)");
	switch (mode) {
		case KD_TEXT:
			printf("text\n");
			break;
		case KD_GRAPHICS:
			printf("graphics\n");
			break;
		default:
			printf("other (%d)\n", mode);
			break;
	}
	return 0;
}

Would it be possible to include something like this in kbd?  I don't 
like the idea to include a binary Linux-only utility in an architecture 
independent package such as console-setup.

Anton Zinoviev






More information about the Pkg-kbd-devel mailing list