This source file includes following definitions.
- shmem_posix_shm_open
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #include "opal_config.h"
27
28 #include <errno.h>
29 #ifdef HAVE_FCNTL_H
30 #include <fcntl.h>
31 #endif
32 #include <string.h>
33 #if OPAL_HAVE_SOLARIS && !defined(_POSIX_C_SOURCE)
34 #define _POSIX_C_SOURCE 200112L
35 #include <sys/mman.h>
36 #undef _POSIX_C_SOURCE
37 #else
38 #ifdef HAVE_SYS_MMAN_H
39 #include <sys/mman.h>
40 #endif
41 #endif
42 #ifdef HAVE_UNISTD_H
43 #include <unistd.h>
44 #endif
45 #ifdef HAVE_SYS_TYPES_H
46 #include <sys/types.h>
47 #endif
48 #ifdef HAVE_NETDB_H
49 #include <netdb.h>
50 #endif
51
52 #include "opal/util/output.h"
53 #include "opal/util/show_help.h"
54 #include "opal/mca/shmem/base/base.h"
55 #include "opal/mca/shmem/shmem.h"
56
57 #include "shmem_posix.h"
58 #include "shmem_posix_common_utils.h"
59
60
61 int
62 shmem_posix_shm_open(char *posix_file_name_buff, size_t size)
63 {
64 int attempt = 0, fd = -1;
65
66
67
68
69
70 do {
71
72
73
74
75 snprintf(posix_file_name_buff, size, "%s%04d",
76 OPAL_SHMEM_POSIX_FILE_NAME_PREFIX, attempt++);
77
78
79
80 if (-1 == (fd = shm_open(posix_file_name_buff,
81 O_CREAT | O_EXCL | O_RDWR, 0600))) {
82 int err = errno;
83
84 if (EEXIST == err) {
85 continue;
86 }
87
88
89
90 else {
91 char hn[OPAL_MAXHOSTNAMELEN];
92 gethostname(hn, sizeof(hn));
93 opal_output_verbose(10, opal_shmem_base_framework.framework_output,
94 "shmem_posix_shm_open: disqualifying posix because "
95 "shm_open(2) failed with error: %s (errno %d)\n",
96 strerror(err), err);
97 break;
98 }
99 }
100
101 else {
102 break;
103 }
104 } while (attempt < OPAL_SHMEM_POSIX_MAX_ATTEMPTS);
105
106
107 if (attempt >= OPAL_SHMEM_POSIX_MAX_ATTEMPTS) {
108 opal_output(0, "shmem: posix: file name search - max attempts exceeded."
109 "cannot continue with posix.\n");
110 }
111 return fd;
112 }
113