From: Thomas Koenig Date: Sun, 27 Dec 2020 15:53:29 +0000 (+0100) Subject: Fix for broken MacOS limitation for name length of shm_open. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b0eabeb48d63234a3dbaad9c1f4d81305439b3e;p=thirdparty%2Fgcc.git 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. --- diff --git a/libgfortran/caf_shared/util.c b/libgfortran/caf_shared/util.c index 0b77a527f8ad..683e2f36d63e 100644 --- a/libgfortran/caf_shared/util.c +++ b/libgfortran/caf_shared/util.c @@ -10,11 +10,22 @@ #include #include #include +#include /* 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);