attempt to support VT switches on OpenBSD

This commit is contained in:
Matthieu Herrb 2024-07-10 15:19:41 +02:00
parent cc09e26976
commit b4462cb033
3 changed files with 37 additions and 5 deletions

View file

@ -21,11 +21,17 @@
#define K_ENABLE K_XLATE #define K_ENABLE K_XLATE
#define K_DISABLE K_RAW #define K_DISABLE K_RAW
#define FRSIG SIGIO #define FRSIG SIGIO
#elif defined(__NetBSD__) || defined(__OpenBSD__) #elif defined(__NetBSD__)
#include <dev/wscons/wsdisplay_usl_io.h> #include <dev/wscons/wsdisplay_usl_io.h>
#define K_ENABLE K_XLATE #define K_ENABLE K_XLATE
#define K_DISABLE K_RAW #define K_DISABLE K_RAW
#define FRSIG 0 // unimplemented #define FRSIG 0 // unimplemented
#elif defined(__OpenBSD__)
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsdisplay_usl_io.h>
#define K_ENABLE K_XLATE
#define K_DISABLE K_RAW
#define FRSIG SIGIO
#else #else
#error Unsupported platform #error Unsupported platform
#endif #endif
@ -161,10 +167,16 @@ static int get_tty_path(int tty, char path[static TTYPATHLEN]) {
int terminal_open(int vt) { int terminal_open(int vt) {
char path[TTYPATHLEN]; char path[TTYPATHLEN];
log_debugf("terminal_open vt %d", vt);
#ifdef __OpenBSD__
if (vt > 0)
vt--;
#endif
if (get_tty_path(vt, path) == -1) { if (get_tty_path(vt, path) == -1) {
log_errorf("Could not generate tty path: %s", strerror(errno)); log_errorf("Could not generate tty path: %s", strerror(errno));
return -1; return -1;
} }
log_debugf("terminal_open path %s", path);
int fd = open(path, O_RDWR | O_NOCTTY); int fd = open(path, O_RDWR | O_NOCTTY);
if (fd == -1) { if (fd == -1) {
log_errorf("Could not open target tty: %s", strerror(errno)); log_errorf("Could not open target tty: %s", strerror(errno));
@ -174,7 +186,7 @@ int terminal_open(int vt) {
} }
int terminal_current_vt(int fd) { int terminal_current_vt(int fd) {
#if defined(__linux__) || defined(__NetBSD__) #if defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__)
struct vt_stat st; struct vt_stat st;
int res = ioctl(fd, VT_GETSTATE, &st); int res = ioctl(fd, VT_GETSTATE, &st);
close(fd); close(fd);
@ -183,7 +195,7 @@ int terminal_current_vt(int fd) {
return -1; return -1;
} }
return st.v_active; return st.v_active;
#elif defined(__FreeBSD__) || defined(__OpenBSD__) #elif defined(__FreeBSD__)
int vt; int vt;
int res = ioctl(fd, VT_GETACTIVE, &vt); int res = ioctl(fd, VT_GETACTIVE, &vt);
close(fd); close(fd);
@ -252,11 +264,20 @@ int terminal_ack_acquire(int fd) {
int terminal_set_keyboard(int fd, bool enable) { int terminal_set_keyboard(int fd, bool enable) {
log_debugf("Setting KD keyboard state to %d", enable); log_debugf("Setting KD keyboard state to %d", enable);
#ifndef __OpenBSD1__
if (ioctl(fd, KDSKBMODE, enable ? K_ENABLE : K_DISABLE) == -1) { if (ioctl(fd, KDSKBMODE, enable ? K_ENABLE : K_DISABLE) == -1) {
log_errorf("Could not set KD keyboard mode to %s: %s", log_errorf("Could not set KD keyboard mode to %s: %s",
enable ? "enabled" : "disabled", strerror(errno)); enable ? "enabled" : "disabled", strerror(errno));
return -1; return -1;
} }
#else
int mode = enable ? WSKBD_RAW : WSKBD_TRANSLATED;
if (ioctl(fd, WSKBDIO_SETMODE, &mode) == -1) {
log_errorf("Could not set keyboard mode to %s: %s",
enable ? "translated" : "raw", strerror(errno));
return -1;
}
#endif
#if defined(__FreeBSD__) #if defined(__FreeBSD__)
struct termios tios; struct termios tios;
if (tcgetattr(fd, &tios) == -1) { if (tcgetattr(fd, &tios) == -1) {
@ -279,10 +300,19 @@ int terminal_set_keyboard(int fd, bool enable) {
int terminal_set_graphics(int fd, bool enable) { int terminal_set_graphics(int fd, bool enable) {
log_debugf("Setting KD graphics state to %d", enable); log_debugf("Setting KD graphics state to %d", enable);
#ifndef __OpenBSD1__
if (ioctl(fd, KDSETMODE, enable ? KD_GRAPHICS : KD_TEXT) == -1) { if (ioctl(fd, KDSETMODE, enable ? KD_GRAPHICS : KD_TEXT) == -1) {
log_errorf("Could not set KD graphics mode to %s: %s", enable ? "graphics" : "text", log_errorf("Could not set KD graphics mode to %s: %s", enable ? "graphics" : "text",
strerror(errno)); strerror(errno));
return -1; return -1;
} }
#else
int mode = enable ? WSDISPLAYIO_MODE_MAPPED : WSDISPLAYIO_MODE_EMUL;
if (ioctl(fd, WSDISPLAYIO_SMODE, &mode) == -1) {
log_errorf("Could not set graphics mode to %s: %s",
enable ? "mapped" : "emul", strerror(errno));
return -1;
}
#endif
return 0; return 0;
} }

View file

@ -327,7 +327,7 @@ static int handle_switch_session(struct client *client, int session) {
log_error("Protocol error: no seat associated with client"); log_error("Protocol error: no seat associated with client");
return -1; return -1;
} }
log_debugf("handle_switch_session %d", session);
if (seat_set_next_session(client, session) == -1) { if (seat_set_next_session(client, session) == -1) {
goto error; goto error;
} }
@ -370,6 +370,7 @@ static int handle_ping(struct client *client) {
static int client_handle_opcode(struct client *client, uint16_t opcode, size_t size) { static int client_handle_opcode(struct client *client, uint16_t opcode, size_t size) {
int res = 0; int res = 0;
log_debugf("client_handle_opcode: %d\n", opcode);
switch (opcode) { switch (opcode) {
case CLIENT_OPEN_SEAT: { case CLIENT_OPEN_SEAT: {
if (size != 0) { if (size != 0) {

View file

@ -87,8 +87,8 @@ static int vt_close(int vt) {
return -1; return -1;
} }
terminal_set_process_switching(ttyfd, true); terminal_set_process_switching(ttyfd, true);
terminal_set_keyboard(ttyfd, true);
terminal_set_graphics(ttyfd, false); terminal_set_graphics(ttyfd, false);
terminal_set_keyboard(ttyfd, true);
close(ttyfd); close(ttyfd);
return 0; return 0;
} }
@ -107,6 +107,7 @@ static int vt_switch(struct seat *seat, int vt) {
static int vt_ack(struct seat *seat, bool release) { static int vt_ack(struct seat *seat, bool release) {
int tty0fd = terminal_open(seat->cur_vt); int tty0fd = terminal_open(seat->cur_vt);
log_debugf("vt_ack VT %d %d\n", seat->cur_vt, release);
if (tty0fd == -1) { if (tty0fd == -1) {
log_errorf("Could not open tty0 to ack VT signal: %s", strerror(errno)); log_errorf("Could not open tty0 to ack VT signal: %s", strerror(errno));
return -1; return -1;