broadway: Handle shm_open failing by falling back on tmp files
This is required if /dev/shm is not mounted on your system, which can happen for instance in certain container configurations.
This commit is contained in:
@ -825,19 +825,31 @@ map_named_shm (char *name, gsize size)
|
||||
|
||||
int fd;
|
||||
void *ptr;
|
||||
char *filename = NULL;
|
||||
|
||||
fd = shm_open(name, O_RDONLY, 0600);
|
||||
if (fd == -1)
|
||||
{
|
||||
perror ("Failed to shm_open");
|
||||
return NULL;
|
||||
filename = g_build_filename (g_get_tmp_dir (), name, NULL);
|
||||
fd = open (filename, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
perror ("Failed to map shm");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ptr = mmap(0, size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
|
||||
(void) close(fd);
|
||||
|
||||
shm_unlink (name);
|
||||
if (filename)
|
||||
{
|
||||
unlink (filename);
|
||||
g_free (filename);
|
||||
}
|
||||
else
|
||||
shm_unlink (name);
|
||||
|
||||
return ptr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user