Skip to content

Commit 2c7265d

Browse files
committed
limit the number of bytes used for the semaphore name depending on platform (31 bytes for MacOS, 252 for Linux)
1 parent aa6746f commit 2c7265d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,14 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
184184
/* the semaphore is shared by keeping it in the shared memory segment */
185185

186186
#if defined(HAVE_SEM_OPEN)
187-
sm_data->sem_name = (char*) malloc( sizeof(char) * (strlen(filename_basename)+32) );
188-
sprintf(sm_data->sem_name,"OMPIO_sharedfp_sem_%s",filename_basename);
187+
188+
#if defined (__APPLE__)
189+
sm_data->sem_name = (char*) malloc( sizeof(char) * 32);
190+
snprintf(sm_data->sem_name,31,"OMPIO_%s",filename_basename);
191+
#else
192+
sm_data->sem_name = (char*) malloc( sizeof(char) * 253);
193+
snprintf(sm_data->sem_name,252,"OMPIO_%s",filename_basename);
194+
#endif
189195

190196
if( (sm_data->mutex = sem_open(sm_data->sem_name, O_CREAT, 0644, 1)) != SEM_FAILED ) {
191197
#elif defined(HAVE_SEM_INIT)

0 commit comments

Comments
 (0)