Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

Commit c105988

Browse files
committed
Fixed DragonFly BSD shared memory implementation.
1 parent f7bc2e1 commit c105988

File tree

6 files changed

+74
-4
lines changed

6 files changed

+74
-4
lines changed

auto/os/conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,26 @@ case "$NXT_SYSTEM" in
167167
NXT_LIBS="$NXT_PTHREAD"
168168
;;
169169

170+
DragonFly)
171+
nxt_have=NXT_DRAGONFLY . auto/have
172+
173+
NXT_STATIC_LINK="ar -r -c"
174+
NXT_SHARED_LINK="\$(CC) -shared"
175+
NXT_SHARED_LOCAL_LINK="\$(CC) -shared"
176+
NXT_MODULE_LINK="\$(CC) -shared"
177+
178+
# "-Wl,-E" exports symbols of executable file.
179+
NXT_EXEC_LINK="\$(CC) -Wl,-E"
180+
NXT_SHARED_LOCAL_EXEC_LINK=
181+
182+
NXT_LIB_STATIC="libnxt.a"
183+
NXT_LIB_SHARED="libnxt.so"
184+
NXT_LIB_SHARED_LOCAL="$NXT_BUILD_DIR/libnxt.so"
185+
186+
NXT_LIBM="-lm"
187+
NXT_LIBS="$NXT_LIBRT $NXT_PTHREAD"
188+
;;
189+
170190
AIX)
171191
nxt_have=NXT_AIX . auto/have
172192

auto/os/test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ case "$NXT_SYSTEM" in
1616
CC=${CC:-cc}
1717
;;
1818

19-
FreeBSD | NetBSD | OpenBSD)
19+
FreeBSD | NetBSD | OpenBSD | DragonFly)
2020
NXT_SYSTEM_VERSION=`uname -r 2>/dev/null`
2121
NXT_SYSTEM_PLATFORM=`uname -m 2>/dev/null`
2222
echo=echo

auto/shmem

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Copyright (C) NGINX, Inc.
44

55

6+
NXT_SHM_PREFIX="/"
7+
68
# FreeBSD, Solaris, MacOSX
79

810
nxt_feature="shm_open()"
@@ -12,10 +14,12 @@ nxt_feature_incs=
1214
nxt_feature_libs=
1315
nxt_feature_test="#include <sys/mman.h>
1416
#include <fcntl.h>
17+
#include <unistd.h>
1518
#include <sys/stat.h>
1619
#include <sys/types.h>
1720

1821
int main() {
22+
int ret;
1923
static char name[] = \"/unit.configure\";
2024

2125
shm_unlink(name);
@@ -25,8 +29,10 @@ nxt_feature_test="#include <sys/mman.h>
2529
if (fd == -1)
2630
return 1;
2731

32+
ret = (access(name, F_OK) == 0);
2833
shm_unlink(name);
29-
return 0;
34+
35+
return ret;
3036
}"
3137
. auto/feature
3238

@@ -45,6 +51,40 @@ if [ $nxt_found = no ]; then
4551
fi
4652

4753

54+
if [ $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
83+
fi
84+
85+
nxt_shm_open_found=$nxt_found
86+
87+
4888
# Linux
4989

5090
nxt_feature="memfd_create()"
@@ -67,3 +107,10 @@ nxt_feature_test="#include <linux/memfd.h>
67107
}"
68108
. auto/feature
69109

110+
111+
if [ "$nxt_shm_open_found$nxt_found" = nono ]; then
112+
$echo
113+
$echo $0: error: no shared memory implementation found.
114+
$echo
115+
exit 1;
116+
fi

configure

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ cat << END >> $NXT_AUTO_CONFIG_H
145145
#define NXT_DEBUG $nxt_debug
146146
#endif
147147
148+
#define NXT_SHM_PREFIX "$NXT_SHM_PREFIX"
149+
148150
END
149151

150152
. auto/test_build

src/go/unit/nxt_go_port_memory.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ nxt_go_new_port_mmap(nxt_go_process_t *process, nxt_port_id_t id,
4949
return NULL;
5050
}
5151

52-
name_len = snprintf(name, sizeof(name) - 1, "/unit.go.%p", name);
52+
name_len = snprintf(name, sizeof(name) - 1,
53+
NXT_SHM_PREFIX "unit.go.%p", name);
5354

5455
#if (NXT_HAVE_MEMFD_CREATE)
5556

src/nxt_port_memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ nxt_port_new_port_mmap(nxt_task_t *task, nxt_process_t *process,
280280
return NULL;
281281
}
282282

283-
p = nxt_sprintf(name, name + sizeof(name), "/unit.%PI.%uxD",
283+
p = nxt_sprintf(name, name + sizeof(name), NXT_SHM_PREFIX "unit.%PI.%uxD",
284284
nxt_pid, nxt_random(&task->thread->random));
285285
*p = '\0';
286286

0 commit comments

Comments
 (0)