From 8aa33e23d4e1b1675f9fbc5937e576105183c2ae Mon Sep 17 00:00:00 2001 From: Valentin David Date: Thu, 9 Aug 2018 13:40:27 +0200 Subject: Keep original flags for create in SafeHardlinks. When open(2) is used with flags O_CREAT|O_RDWR, the file descriptor must be readable. Unfortunately O_RDWR was not passed which made read fail with EBADF and mmap to signal SIGBUS. This issue happened with man-db for example. Fixes #143. --- buildstream/_fuse/fuse.py | 6 +++++- buildstream/_fuse/hardlinks.py | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/buildstream/_fuse/fuse.py b/buildstream/_fuse/fuse.py index 58febcba0..4ff6b9903 100644 --- a/buildstream/_fuse/fuse.py +++ b/buildstream/_fuse/fuse.py @@ -757,7 +757,11 @@ class FUSE(object): if self.raw_fi: return self.operations('create', path, mode, fi) else: - fi.fh = self.operations('create', path, mode) + # This line is different from upstream to fix issues + # reading file opened with O_CREAT|O_RDWR. + # See issue #143. + fi.fh = self.operations('create', path, mode, fi.flags) + # END OF MODIFICATION return 0 def ftruncate(self, path, length, fip): diff --git a/buildstream/_fuse/hardlinks.py b/buildstream/_fuse/hardlinks.py index 4da51bb22..1386f14cf 100644 --- a/buildstream/_fuse/hardlinks.py +++ b/buildstream/_fuse/hardlinks.py @@ -185,12 +185,12 @@ class SafeHardlinkOps(Operations): return os.open(full_path, flags) - def create(self, path, mode, fi=None): + def create(self, path, mode, flags): full_path = self._full_path(path) # If it already exists, ensure it's a copy first self._ensure_copy(full_path) - return os.open(full_path, os.O_WRONLY | os.O_CREAT, mode) + return os.open(full_path, flags, mode) def read(self, path, length, offset, fh): os.lseek(fh, offset, os.SEEK_SET) -- cgit v1.2.1