@alejandro-colomar reported that the build was broken on MacOS
cc -o build/unitd -pipe -fPIC -fvisibility=hidden -O -W -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -fstrict-aliasing -Wstrict-overflow=5 -Wmissing-prototypes -Werror -g \
build/src/nxt_main.o build/libnxt.a \
\
\
-L/usr/local/Cellar/pcre2/10.40/lib -lpcre2-8
Undefined symbols for architecture x86_64:
"_nxt_fs_mkdir_parent", referenced from:
_nxt_runtime_pid_file_create in libnxt.a(nxt_runtime.o)
_nxt_runtime_controller_socket in libnxt.a(nxt_controller.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [build/unitd] Error 1
This was due to commit 57fc920 ("Socket: Created control socket & pid file
directories.").
This happened because this commit introduced the usage of
nxt_fs_mkdir_parent() in core code which uses nxt_fs_mkdir(), both of
these are defined in src/nxt_fs.c. It turns out however that this file
doesn't get built on MacOS (or any system that isn't Linux or that
lacks a FreeBSD compatible nmount(2) system call) due to the following
In auto/sources we have
if [ $NXT_HAVE_ROOTFS = YES ]; then
NXT_LIB_SRCS="$NXT_LIB_SRCS src/nxt_fs.c"
fi
NXT_HAVE_ROOTFS is set in auto/isolation
If [ $NXT_HAVE_MOUNT = YES -a $NXT_HAVE_UNMOUNT = YES ]; then
NXT_HAVE_ROOTFS=YES
cat << END >> $NXT_AUTO_CONFIG_H
#ifndef NXT_HAVE_ISOLATION_ROOTFS
#define NXT_HAVE_ISOLATION_ROOTFS 1
#endif
END
fi
While we do have a check for a generic umount(2) which is found on
MacOS, for mount(2) we currently only check for the Linux mount(2) and
FreeBSD nmount(2) system calls. So NXT_HAVE_ROOTFS is set to NO on MacOS
and we don't build src/nxt_fs.c
This fixes the immediate build issue by taking the mount/umount OS
support out of nxt_fs.c into a new nxt_fs_mount.c file which is guarded
by the above while we now build nxt_fs.c unconditionally.
This should fix the build on any _supported_ system.
Reported-by: Alejandro Colomar <alx@nginx.com>
Fixes: 57fc920 ("Socket: Created control socket & pid file directories.")
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
85 lines
1.5 KiB
C
85 lines
1.5 KiB
C
/*
|
|
* Copyright (C) NGINX, Inc.
|
|
*/
|
|
|
|
#include <nxt_main.h>
|
|
|
|
|
|
static nxt_int_t nxt_fs_mkdir(const u_char *dir, mode_t mode);
|
|
|
|
|
|
nxt_int_t
|
|
nxt_fs_mkdir_all(const u_char *dir, mode_t mode)
|
|
{
|
|
char *start, *end, *dst;
|
|
size_t dirlen;
|
|
char path[PATH_MAX];
|
|
|
|
dirlen = nxt_strlen(dir);
|
|
|
|
nxt_assert(dirlen < PATH_MAX && dirlen > 1 && dir[0] == '/');
|
|
|
|
dst = path;
|
|
start = end = (char *) dir;
|
|
|
|
while (*start != '\0') {
|
|
if (*start == '/') {
|
|
*dst++ = *start++;
|
|
}
|
|
|
|
end = strchr(start, '/');
|
|
if (end == NULL) {
|
|
end = ((char *)dir + dirlen);
|
|
}
|
|
|
|
dst = nxt_cpymem(dst, start, end - start);
|
|
*dst = '\0';
|
|
|
|
if (nxt_slow_path(nxt_fs_mkdir((u_char *) path, mode) != NXT_OK
|
|
&& nxt_errno != EEXIST))
|
|
{
|
|
return NXT_ERROR;
|
|
}
|
|
|
|
start = end;
|
|
}
|
|
|
|
return NXT_OK;
|
|
}
|
|
|
|
|
|
nxt_int_t
|
|
nxt_fs_mkdir_parent(const u_char *path, mode_t mode)
|
|
{
|
|
char *ptr, *dir;
|
|
nxt_int_t ret;
|
|
|
|
dir = nxt_strdup(path);
|
|
if (nxt_slow_path(dir == NULL)) {
|
|
return NXT_ERROR;
|
|
}
|
|
|
|
ret = NXT_OK;
|
|
|
|
ptr = strrchr(dir, '/');
|
|
if (nxt_fast_path(ptr != NULL)) {
|
|
*ptr = '\0';
|
|
ret = nxt_fs_mkdir((const u_char *) dir, mode);
|
|
}
|
|
|
|
nxt_free(dir);
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
static nxt_int_t
|
|
nxt_fs_mkdir(const u_char *dir, mode_t mode)
|
|
{
|
|
if (nxt_fast_path(mkdir((const char *) dir, mode) == 0)) {
|
|
return NXT_OK;
|
|
}
|
|
|
|
return NXT_ERROR;
|
|
}
|