summaryrefslogtreecommitdiff
path: root/extmod/vfs_posix_file.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-03-18 17:43:00 +1100
committerDamien George <damien.p.george@gmail.com>2020-03-18 21:01:07 +1100
commit68b1bc2042f8e5dcdfbe12c5b0dace0b174f6911 (patch)
tree35e0d18abe1a279c990294c21f591f81ee06bd07 /extmod/vfs_posix_file.c
parentad9a0ec8abc9d04b93b949831b7152f55ca0d7ac (diff)
extmod/vfs_posix_file: Lock GIL when writing and allow stdio flush.
Also support MP_STREAM_GET_FILENO ioctl. The stdio flush change was done previously for the unix port in 3e0b46b9af8b7a6934b7ac68671ef8f55be2b848. These changes make this POSIX file implementation equivalent to the unix file implementation.
Diffstat (limited to 'extmod/vfs_posix_file.c')
-rw-r--r--extmod/vfs_posix_file.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/extmod/vfs_posix_file.c b/extmod/vfs_posix_file.c
index b49251f03..8ac6f975d 100644
--- a/extmod/vfs_posix_file.c
+++ b/extmod/vfs_posix_file.c
@@ -157,7 +157,9 @@ STATIC mp_uint_t vfs_posix_file_write(mp_obj_t o_in, const void *buf, mp_uint_t
return size;
}
#endif
+ MP_THREAD_GIL_EXIT();
mp_int_t r = write(o->fd, buf, size);
+ MP_THREAD_GIL_ENTER();
while (r == -1 && errno == EINTR) {
if (MP_STATE_VM(mp_pending_exception) != MP_OBJ_NULL) {
mp_obj_t obj = MP_STATE_VM(mp_pending_exception);
@@ -184,6 +186,13 @@ STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_
int ret = fsync(o->fd);
MP_THREAD_GIL_ENTER();
if (ret == -1) {
+ if (errno == EINVAL
+ && (o->fd == STDIN_FILENO || o->fd == STDOUT_FILENO || o->fd == STDERR_FILENO)) {
+ // fsync(stdin/stdout/stderr) may fail with EINVAL, but don't propagate that
+ // error out. Because data is not buffered by us, and stdin/out/err.flush()
+ // should just be a no-op.
+ return 0;
+ }
*errcode = errno;
return MP_STREAM_ERROR;
}
@@ -208,6 +217,8 @@ STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_
o->fd = -1;
#endif
return 0;
+ case MP_STREAM_GET_FILENO:
+ return o->fd;
default:
*errcode = EINVAL;
return MP_STREAM_ERROR;