aboutsummaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authorThomas Koenig <tkoenig@gcc.gnu.org>2020-12-27 16:53:29 +0100
committerThomas Koenig <tkoenig@gcc.gnu.org>2020-12-27 16:55:50 +0100
commit2b0eabeb48d63234a3dbaad9c1f4d81305439b3e (patch)
tree9ef0accf59f45f2d41a6a773c12cd350856e5994 /libgfortran
parente4c896fd159c3533fbaefa538fc6c6189b86bf21 (diff)
Fix for broken MacOS limitation for name length of shm_open.
libgfortran/ChangeLog: * caf_shared/util.c (CUT_INT): New macro. (MEMOBJ_NAME): Set to something short if __APPLE__ is defined. (get_shmem_fd): Exit on any error but EEXIST.
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/caf_shared/util.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/libgfortran/caf_shared/util.c b/libgfortran/caf_shared/util.c
index 0b77a527f8a..683e2f36d63 100644
--- a/libgfortran/caf_shared/util.c
+++ b/libgfortran/caf_shared/util.c
@@ -10,11 +10,22 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <assert.h>
+#include <errno.h>
/* Shared Memory objects live in their own namspace (usually found under
* /dev/shm/), so the "/" is needed. It is for some reason impossible to
- * create a shared memory object without name. */
+ * create a shared memory object without name.
+ *
+ * Apple, for some reason, only allows 31 characters in memfd names, so we need
+ * to make the name a bit shorter in that case. */
+#ifndef __APPLE__
#define MEMOBJ_NAME "/gfortran_coarray_memfd"
+#define CUT_INT(x) (x)
+#else
+#define MEMOBJ_NAME "/gfccas_"
+#define CUT_INT(x) (x % 100000)
+#endif
+
size_t
alignto (size_t size, size_t align)
@@ -66,8 +77,13 @@ get_shmem_fd (void)
do
{
snprintf (buffer, sizeof (buffer), MEMOBJ_NAME "_%u_%d",
- (unsigned int)getpid (), id++);
+ (unsigned int)getpid (), CUT_INT(id++));
fd = shm_open (buffer, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
+ if (fd == -1 && errno != EEXIST)
+ {
+ perror("Failed to create the memfd");
+ exit(1);
+ }
}
while (fd == -1);
shm_unlink (buffer);