From f0f6dc3261b37ea65d5dcf175422b94743fbdb40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Fri, 13 Jan 2017 03:22:35 +0000 Subject: [PATCH] [INTERPRETER] * BUG: Automatically restart mkfifo() and open() system calls when executing the PIPE instruction. git-svn-id: svn://localhost/gambas/trunk@8053 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbx/gbx_stream_pipe.c | 75 +++++++++++++++++++------------------- main/share/gb_common.h | 12 +++++- 2 files changed, 47 insertions(+), 40 deletions(-) diff --git a/main/gbx/gbx_stream_pipe.c b/main/gbx/gbx_stream_pipe.c index e22f31aae..12bef01ba 100644 --- a/main/gbx/gbx_stream_pipe.c +++ b/main/gbx/gbx_stream_pipe.c @@ -1,23 +1,23 @@ /*************************************************************************** - gbx_stream_pipe.c + gbx_stream_pipe.c - (c) 2000-2013 Benoît Minisini + (c) 2000-2017 Benoît Minisini - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - MA 02110-1301, USA. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. ***************************************************************************/ @@ -43,43 +43,42 @@ static int stream_open(STREAM *stream, const char *path, int mode) { - int fd; - int fmode; + int fd; + int fmode; - if (mkfifo(path, 0666) != 0) + RESTART_SYSCALL(mkfifo(path, 0666)) { if (errno != EEXIST) return TRUE; } - fmode = 0; + fmode = 0; - switch (mode & ST_MODE) - { - case ST_READ: fmode |= O_RDONLY; break; - case ST_WRITE: fmode |= O_WRONLY; break; - case ST_READ_WRITE: fmode |= O_RDWR; break; - default: fmode |= O_RDONLY; - } + switch (mode & ST_MODE) + { + case ST_READ: fmode |= O_RDONLY; break; + case ST_WRITE: fmode |= O_WRONLY; break; + case ST_READ_WRITE: fmode |= O_RDWR; break; + default: fmode |= O_RDONLY; + } - fd = open(path, fmode); - if (fd < 0) - return TRUE; + RESTART_SYSCALL(fd = open(path, fmode)) + return TRUE; - stream->direct.size = 0; + stream->direct.size = 0; - FD = fd; - return FALSE; + FD = fd; + return FALSE; } static int stream_close(STREAM *stream) { - if (close(FD) < 0) - return TRUE; + if (close(FD) < 0) + return TRUE; - FD = -1; - return FALSE; + FD = -1; + return FALSE; } @@ -99,7 +98,7 @@ static int stream_write(STREAM *stream, char *buffer, int len) static int stream_seek(STREAM *stream, int64_t pos, int whence) { - return TRUE; + return TRUE; } @@ -111,7 +110,7 @@ static int stream_tell(STREAM *stream, int64_t *pos) static int stream_flush(STREAM *stream) { - return FALSE; + return FALSE; } @@ -122,7 +121,7 @@ static int stream_flush(STREAM *stream) static int stream_handle(STREAM *stream) { - return FD; + return FD; } diff --git a/main/share/gb_common.h b/main/share/gb_common.h index f6efe6d49..0a35cd8da 100644 --- a/main/share/gb_common.h +++ b/main/share/gb_common.h @@ -2,7 +2,7 @@ gb_common.h - (c) 2000-2013 Benoît Minisini + (c) 2000-2017 Benoît Minisini This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -181,7 +181,7 @@ typedef #define BREAKPOINT() { raise(SIGTRAP); } #endif /* __i386__ */ -#define COPYRIGHT "(c) 2000-2016 Benoît Minisini\n\n" \ +#define COPYRIGHT "(c) 2000-2017 Benoît Minisini\n\n" \ "This program is free software; you can redistribute it and/or \n" \ "modify it under the terms of the GNU General Public License as \n" \ "published by the Free Software Foundation; either version 2, or \n" \ @@ -194,4 +194,12 @@ typedef #define $(_x) _x +#define RESTART_SYSCALL(_code) \ + for(;;) \ + { \ + errno = 0; \ + if ((_code) >= 0 || (errno != EINTR)) \ + break; \ + } if (errno) + #endif /* __COMMON_H */