Fixed the build on MacOS (and others).
@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>
This commit is contained in:
@@ -104,6 +104,7 @@ NXT_LIB_SRCS=" \
|
|||||||
src/nxt_websocket_accept.c \
|
src/nxt_websocket_accept.c \
|
||||||
src/nxt_http_websocket.c \
|
src/nxt_http_websocket.c \
|
||||||
src/nxt_h1proto_websocket.c \
|
src/nxt_h1proto_websocket.c \
|
||||||
|
src/nxt_fs.c \
|
||||||
"
|
"
|
||||||
|
|
||||||
NXT_LIB_SRC0=" \
|
NXT_LIB_SRC0=" \
|
||||||
@@ -187,7 +188,7 @@ NXT_LIB_UTF8_FILE_NAME_TEST_SRCS=" \
|
|||||||
|
|
||||||
|
|
||||||
if [ $NXT_HAVE_ROOTFS = YES ]; then
|
if [ $NXT_HAVE_ROOTFS = YES ]; then
|
||||||
NXT_LIB_SRCS="$NXT_LIB_SRCS src/nxt_fs.c"
|
NXT_LIB_SRCS="$NXT_LIB_SRCS src/nxt_fs_mount.c"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
225
src/nxt_fs.c
225
src/nxt_fs.c
@@ -4,235 +4,10 @@
|
|||||||
|
|
||||||
#include <nxt_main.h>
|
#include <nxt_main.h>
|
||||||
|
|
||||||
#if (NXT_HAVE_FREEBSD_NMOUNT)
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/uio.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static nxt_int_t nxt_fs_mkdir(const u_char *dir, mode_t mode);
|
static nxt_int_t nxt_fs_mkdir(const u_char *dir, mode_t mode);
|
||||||
|
|
||||||
|
|
||||||
#if (NXT_HAVE_LINUX_MOUNT)
|
|
||||||
|
|
||||||
nxt_int_t
|
|
||||||
nxt_fs_mount(nxt_task_t *task, nxt_fs_mount_t *mnt)
|
|
||||||
{
|
|
||||||
int rc;
|
|
||||||
const char *fsname;
|
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
flags = 0;
|
|
||||||
|
|
||||||
switch (mnt->type) {
|
|
||||||
case NXT_FS_BIND:
|
|
||||||
if (nxt_slow_path(mnt->flags != 0)) {
|
|
||||||
nxt_log(task, NXT_LOG_WARN,
|
|
||||||
"bind mount ignores additional flags");
|
|
||||||
}
|
|
||||||
|
|
||||||
fsname = "bind";
|
|
||||||
flags = MS_BIND | MS_REC;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NXT_FS_PROC:
|
|
||||||
fsname = "proc";
|
|
||||||
goto getflags;
|
|
||||||
|
|
||||||
case NXT_FS_TMP:
|
|
||||||
fsname = "tmpfs";
|
|
||||||
goto getflags;
|
|
||||||
|
|
||||||
default:
|
|
||||||
fsname = (const char *) mnt->name;
|
|
||||||
|
|
||||||
getflags:
|
|
||||||
|
|
||||||
if (mnt->flags & NXT_FS_FLAGS_NODEV) {
|
|
||||||
flags |= MS_NODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mnt->flags & NXT_FS_FLAGS_NOEXEC) {
|
|
||||||
flags |= MS_NOEXEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mnt->flags & NXT_FS_FLAGS_NOSUID) {
|
|
||||||
flags |= MS_NOSUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(mnt->flags & NXT_FS_FLAGS_NOTIME)) {
|
|
||||||
flags |= MS_RELATIME;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = mount((const char *) mnt->src, (const char *) mnt->dst, fsname, flags,
|
|
||||||
mnt->data);
|
|
||||||
|
|
||||||
if (nxt_slow_path(rc < 0)) {
|
|
||||||
nxt_alert(task, "mount(\"%s\", \"%s\", \"%s\", %ul, \"%s\") %E",
|
|
||||||
mnt->src, mnt->dst, fsname, flags, mnt->data, nxt_errno);
|
|
||||||
|
|
||||||
return NXT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NXT_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif (NXT_HAVE_FREEBSD_NMOUNT)
|
|
||||||
|
|
||||||
nxt_int_t
|
|
||||||
nxt_fs_mount(nxt_task_t *task, nxt_fs_mount_t *mnt)
|
|
||||||
{
|
|
||||||
int flags;
|
|
||||||
u_char *data, *p, *end;
|
|
||||||
size_t iovlen;
|
|
||||||
nxt_int_t ret;
|
|
||||||
const char *fsname;
|
|
||||||
struct iovec iov[128];
|
|
||||||
char errmsg[256];
|
|
||||||
|
|
||||||
if (nxt_slow_path((mnt->flags & NXT_FS_FLAGS_NODEV) && !mnt->builtin)) {
|
|
||||||
nxt_alert(task, "nmount(2) doesn't support \"nodev\" option");
|
|
||||||
|
|
||||||
return NXT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
flags = 0;
|
|
||||||
|
|
||||||
switch (mnt->type) {
|
|
||||||
case NXT_FS_BIND:
|
|
||||||
fsname = "nullfs";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NXT_FS_PROC:
|
|
||||||
fsname = "procfs";
|
|
||||||
goto getflags;
|
|
||||||
|
|
||||||
case NXT_FS_TMP:
|
|
||||||
fsname = "tmpfs";
|
|
||||||
goto getflags;
|
|
||||||
|
|
||||||
default:
|
|
||||||
fsname = (const char *) mnt->name;
|
|
||||||
|
|
||||||
getflags:
|
|
||||||
|
|
||||||
if (mnt->flags & NXT_FS_FLAGS_NOEXEC) {
|
|
||||||
flags |= MNT_NOEXEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mnt->flags & NXT_FS_FLAGS_NOSUID) {
|
|
||||||
flags |= MNT_NOSUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mnt->flags & NXT_FS_FLAGS_NOTIME) {
|
|
||||||
flags |= MNT_NOATIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mnt->flags & NXT_FS_FLAGS_RDONLY) {
|
|
||||||
flags |= MNT_RDONLY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
iov[0].iov_base = (void *) "fstype";
|
|
||||||
iov[0].iov_len = 7;
|
|
||||||
iov[1].iov_base = (void *) fsname;
|
|
||||||
iov[1].iov_len = nxt_strlen(fsname) + 1;
|
|
||||||
iov[2].iov_base = (void *) "fspath";
|
|
||||||
iov[2].iov_len = 7;
|
|
||||||
iov[3].iov_base = (void *) mnt->dst;
|
|
||||||
iov[3].iov_len = nxt_strlen(mnt->dst) + 1;
|
|
||||||
iov[4].iov_base = (void *) "target";
|
|
||||||
iov[4].iov_len = 7;
|
|
||||||
iov[5].iov_base = (void *) mnt->src;
|
|
||||||
iov[5].iov_len = nxt_strlen(mnt->src) + 1;
|
|
||||||
iov[6].iov_base = (void *) "errmsg";
|
|
||||||
iov[6].iov_len = 7;
|
|
||||||
iov[7].iov_base = (void *) errmsg;
|
|
||||||
iov[7].iov_len = sizeof(errmsg);
|
|
||||||
|
|
||||||
iovlen = 8;
|
|
||||||
|
|
||||||
data = NULL;
|
|
||||||
|
|
||||||
if (mnt->data != NULL) {
|
|
||||||
data = (u_char *) nxt_strdup(mnt->data);
|
|
||||||
if (nxt_slow_path(data == NULL)) {
|
|
||||||
return NXT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
end = data - 1;
|
|
||||||
|
|
||||||
do {
|
|
||||||
p = end + 1;
|
|
||||||
end = nxt_strchr(p, '=');
|
|
||||||
if (end == NULL) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
*end = '\0';
|
|
||||||
|
|
||||||
iov[iovlen].iov_base = (void *) p;
|
|
||||||
iov[iovlen].iov_len = (end - p) + 1;
|
|
||||||
|
|
||||||
iovlen++;
|
|
||||||
|
|
||||||
p = end + 1;
|
|
||||||
|
|
||||||
end = nxt_strchr(p, ',');
|
|
||||||
if (end != NULL) {
|
|
||||||
*end = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
iov[iovlen].iov_base = (void *) p;
|
|
||||||
iov[iovlen].iov_len = nxt_strlen(p) + 1;
|
|
||||||
|
|
||||||
iovlen++;
|
|
||||||
|
|
||||||
} while (end != NULL && nxt_nitems(iov) > (iovlen + 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = NXT_OK;
|
|
||||||
|
|
||||||
if (nxt_slow_path(nmount(iov, iovlen, flags) < 0)) {
|
|
||||||
nxt_alert(task, "nmount(%p, %d, 0) %s", iov, iovlen, errmsg);
|
|
||||||
ret = NXT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data != NULL) {
|
|
||||||
free(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if (NXT_HAVE_LINUX_UMOUNT2)
|
|
||||||
|
|
||||||
void
|
|
||||||
nxt_fs_unmount(const u_char *path)
|
|
||||||
{
|
|
||||||
if (nxt_slow_path(umount2((const char *) path, MNT_DETACH) < 0)) {
|
|
||||||
nxt_thread_log_error(NXT_LOG_WARN, "umount2(%s, MNT_DETACH) %E",
|
|
||||||
path, nxt_errno);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif (NXT_HAVE_UNMOUNT)
|
|
||||||
|
|
||||||
void
|
|
||||||
nxt_fs_unmount(const u_char *path)
|
|
||||||
{
|
|
||||||
if (nxt_slow_path(unmount((const char *) path, MNT_FORCE) < 0)) {
|
|
||||||
nxt_thread_log_error(NXT_LOG_WARN, "unmount(%s) %E", path, nxt_errno);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
nxt_int_t
|
nxt_int_t
|
||||||
nxt_fs_mkdir_all(const u_char *dir, mode_t mode)
|
nxt_fs_mkdir_all(const u_char *dir, mode_t mode)
|
||||||
{
|
{
|
||||||
|
|||||||
32
src/nxt_fs.h
32
src/nxt_fs.h
@@ -6,40 +6,8 @@
|
|||||||
#define _NXT_FS_H_INCLUDED_
|
#define _NXT_FS_H_INCLUDED_
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
NXT_FS_UNKNOWN = 0,
|
|
||||||
NXT_FS_BIND,
|
|
||||||
NXT_FS_TMP,
|
|
||||||
NXT_FS_PROC,
|
|
||||||
NXT_FS_LAST,
|
|
||||||
} nxt_fs_type_t;
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
NXT_FS_FLAGS_NOSUID = 1 << 0,
|
|
||||||
NXT_FS_FLAGS_NOEXEC = 1 << 1,
|
|
||||||
NXT_FS_FLAGS_NOTIME = 1 << 2,
|
|
||||||
NXT_FS_FLAGS_NODEV = 1 << 3,
|
|
||||||
NXT_FS_FLAGS_RDONLY = 1 << 4,
|
|
||||||
} nxt_fs_flags_t;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
u_char *src;
|
|
||||||
u_char *dst;
|
|
||||||
nxt_fs_type_t type;
|
|
||||||
u_char *name;
|
|
||||||
nxt_fs_flags_t flags;
|
|
||||||
u_char *data;
|
|
||||||
nxt_uint_t builtin; /* 1-bit */
|
|
||||||
nxt_uint_t deps; /* 1-bit */
|
|
||||||
} nxt_fs_mount_t;
|
|
||||||
|
|
||||||
|
|
||||||
nxt_int_t nxt_fs_mkdir_parent(const u_char *path, mode_t mode);
|
nxt_int_t nxt_fs_mkdir_parent(const u_char *path, mode_t mode);
|
||||||
nxt_int_t nxt_fs_mkdir_all(const u_char *dir, mode_t mode);
|
nxt_int_t nxt_fs_mkdir_all(const u_char *dir, mode_t mode);
|
||||||
nxt_int_t nxt_fs_mount(nxt_task_t *task, nxt_fs_mount_t *mnt);
|
|
||||||
void nxt_fs_unmount(const u_char *path);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* _NXT_FS_H_INCLUDED_ */
|
#endif /* _NXT_FS_H_INCLUDED_ */
|
||||||
|
|||||||
230
src/nxt_fs_mount.c
Normal file
230
src/nxt_fs_mount.c
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) NGINX, Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <nxt_main.h>
|
||||||
|
|
||||||
|
#if (NXT_HAVE_FREEBSD_NMOUNT)
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if (NXT_HAVE_LINUX_MOUNT)
|
||||||
|
|
||||||
|
nxt_int_t
|
||||||
|
nxt_fs_mount(nxt_task_t *task, nxt_fs_mount_t *mnt)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
const char *fsname;
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
|
flags = 0;
|
||||||
|
|
||||||
|
switch (mnt->type) {
|
||||||
|
case NXT_FS_BIND:
|
||||||
|
if (nxt_slow_path(mnt->flags != 0)) {
|
||||||
|
nxt_log(task, NXT_LOG_WARN,
|
||||||
|
"bind mount ignores additional flags");
|
||||||
|
}
|
||||||
|
|
||||||
|
fsname = "bind";
|
||||||
|
flags = MS_BIND | MS_REC;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NXT_FS_PROC:
|
||||||
|
fsname = "proc";
|
||||||
|
goto getflags;
|
||||||
|
|
||||||
|
case NXT_FS_TMP:
|
||||||
|
fsname = "tmpfs";
|
||||||
|
goto getflags;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fsname = (const char *) mnt->name;
|
||||||
|
|
||||||
|
getflags:
|
||||||
|
|
||||||
|
if (mnt->flags & NXT_FS_FLAGS_NODEV) {
|
||||||
|
flags |= MS_NODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mnt->flags & NXT_FS_FLAGS_NOEXEC) {
|
||||||
|
flags |= MS_NOEXEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mnt->flags & NXT_FS_FLAGS_NOSUID) {
|
||||||
|
flags |= MS_NOSUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(mnt->flags & NXT_FS_FLAGS_NOTIME)) {
|
||||||
|
flags |= MS_RELATIME;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = mount((const char *) mnt->src, (const char *) mnt->dst, fsname, flags,
|
||||||
|
mnt->data);
|
||||||
|
|
||||||
|
if (nxt_slow_path(rc < 0)) {
|
||||||
|
nxt_alert(task, "mount(\"%s\", \"%s\", \"%s\", %ul, \"%s\") %E",
|
||||||
|
mnt->src, mnt->dst, fsname, flags, mnt->data, nxt_errno);
|
||||||
|
|
||||||
|
return NXT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NXT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif (NXT_HAVE_FREEBSD_NMOUNT)
|
||||||
|
|
||||||
|
nxt_int_t
|
||||||
|
nxt_fs_mount(nxt_task_t *task, nxt_fs_mount_t *mnt)
|
||||||
|
{
|
||||||
|
int flags;
|
||||||
|
u_char *data, *p, *end;
|
||||||
|
size_t iovlen;
|
||||||
|
nxt_int_t ret;
|
||||||
|
const char *fsname;
|
||||||
|
struct iovec iov[128];
|
||||||
|
char errmsg[256];
|
||||||
|
|
||||||
|
if (nxt_slow_path((mnt->flags & NXT_FS_FLAGS_NODEV) && !mnt->builtin)) {
|
||||||
|
nxt_alert(task, "nmount(2) doesn't support \"nodev\" option");
|
||||||
|
|
||||||
|
return NXT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
flags = 0;
|
||||||
|
|
||||||
|
switch (mnt->type) {
|
||||||
|
case NXT_FS_BIND:
|
||||||
|
fsname = "nullfs";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NXT_FS_PROC:
|
||||||
|
fsname = "procfs";
|
||||||
|
goto getflags;
|
||||||
|
|
||||||
|
case NXT_FS_TMP:
|
||||||
|
fsname = "tmpfs";
|
||||||
|
goto getflags;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fsname = (const char *) mnt->name;
|
||||||
|
|
||||||
|
getflags:
|
||||||
|
|
||||||
|
if (mnt->flags & NXT_FS_FLAGS_NOEXEC) {
|
||||||
|
flags |= MNT_NOEXEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mnt->flags & NXT_FS_FLAGS_NOSUID) {
|
||||||
|
flags |= MNT_NOSUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mnt->flags & NXT_FS_FLAGS_NOTIME) {
|
||||||
|
flags |= MNT_NOATIME;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mnt->flags & NXT_FS_FLAGS_RDONLY) {
|
||||||
|
flags |= MNT_RDONLY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iov[0].iov_base = (void *) "fstype";
|
||||||
|
iov[0].iov_len = 7;
|
||||||
|
iov[1].iov_base = (void *) fsname;
|
||||||
|
iov[1].iov_len = nxt_strlen(fsname) + 1;
|
||||||
|
iov[2].iov_base = (void *) "fspath";
|
||||||
|
iov[2].iov_len = 7;
|
||||||
|
iov[3].iov_base = (void *) mnt->dst;
|
||||||
|
iov[3].iov_len = nxt_strlen(mnt->dst) + 1;
|
||||||
|
iov[4].iov_base = (void *) "target";
|
||||||
|
iov[4].iov_len = 7;
|
||||||
|
iov[5].iov_base = (void *) mnt->src;
|
||||||
|
iov[5].iov_len = nxt_strlen(mnt->src) + 1;
|
||||||
|
iov[6].iov_base = (void *) "errmsg";
|
||||||
|
iov[6].iov_len = 7;
|
||||||
|
iov[7].iov_base = (void *) errmsg;
|
||||||
|
iov[7].iov_len = sizeof(errmsg);
|
||||||
|
|
||||||
|
iovlen = 8;
|
||||||
|
|
||||||
|
data = NULL;
|
||||||
|
|
||||||
|
if (mnt->data != NULL) {
|
||||||
|
data = (u_char *) nxt_strdup(mnt->data);
|
||||||
|
if (nxt_slow_path(data == NULL)) {
|
||||||
|
return NXT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
end = data - 1;
|
||||||
|
|
||||||
|
do {
|
||||||
|
p = end + 1;
|
||||||
|
end = nxt_strchr(p, '=');
|
||||||
|
if (end == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
*end = '\0';
|
||||||
|
|
||||||
|
iov[iovlen].iov_base = (void *) p;
|
||||||
|
iov[iovlen].iov_len = (end - p) + 1;
|
||||||
|
|
||||||
|
iovlen++;
|
||||||
|
|
||||||
|
p = end + 1;
|
||||||
|
|
||||||
|
end = nxt_strchr(p, ',');
|
||||||
|
if (end != NULL) {
|
||||||
|
*end = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
iov[iovlen].iov_base = (void *) p;
|
||||||
|
iov[iovlen].iov_len = nxt_strlen(p) + 1;
|
||||||
|
|
||||||
|
iovlen++;
|
||||||
|
|
||||||
|
} while (end != NULL && nxt_nitems(iov) > (iovlen + 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = NXT_OK;
|
||||||
|
|
||||||
|
if (nxt_slow_path(nmount(iov, iovlen, flags) < 0)) {
|
||||||
|
nxt_alert(task, "nmount(%p, %d, 0) %s", iov, iovlen, errmsg);
|
||||||
|
ret = NXT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data != NULL) {
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if (NXT_HAVE_LINUX_UMOUNT2)
|
||||||
|
|
||||||
|
void
|
||||||
|
nxt_fs_unmount(const u_char *path)
|
||||||
|
{
|
||||||
|
if (nxt_slow_path(umount2((const char *) path, MNT_DETACH) < 0)) {
|
||||||
|
nxt_thread_log_error(NXT_LOG_WARN, "umount2(%s, MNT_DETACH) %E",
|
||||||
|
path, nxt_errno);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif (NXT_HAVE_UNMOUNT)
|
||||||
|
|
||||||
|
void
|
||||||
|
nxt_fs_unmount(const u_char *path)
|
||||||
|
{
|
||||||
|
if (nxt_slow_path(unmount((const char *) path, MNT_FORCE) < 0)) {
|
||||||
|
nxt_thread_log_error(NXT_LOG_WARN, "unmount(%s) %E", path, nxt_errno);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
48
src/nxt_fs_mount.h
Normal file
48
src/nxt_fs_mount.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) NGINX, Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NXT_FS_MOUNT_H_INCLUDED_
|
||||||
|
#define _NXT_FS_MOUNT_H_INCLUDED_
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum nxt_fs_type_s nxt_fs_type_t;
|
||||||
|
typedef enum nxt_fs_flags_s nxt_fs_flags_t;
|
||||||
|
typedef struct nxt_fs_mount_s nxt_fs_mount_t;
|
||||||
|
|
||||||
|
|
||||||
|
enum nxt_fs_type_s {
|
||||||
|
NXT_FS_UNKNOWN = 0,
|
||||||
|
NXT_FS_BIND,
|
||||||
|
NXT_FS_TMP,
|
||||||
|
NXT_FS_PROC,
|
||||||
|
NXT_FS_LAST,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum nxt_fs_flags_s {
|
||||||
|
NXT_FS_FLAGS_NOSUID = 1 << 0,
|
||||||
|
NXT_FS_FLAGS_NOEXEC = 1 << 1,
|
||||||
|
NXT_FS_FLAGS_NOTIME = 1 << 2,
|
||||||
|
NXT_FS_FLAGS_NODEV = 1 << 3,
|
||||||
|
NXT_FS_FLAGS_RDONLY = 1 << 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct nxt_fs_mount_s {
|
||||||
|
u_char *src;
|
||||||
|
u_char *dst;
|
||||||
|
nxt_fs_type_t type;
|
||||||
|
u_char *name;
|
||||||
|
nxt_fs_flags_t flags;
|
||||||
|
u_char *data;
|
||||||
|
nxt_uint_t builtin; /* 1-bit */
|
||||||
|
nxt_uint_t deps; /* 1-bit */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
nxt_int_t nxt_fs_mount(nxt_task_t *task, nxt_fs_mount_t *mnt);
|
||||||
|
void nxt_fs_unmount(const u_char *path);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _NXT_FS_MOUNT_H_INCLUDED_ */
|
||||||
@@ -59,6 +59,7 @@ typedef uint16_t nxt_port_id_t;
|
|||||||
#include <nxt_process_type.h>
|
#include <nxt_process_type.h>
|
||||||
#include <nxt_capability.h>
|
#include <nxt_capability.h>
|
||||||
#include <nxt_credential.h>
|
#include <nxt_credential.h>
|
||||||
|
#include <nxt_fs_mount.h>
|
||||||
#include <nxt_fs.h>
|
#include <nxt_fs.h>
|
||||||
#include <nxt_process.h>
|
#include <nxt_process.h>
|
||||||
#include <nxt_utf8.h>
|
#include <nxt_utf8.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user