Skip to content

Commit

Permalink
Merge pull request #59 from gridpoint-com/fb0-timeout
Browse files Browse the repository at this point in the history
Wait for upto 60s for /dev/fb0 to become available
  • Loading branch information
crertel authored Dec 6, 2023
2 parents 5aa0f02 + c1ad699 commit 4f9be00
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion c_src/device/cairo/cairo_fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
#include <errno.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sched.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>

#include "cairo_ctx.h"
#include "comms.h"
#include "device.h"
#include "fontstash.h"
#include "scenic_ops.h"

#define FB0_TIMEOUT 60 //seconds
const char* device = "/dev/fb0";

typedef struct {
Expand Down Expand Up @@ -95,7 +98,15 @@ int device_init(const device_opts_t* p_opts,

p_info->v_ctx = p_ctx;

if ((g_cairo_fb.fd = open(device, O_RDWR)) == -1) {
time_t fb0_timer_start = time(NULL);
while ((time(NULL) - fb0_timer_start) < FB0_TIMEOUT) {
if ((g_cairo_fb.fd = open(device, O_RDWR)) != -1) {
break;
}
sched_yield();
}

if (g_cairo_fb.fd == -1) {
log_error("Failed to open device %s: %s", device, strerror(errno));
return -1;
}
Expand Down

0 comments on commit 4f9be00

Please sign in to comment.