Commit c8fe917e authored by Benoît Minisini's avatar Benoît Minisini
Browse files

Pipes are now always internally opened for writing, to workaround a 'glib'...

Pipes are now always internally opened for writing, to workaround a 'glib' behaviour, that eats 100% CPU when there is no writer anymore on a pipe watched for reading.

[INTERPRETER]
* BUG: Pipes are now always internally opened for writing, to workaround a 'glib' behaviour, that eats 100% CPU when there is no writer anymore on a pipe watched for reading.
parent e08d47dd
Pipeline #336536418 passed with stage
in 24 minutes and 7 seconds
......@@ -100,6 +100,14 @@ typedef
}
STREAM_DIRECT;
typedef
struct {
STREAM_COMMON common;
int fd;
unsigned can_write : 1;
}
STREAM_PIPE;
typedef
struct {
STREAM_COMMON common;
......@@ -155,7 +163,7 @@ typedef
STREAM_RESERVED _reserved;
STREAM_DIRECT direct;
STREAM_BUFFER buffer;
STREAM_DIRECT pipe;
STREAM_PIPE pipe;
STREAM_MEMORY memory;
STREAM_ARCH arch;
STREAM_PROCESS process;
......
......@@ -56,19 +56,19 @@ static int stream_open(STREAM *stream, const char *path, int mode)
switch (mode & GB_ST_MODE)
{
case GB_ST_READ: fmode |= O_RDONLY | O_NONBLOCK; break;
case GB_ST_READ: fmode |= O_RDWR; break;
case GB_ST_WRITE: fmode |= O_WRONLY; break;
case GB_ST_READ_WRITE: fmode |= O_RDWR; break;
default: fmode |= O_RDONLY;
default: fmode |= O_RDWR;
}
RESTART_SYSCALL(fd = open(path, fmode))
RESTART_SYSCALL(fd = open(path, fmode | O_NONBLOCK))
return TRUE;
if ((mode & GB_ST_MODE) == GB_ST_READ)
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK);
stream->direct.size = 0;
stream->pipe.can_write = mode & GB_ST_WRITE;
FD = fd;
return FALSE;
......@@ -93,6 +93,12 @@ static int stream_read(STREAM *stream, char *buffer, int len)
static int stream_write(STREAM *stream, char *buffer, int len)
{
if (!stream->pipe.can_write)
{
errno = EBADF;
return -1;
}
return write(FD, buffer, len);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment