Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions auto/make
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,6 @@ ${NXT_DAEMON}-install: $NXT_DAEMON install-check
|| install -d \$(DESTDIR)$NXT_STATEDIR
test -d \$(DESTDIR)$NXT_LOGDIR \
|| install -d \$(DESTDIR)$NXT_LOGDIR
test -d \$(DESTDIR)$NXT_RUNSTATEDIR \
|| install -d \$(DESTDIR)$NXT_RUNSTATEDIR

manpage-install: manpage install-check
test -d \$(DESTDIR)$NXT_MANDIR/man8 \
Expand Down
1 change: 0 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ mkdir -p $NXT_BUILD_DIR/src
mkdir -p $NXT_BUILD_DIR/src/test
mkdir -p $NXT_BUILD_DIR/var/lib/unit
mkdir -p $NXT_BUILD_DIR/var/log/unit
mkdir -p $NXT_BUILD_DIR/var/run/unit


> $NXT_AUTOCONF_ERR
Expand Down
2 changes: 1 addition & 1 deletion src/nxt_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ nxt_runtime_controller_socket(nxt_task_t *task, nxt_runtime_t *rt)
if (ls->sockaddr->u.sockaddr.sa_family == AF_UNIX) {
const char *path = ls->sockaddr->u.sockaddr_un.sun_path;

nxt_fs_mkdir_parent((const u_char *) path, 0755);
nxt_fs_mkdir_parents_dirname((const u_char *) path, 0755);
}
#endif

Expand Down
25 changes: 21 additions & 4 deletions src/nxt_fs.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/*
* Copyright (C) NGINX, Inc.
* Copyright 2024, Alejandro Colomar <alx@kernel.org>
*/

#include <nxt_main.h>

#include <errno.h>


static nxt_int_t nxt_fs_mkdir(const u_char *dir, mode_t mode);

Expand Down Expand Up @@ -49,7 +52,7 @@ nxt_fs_mkdir_all(const u_char *dir, mode_t mode)


nxt_int_t
nxt_fs_mkdir_parent(const u_char *path, mode_t mode)
nxt_fs_mkdir_parents_dirname(const u_char *path, mode_t mode)
{
char *ptr, *dir;
nxt_int_t ret;
Expand All @@ -62,11 +65,25 @@ nxt_fs_mkdir_parent(const u_char *path, mode_t mode)
ret = NXT_OK;

ptr = strrchr(dir, '/');
if (nxt_fast_path(ptr != NULL)) {
*ptr = '\0';
ret = nxt_fs_mkdir((const u_char *) dir, mode);
if (ptr == dir || nxt_slow_path(ptr == NULL)) {
goto out_free;
}

*ptr = '\0';
if (strcmp(dir, (const char *) path) != 0)
{
ret = nxt_fs_mkdir_parents_dirname((const u_char *) dir, mode);
if (nxt_slow_path(ret == NXT_ERROR)) {
goto out_free;
}
}

ret = nxt_fs_mkdir((const u_char *) dir, mode);
if (ret == NXT_ERROR && errno == EEXIST) {
ret = NXT_OK;
}

out_free:
nxt_free(dir);

return ret;
Expand Down
2 changes: 1 addition & 1 deletion src/nxt_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define _NXT_FS_H_INCLUDED_


nxt_int_t nxt_fs_mkdir_parent(const u_char *path, mode_t mode);
nxt_int_t nxt_fs_mkdir_parents_dirname(const u_char *path, mode_t mode);
nxt_int_t nxt_fs_mkdir_all(const u_char *dir, mode_t mode);


Expand Down
2 changes: 1 addition & 1 deletion src/nxt_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ nxt_runtime_pid_file_create(nxt_task_t *task, nxt_file_name_t *pid_file)

file.name = pid_file;

nxt_fs_mkdir_parent(pid_file, 0755);
nxt_fs_mkdir_parents_dirname(pid_file, 0755);

n = nxt_file_open(task, &file, O_WRONLY, O_CREAT | O_TRUNC,
NXT_FILE_DEFAULT_ACCESS);
Expand Down