diff --git a/lib/libbe/be_access.c b/lib/libbe/be_access.c --- 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 @@ /* 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 --- a/lib/libbe/libbe.3 +++ b/lib/libbe/libbe.3 @@ -351,6 +351,10 @@ 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 .