misc: do not hang if graphics backend is not available

This commit is contained in:
Vladimir Stoiakin 2025-05-12 17:47:29 +03:00
parent ba3f08698e
commit 23e24f7f89
4 changed files with 38 additions and 63 deletions

View file

@ -12,6 +12,7 @@ If a change only affects particular applications, they are listed in parentheses
- misc: Use standard C library instead of builtin functions (!49, thanks @vstoiakin)
- feat: Add support for split packaging of buffyboard and unl0kr (!54, thanks @vstoiakin)
- fix: Do not hang if graphics backend is not available (!57, thanks @vstoiakin)
## 3.3.0 (2025-04-15)

View file

@ -221,6 +221,10 @@ int main(int argc, char *argv[]) {
/* Initialise display */
lv_display_t *disp = lv_linux_fbdev_create();
if (access("/dev/fb0", F_OK) != 0) {
bbx_log(BBX_LOG_LEVEL_ERROR, "/dev/fb0 is not available");
sigaction_handler(SIGTERM);
}
lv_linux_fbdev_set_file(disp, "/dev/fb0");
if (conf_opts.quirks.fbdev_force_refresh) {
lv_linux_fbdev_set_force_refresh(disp, true);

View file

@ -25,7 +25,6 @@
#include <unistd.h>
#include <sys/reboot.h>
#include <sys/stat.h>
#include <sys/time.h>
@ -193,6 +192,11 @@ static void shutdown(void);
*/
static void sigaction_handler(int signum);
/**
* Restore the terminal and exit from the program with EXIT_FAILURE.
*/
static void exit_failure();
/**
* Static functions
@ -372,6 +376,11 @@ static void sigaction_handler(int signum) {
exit(0);
}
static void exit_failure() {
ul_terminal_reset_current_terminal();
exit(EXIT_FAILURE);
}
/**
* Main
@ -423,6 +432,10 @@ int main(int argc, char *argv[]) {
case UL_BACKENDS_BACKEND_FBDEV:
bbx_log(BBX_LOG_LEVEL_VERBOSE, "Using framebuffer backend");
disp = lv_linux_fbdev_create();
if (access("/dev/fb0", F_OK) != 0) {
bbx_log(BBX_LOG_LEVEL_ERROR, "/dev/fb0 is not available");
exit_failure();
}
lv_linux_fbdev_set_file(disp, "/dev/fb0");
if (conf_opts.quirks.fbdev_force_refresh) {
lv_linux_fbdev_set_force_refresh(disp, true);
@ -434,27 +447,28 @@ int main(int argc, char *argv[]) {
bbx_log(BBX_LOG_LEVEL_VERBOSE, "Using DRM backend");
disp = lv_linux_drm_create();
char *format_string = "/dev/dri/card%d";
char drm_path[16] = {0};
struct stat buffer;
char drm_path[16];
bool found = false;
for (int i = 0; i < 9; i++) {
sprintf(drm_path, "/dev/dri/card%d", i);
for (size_t i = 0; i < 9; i++) {
sprintf(drm_path, format_string, i);
if (stat(drm_path, &buffer) != 0) {
continue;
if (access(drm_path, F_OK) == 0) {
found = true;
break;
}
lv_linux_drm_set_file(disp, drm_path, -1);
break;
}
if (!found) {
bbx_log(BBX_LOG_LEVEL_ERROR, "/dev/dri/card* are not available");
exit_failure();
}
lv_linux_drm_set_file(disp, drm_path, -1);
break;
#endif /* LV_USE_LINUX_DRM */
default:
bbx_log(BBX_LOG_LEVEL_ERROR, "Unable to find suitable backend");
exit(EXIT_FAILURE);
exit_failure();
}
/* Override display properties with command line options if necessary */

View file

@ -26,50 +26,6 @@ static int current_fd = -1;
static int original_mode = -1;
static int original_kb_mode = -1;
/**
* Static prototypes
*/
/**
* Close the current file descriptor and reopen /dev/tty0.
*
* @return true if opening was successful, false otherwise
*/
static bool reopen_current_terminal(void);
/**
* Close the current file descriptor.
*/
static void close_current_terminal(void);
/**
* Static functions
*/
static bool reopen_current_terminal(void) {
close_current_terminal();
current_fd = open("/dev/tty0", O_RDWR);
if (current_fd < 0) {
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not open /dev/tty0");
return false;
}
return true;
}
static void close_current_terminal(void) {
if (current_fd < 0) {
return;
}
close(current_fd);
current_fd = -1;
}
/**
* Public functions
*/
@ -80,11 +36,10 @@ void ul_terminal_prepare_current_terminal(bool enable_graphics_mode, bool disabl
return;
}
/* Reopen the current terminal */
reopen_current_terminal();
/* Open the current terminal */
current_fd = open("/dev/tty0", O_RDWR);
if (current_fd < 0) {
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not prepare current terminal");
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not open /dev/tty0");
return;
}
@ -128,5 +83,6 @@ void ul_terminal_reset_current_terminal(void) {
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not reset terminal keyboard mode");
}
close_current_terminal();
close(current_fd);
current_fd = -1;
}