1
2# Copyright (C) Igor Sysoev
3# Copyright (C) NGINX, Inc.
4
5
6NXT_SHM_PREFIX="/"
7
8# FreeBSD, Solaris, MacOSX
9
10nxt_feature="shm_open()"
11nxt_feature_name=NXT_HAVE_SHM_OPEN
12nxt_feature_run=yes
13nxt_feature_incs=
14nxt_feature_libs=
15nxt_feature_test="#include <sys/mman.h>
16                  #include <fcntl.h>
17                  #include <unistd.h>
18                  #include <sys/stat.h>
19                  #include <sys/types.h>
20
21                  int main() {
22                      int         ret;
23                      static char name[] = \"/unit.configure\";
24
25                      shm_unlink(name);
26
27                      int fd = shm_open(name, O_CREAT | O_EXCL | O_RDWR,
28                          S_IRUSR | S_IWUSR);
29                      if (fd == -1)
30                          return 1;
31
32                      ret = (access(name, F_OK) == 0);
33                      shm_unlink(name);
34
35                      return ret;
36                  }"
37. auto/feature
38
39
40if [ $nxt_found = no ]; then
41
42    # Linux and NetBSD 7.0 shm_open() are in librt.
43
44    nxt_feature="shm_open() in librt"
45    nxt_feature_libs="-lrt"
46    . auto/feature
47
48    if [ $nxt_found = yes ]; then
49        NXT_LIBRT=$nxt_feature_libs
50    fi
51fi
52
53
54if [ $nxt_found = no ]; then
55
56    # DragonFly has no separate namespace for shm_open().
57
58    nxt_feature="shm_open() in /tmp directory"
59    nxt_feature_libs=
60    nxt_feature_test="#include <sys/mman.h>
61                      #include <fcntl.h>
62                      #include <sys/stat.h>
63                      #include <sys/types.h>
64
65                      int main() {
66                          static char name[] = \"/tmp/unit.configure\";
67
68                          shm_unlink(name);
69
70                          int fd = shm_open(name, O_CREAT | O_EXCL | O_RDWR,
71                              S_IRUSR | S_IWUSR);
72                          if (fd == -1)
73                              return 1;
74
75                          shm_unlink(name);
76                          return 0;
77                      }"
78    . auto/feature
79
80    if [ $nxt_found = yes ]; then
81        NXT_SHM_PREFIX="/tmp/"
82    fi
83fi
84
85nxt_shm_open_found=$nxt_found
86
87
88# FreeBSD 8.0
89
90nxt_feature="shm_open(SHM_ANON)"
91nxt_feature_name=NXT_HAVE_SHM_OPEN_ANON
92nxt_feature_libs=
93nxt_feature_test="#include <sys/mman.h>
94                  #include <fcntl.h>
95                  #include <sys/stat.h>
96
97                  int main() {
98                      int fd = shm_open(SHM_ANON, O_RDWR, S_IRUSR | S_IWUSR);
99                      if (fd == -1)
100                          return 1;
101
102                      return 0;
103                  }"
104. auto/feature
105
106if [ "$nxt_shm_open_found" = no ]; then
107    nxt_shm_open_found=$nxt_found
108fi
109
110
111# Linux
112
113nxt_feature="memfd_create()"
114nxt_feature_name=NXT_HAVE_MEMFD_CREATE
115nxt_feature_run=yes
116nxt_feature_incs=
117nxt_feature_libs=
118nxt_feature_test="#include <linux/memfd.h>
119                  #include <unistd.h>
120                  #include <sys/syscall.h>
121
122                  int main() {
123                      static char name[] = \"/unit.configure\";
124
125                      int fd = syscall(SYS_memfd_create, name, MFD_CLOEXEC);
126                      if (fd == -1)
127                          return 1;
128
129                      return 0;
130                  }"
131. auto/feature
132
133
134if [ "$nxt_shm_open_found$nxt_found" = nono ]; then
135    $echo
136    $echo $0: error: no shared memory implementation found.
137    $echo
138    exit 1;
139fi
140