From 47bbca6806ff90d6bf56d857da37645800b8285c Mon Sep 17 00:00:00 2001 From: Tyrolyean Date: Mon, 18 Jul 2022 00:06:34 +0200 Subject: [PATCH] Add fix for output being O_NONBLOCK This tries to remove the O_NONBLOCK flag from an output FD if the output seems to be setup this way. Signed-off-by: Tyrolyean --- shadermeh.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/shadermeh.c b/shadermeh.c index 6c7503b..ebc429b 100644 --- a/shadermeh.c +++ b/shadermeh.c @@ -5,6 +5,7 @@ * Copyright (C) 2022 David Oberhollenzer */ #include "shadermeh.h" +#include static GLfloat vertex_buffer[] = { -1.0f, -1.0f, 0.0f, /* lower left corner */ @@ -51,10 +52,23 @@ static int write_retry(int fd, const void *buffer, size_t size) int ret = write(fd, buffer, size); if (ret < 0) { - if (errno == EINTR) - continue; - perror("write"); - return -1; + if (errno == EINTR){ + continue; + }else if(errno == EAGAIN){ + perror("Output pipe probably has O_NONBLOCK " + "set! Removing setting"); + ret = fcntl(STDOUT_FILENO, F_SETFL, + fcntl(STDOUT_FILENO,F_GETFL) + &(~O_NONBLOCK)); + if(ret == -1){ + perror("Failed to set STDOUT blocking"); + return -1; + } + continue; + }else{ + perror("write"); + } + return -1; } if (ret == 0)