From 2c2518164415705763fb1381cd5a040a6ce4cffc Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 12 Apr 2022 22:45:32 +0200 Subject: [PATCH] Terminal: Make the prerequisites check verbose (#8994) So we actually have a chance of understanding why it fails to load ;). (Also, properly require posix FFI stuff, in the unlikely event they aren't already in the main namespace). --- plugins/terminal.koplugin/main.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/plugins/terminal.koplugin/main.lua b/plugins/terminal.koplugin/main.lua index ec7d8cdea..6c7dd761e 100644 --- a/plugins/terminal.koplugin/main.lua +++ b/plugins/terminal.koplugin/main.lua @@ -5,8 +5,10 @@ This plugin provides a terminal emulator (VT52 (+some ANSI)) ]] local Device = require("device") +local logger = require("logger") local ffi = require("ffi") local C = ffi.C +require("ffi/posix_h") -- for terminal emulator ffi.cdef[[ @@ -23,14 +25,19 @@ int tcflush(int fd, int queue_selector) __attribute__((nothrow, leaf)); ]] local function check_prerequisites() - local ptmx_name = "/dev/ptmx" - local ptmx = C.open(ptmx_name, bit.bor(C.O_RDWR, C.O_NONBLOCK, C.O_CLOEXEC)) + local ptmx = C.open("/dev/ptmx", bit.bor(C.O_RDWR, C.O_NONBLOCK, C.O_CLOEXEC)) + if ptmx == -1 then + logger.warn("Terminal: can not open /dev/ptmx:", ffi.string(C.strerror(ffi.errno()))) + return false + end if C.grantpt(ptmx) ~= 0 then + logger.warn("Terminal: can not grantpt:", ffi.string(C.strerror(ffi.errno()))) C.close(ptmx) return false end if C.unlockpt(ptmx) ~= 0 then + logger.warn("Terminal: can not unlockpt:", ffi.string(C.strerror(ffi.errno()))) C.close(ptmx) return false end @@ -60,7 +67,6 @@ local TermInputText = require("terminputtext") local TextWidget = require("ui/widget/textwidget") local bit = require("bit") local lfs = require("libs/libkoreader-lfs") -local logger = require("logger") local _ = require("gettext") local T = require("ffi/util").template @@ -100,17 +106,17 @@ function Terminal:spawnShell(cols, rows) self.ptmx = C.open(ptmx_name, bit.bor(C.O_RDWR, C.O_NONBLOCK, C.O_CLOEXEC)) if self.ptmx == -1 then - logger.err("Terminal: can not open", ptmx_name, ffi.string(C.strerror(ffi.errno()))) + logger.err("Terminal: can not open", ptmx_name .. ":", ffi.string(C.strerror(ffi.errno()))) return false end if C.grantpt(self.ptmx) ~= 0 then - logger.err("Terminal: can not grantpt", ffi.string(C.strerror(ffi.errno()))) + logger.err("Terminal: can not grantpt:", ffi.string(C.strerror(ffi.errno()))) C.close(self.ptmx) return false end if C.unlockpt(self.ptmx) ~= 0 then - logger.err("Terminal: can not unockpt", ffi.string(C.strerror(ffi.errno()))) + logger.err("Terminal: can not unockpt:", ffi.string(C.strerror(ffi.errno()))) C.close(self.ptmx) return false end @@ -128,7 +134,7 @@ function Terminal:spawnShell(cols, rows) local pid = C.fork() if pid < 0 then - logger.err("Terminal: fork failed", ffi.string(C.strerror(ffi.errno()))) + logger.err("Terminal: fork failed:", ffi.string(C.strerror(ffi.errno()))) return false elseif pid == 0 then C.close(self.ptmx)