Last active
October 9, 2024 11:31
-
-
Save legionus/1cc007048481bd41b47196592244a697 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/libkfont/kdfontop.c b/src/libkfont/kdfontop.c | |
index 1eadbebb..cada3f95 100644 | |
--- a/src/libkfont/kdfontop.c | |
+++ b/src/libkfont/kdfontop.c | |
@@ -21,11 +21,29 @@ | |
#include "compat/linux-kd.h" | |
#endif | |
+static int | |
+is_kd_text(struct kfont_context *ctx, int fd) | |
+{ | |
+ unsigned int kd_mode; | |
+ | |
+ if (ioctl(fd, KDGETMODE, &kd_mode)) { | |
+ KFONT_ERR(ctx, "ioctl(KDGETMODE): %m"); | |
+ return 0; | |
+ } | |
+ | |
+ return (kd_mode == KD_TEXT); | |
+} | |
+ | |
int | |
kfont_restore_font(struct kfont_context *ctx, int fd) | |
{ | |
struct console_font_op cfo; | |
+ if (!is_kd_text(ctx, fd)) { | |
+ KFONT_ERR(ctx, _("Console is not in text mode")); | |
+ return -1; | |
+ } | |
+ | |
cfo.op = KD_FONT_OP_SET_DEFAULT; | |
if (ioctl(fd, KDFONTOP, &cfo)) { | |
@@ -60,6 +78,11 @@ get_font_kdfontop(struct kfont_context *ctx, int consolefd, | |
{ | |
struct console_font_op cfo; | |
+ if (!is_kd_text(ctx, consolefd)) { | |
+ KFONT_ERR(ctx, _("Console is not in text mode")); | |
+ return -1; | |
+ } | |
+ | |
cfo.op = KD_FONT_OP_GET; | |
cfo.flags = 0; | |
cfo.width = 32; | |
@@ -162,6 +185,11 @@ put_font_kdfontop(struct kfont_context *ctx, int consolefd, unsigned char *buf, | |
{ | |
struct console_font_op cfo; | |
+ if (!is_kd_text(ctx, consolefd)) { | |
+ KFONT_ERR(ctx, _("Console is not in text mode")); | |
+ return -1; | |
+ } | |
+ | |
if (vpitch == 32 && width <= 32) | |
cfo.op = KD_FONT_OP_SET; | |
else { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment