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

console-setup for FreeBSD



[Please send CC to me if you reply.]

I hope the next version of console-setup will have some preliminary 
support for FreeBSD kernel.  But I have some questions.

1. How can I detect in a shell script what kernel is in use (Linux or 
FreeBSD).  This code should work both in normal Debian installation and 
in the environment of Debian installer.

2. Is it dangerous to configure the console while X is running? Is it 
possible to detect reliably whether a script executes on the console or 
in X Window?  For Linux I've used a code like this:

case `readlink /proc/self/fd/2` in
    /dev/tty[0-9]*|/dev/vc/[0-9]*|/dev/console)
        ;;
    *)
        echo We are not on the Linux console, the console is left unconfigured.
        exit 0 
        ;;
esac

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;
}

3. I suppose UTF-8 is not supported?

Anton Zinoviev



Reply to: