git: 8dc42b80fdfb - stable/14 - libbe: don't hardcode /tmp
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 26 Apr 2025 03:24:58 UTC
The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=8dc42b80fdfb0f39ba52560ac35b6914c72fcff5 commit 8dc42b80fdfb0f39ba52560ac35b6914c72fcff5 Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2025-04-21 03:47:59 +0000 Commit: Kyle Evans <kevans@FreeBSD.org> CommitDate: 2025-04-26 03:24:13 +0000 libbe: don't hardcode /tmp Respect $TMPDIR if it's set, fallback to _PATH_TMP (not hardcoded /tmp) if it's not. Bump .Dd after recent commits. Reviewed by: rcm (cherry picked from commit 2f11393fee4d60d38634a261edf9aa9fea39c75c) --- lib/libbe/be_access.c | 14 ++++++++++++-- lib/libbe/libbe.3 | 6 +++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/libbe/be_access.c b/lib/libbe/be_access.c index 51f5a75e957d..44e7eb1e651c 100644 --- a/lib/libbe/be_access.c +++ b/lib/libbe/be_access.c @@ -33,7 +33,7 @@ #include "be.h" #include "be_impl.h" -#define LIBBE_MOUNT_PREFIX "be_mount." /* XXX */ +#define LIBBE_MOUNT_PREFIX "be_mount." struct be_mountcheck_info { const char *path; @@ -261,7 +261,17 @@ be_mount(libbe_handle_t *lbh, const char *bootenv, const char *mountpoint, /* Create mountpoint if it is not specified */ if (mountpoint == NULL) { - strlcpy(mnt_temp, "/tmp/be_mount.XXXX", sizeof(mnt_temp)); + const char *tmpdir; + + tmpdir = getenv("TMPDIR"); + if (tmpdir == NULL) + tmpdir = _PATH_TMP; + + if (snprintf(mnt_temp, sizeof(mnt_temp), "%s%s%sXXXX", tmpdir, + tmpdir[strlen(tmpdir) - 1] == '/' ? "" : "/", + LIBBE_MOUNT_PREFIX) >= (int)sizeof(mnt_temp)) + return (set_error(lbh, BE_ERR_PATHLEN)); + if (mkdtemp(mnt_temp) == NULL) return (set_error(lbh, BE_ERR_IO)); } diff --git a/lib/libbe/libbe.3 b/lib/libbe/libbe.3 index 743922a76391..c1bf52e42324 100644 --- a/lib/libbe/libbe.3 +++ b/lib/libbe/libbe.3 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd March 18, 2024 +.Dd April 25, 2025 .Dt LIBBE 3 .Os .Sh NAME @@ -358,6 +358,10 @@ If is .Dv NULL , a mount point will be generated in +.Ev TMPDIR +or, if +.Ev TMPDIR +is not set, .Pa /tmp using .Xr mkdtemp 3 .