summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2004-07-02 15:48:37 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2004-07-02 15:48:37 +0000
commit66924073e22b52adf59a2d6050959e6c82f0702f (patch)
treeec124a131dbce419edd74c644d2a6747246c4dc7 /sbin
parent17d799d89f51c3bf557c7965aaba186b52772c10 (diff)
Take TMPDIR into account when creating a temp mountpoint for populating.
ok avsm@ millert@; man page ok jmc@
Diffstat (limited to 'sbin')
-rw-r--r--sbin/newfs/newfs.810
-rw-r--r--sbin/newfs/newfs.c33
-rw-r--r--sbin/newfs/pathnames.h3
3 files changed, 35 insertions, 11 deletions
diff --git a/sbin/newfs/newfs.8 b/sbin/newfs/newfs.8
index 0f39fae0c5b..963c8162312 100644
--- a/sbin/newfs/newfs.8
+++ b/sbin/newfs/newfs.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: newfs.8,v 1.37 2004/06/26 18:21:36 otto Exp $
+.\" $OpenBSD: newfs.8,v 1.38 2004/07/02 15:48:35 otto Exp $
.\" $NetBSD: newfs.8,v 1.12 1995/03/18 14:58:41 cgd Exp $
.\"
.\" Copyright (c) 1983, 1987, 1991, 1993, 1994
@@ -316,6 +316,14 @@ If the
.Fl P Ar file
option is not used, the owner and mode of the created mfs file system will
be the same as the owner and mode of the mount point.
+.Sh ENVIRONMENT
+.Bl -tag -width TMPDIR
+.It Ev TMPDIR
+Directory in which to create temporary mount points for use by
+.Nm mount_mfs Fl P
+instead of
+.Pa /tmp .
+.El
.Sh SEE ALSO
.Xr disktab 5 ,
.Xr fs 5 ,
diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c
index 2994674bc24..1209d60e8e3 100644
--- a/sbin/newfs/newfs.c
+++ b/sbin/newfs/newfs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: newfs.c,v 1.48 2004/06/26 18:21:36 otto Exp $ */
+/* $OpenBSD: newfs.c,v 1.49 2004/07/02 15:48:36 otto Exp $ */
/* $NetBSD: newfs.c,v 1.20 1996/05/16 07:13:03 thorpej Exp $ */
/*
@@ -40,7 +40,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)newfs.c 8.8 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$OpenBSD: newfs.c,v 1.48 2004/06/26 18:21:36 otto Exp $";
+static char rcsid[] = "$OpenBSD: newfs.c,v 1.49 2004/07/02 15:48:36 otto Exp $";
#endif
#endif /* not lint */
@@ -959,19 +959,34 @@ copy(char *src, char *dst)
static int
gettmpmnt(char *mountpoint, size_t len)
{
+ const char *tmp;
+ const char *mnt = _PATH_MNT;
struct statfs fs;
+ size_t n;
- if (statfs("/tmp", &fs) != 0)
- err(1, "statfs /tmp");
+ tmp = getenv("TMPDIR");
+ if (tmp == NULL || *tmp == '\0')
+ tmp = _PATH_TMP;
+
+ if (statfs(tmp, &fs) != 0)
+ err(1, "statfs %s", tmp);
if (fs.f_flags & MNT_RDONLY) {
- if (statfs("/mnt", &fs) != 0)
- err(1, "statfs /mnt");
+ if (statfs(mnt, &fs) != 0)
+ err(1, "statfs %s", mnt);
if (strcmp(fs.f_mntonname, "/") != 0)
- errx(1, "temp mountpoint /mnt busy");
- strlcpy(mountpoint, "/mnt", len);
+ errx(1, "tmp mountpoint %s busy", mnt);
+ if (strlcpy(mountpoint, mnt, len) >= len)
+ errx(1, "tmp mountpoint %s too long", mnt);
return (0);
}
- strlcpy(mountpoint, "/tmp/mntXXXXXXXXXXX", len);
+ n = strlcpy(mountpoint, tmp, len);
+ if (n >= len)
+ errx(1, "tmp mount point too long");
+ if (mountpoint[n - 1] != '/')
+ strlcat(mountpoint, "/", len);
+ n = strlcat(mountpoint, "mntXXXXXXXXXX", len);
+ if (n >= len)
+ errx(1, "tmp mount point too long");
if (mkdtemp(mountpoint) == NULL)
err(1, "mkdtemp %s", mountpoint);
return (1);
diff --git a/sbin/newfs/pathnames.h b/sbin/newfs/pathnames.h
index 86ca8484504..27f99496800 100644
--- a/sbin/newfs/pathnames.h
+++ b/sbin/newfs/pathnames.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pathnames.h,v 1.1 1996/12/04 08:38:59 deraadt Exp $ */
+/* $OpenBSD: pathnames.h,v 1.2 2004/07/02 15:48:36 otto Exp $ */
/* $NetBSD: pathnames.h,v 1.1 1996/09/11 20:27:15 christos Exp $ */
/*
@@ -32,3 +32,4 @@
#define _PATH_SBIN "/sbin"
#define _PATH_USRSBIN "/usr/sbin"
+#define _PATH_MNT "/mnt"