small changes

This commit is contained in:
2024-08-07 00:07:44 +02:00
parent e745b27a68
commit 4de2720bed
3 changed files with 22 additions and 14 deletions

View File

@@ -1,15 +1,18 @@
#include "chvt.h"
#include <stdio.h>
#include <chvt.h>
static char *vterms[] = {"/dev/tty", "/dev/tty0", "/dev/vc/0", "/dev/systty",
"/dev/console"};
int chvt(int n) {
fprintf(stderr, "activating vt %d\n", n);
char c = 0;
for (int i = 0; i < sizeof(vterms) / sizeof(vterms[0]); i++) {
int fd = open(vterms[i], O_RDWR);
if (fd >= 0 && isatty(fd) && ioctl(fd, KDGKBTYPE, &c) == 0 && c < 3) {
if (ioctl(fd, VT_ACTIVATE, n) < 0 || ioctl(fd, VT_WAITACTIVE, n) < 0) {
printf("Couldn't active vt %d\n", n);
fprintf(stderr, "Couldn't activate vt %d\n", n);
return -1;
}
return 0;
@@ -17,6 +20,6 @@ int chvt(int n) {
close(fd);
}
printf("Couldn't get a file descriptor referring to the console.\n");
fprintf(stderr, "Couldn't get a file descriptor referring to the console.\n");
return -1;
}