mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-11-13 12:09:35 +03:00
Remove sz requirement and implement proper fix for failure to mmap shm objects on OS X. Apparently they have to be mapped shared.
This commit is contained in:
parent
dbd7ec5b27
commit
c01f009e42
@ -137,11 +137,11 @@ static inline bool
|
||||
mmap_img_file(GraphicsManager UNUSED *self, Image *img, size_t sz, off_t offset) {
|
||||
if (!sz) {
|
||||
struct stat s;
|
||||
if (fstat(img->load_data.fd, &s) != 0) ABRT(EBADF, "Failed to fstat() file with error: [%d] %s", errno, strerror(errno));
|
||||
if (fstat(img->load_data.fd, &s) != 0) ABRT(EBADF, "Failed to fstat() the fd: %d file with error: [%d] %s", img->load_data.fd, errno, strerror(errno));
|
||||
sz = s.st_size;
|
||||
}
|
||||
void *addr = mmap(0, sz, PROT_READ, MAP_PRIVATE, img->load_data.fd, offset);
|
||||
if (addr == MAP_FAILED) ABRT(EBADF, "Failed to map image file with error: [%d] %s", errno, strerror(errno));
|
||||
void *addr = mmap(0, sz, PROT_READ, MAP_SHARED, img->load_data.fd, offset);
|
||||
if (addr == MAP_FAILED) ABRT(EBADF, "Failed to map image file fd: %d at offset: %zd with size: %zu with error: [%d] %s", img->load_data.fd, offset, sz, errno, strerror(errno));
|
||||
img->load_data.mapped_file = addr;
|
||||
img->load_data.mapped_file_sz = sz;
|
||||
return true;
|
||||
@ -337,7 +337,6 @@ handle_add_command(GraphicsManager *self, const GraphicsCommand *g, const uint8_
|
||||
else fd = open(fname, O_CLOEXEC | O_RDONLY);
|
||||
if (fd == -1) ABRT(EBADF, "Failed to open file %s for graphics transmission with error: [%d] %s", fname, errno, strerror(errno));
|
||||
img->load_data.fd = fd;
|
||||
if (tt == 's' && !g->data_sz) ABRT(EINVAL, "data size required for shared memory object");
|
||||
img->data_loaded = mmap_img_file(self, img, g->data_sz, g->data_offset);
|
||||
if (tt == 't') unlink(fname);
|
||||
else if (tt == 's') shm_unlink(fname);
|
||||
|
@ -90,5 +90,5 @@ class TestGraphics(BaseTest):
|
||||
# Test loading from POSIX SHM
|
||||
name = '/kitty-test-shm'
|
||||
g.shm_write(name, random_data)
|
||||
sl(name, s=24, v=32, t='s', S=len(random_data), expecting_data=random_data)
|
||||
sl(name, s=24, v=32, t='s', expecting_data=random_data)
|
||||
self.assertRaises(FileNotFoundError, g.shm_unlink, name) # check that file was deleted
|
||||
|
Loading…
Reference in New Issue
Block a user