diff --git a/auto/make b/auto/make index 2788b9f52..515d69e98 100644 --- a/auto/make +++ b/auto/make @@ -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 \ diff --git a/configure b/configure index 2cb4d457e..42c861fb3 100755 --- a/configure +++ b/configure @@ -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 diff --git a/src/nxt_controller.c b/src/nxt_controller.c index eb814321d..f396daa97 100644 --- a/src/nxt_controller.c +++ b/src/nxt_controller.c @@ -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 diff --git a/src/nxt_fs.c b/src/nxt_fs.c index e10c5bcb2..649986f71 100644 --- a/src/nxt_fs.c +++ b/src/nxt_fs.c @@ -1,9 +1,12 @@ /* * Copyright (C) NGINX, Inc. + * Copyright 2024, Alejandro Colomar */ #include +#include + static nxt_int_t nxt_fs_mkdir(const u_char *dir, mode_t mode); @@ -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; @@ -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; diff --git a/src/nxt_fs.h b/src/nxt_fs.h index c8868d809..bc973e269 100644 --- a/src/nxt_fs.h +++ b/src/nxt_fs.h @@ -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); diff --git a/src/nxt_runtime.c b/src/nxt_runtime.c index 0e7f879e1..2c77e13c4 100644 --- a/src/nxt_runtime.c +++ b/src/nxt_runtime.c @@ -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);