Eliminate the distinct path check, since the paths don't actually need to be

distinct and allowing this makes certain useful tasks possible, such as
 fixing an unpopulated /dev while a tmpfs is mounted over it.
However, require the paths to be different, as mounting a path directly over
 itself has the side effect of causing any other mount points within that path
 to no longer be accessible, and is difficult to unmount when done on /.
This commit is contained in:
erh 2016-07-25 04:40:51 +00:00
parent a3625f4d7b
commit 2b151ae574

View File

@ -1,4 +1,4 @@
/* $NetBSD: mount_null.c,v 1.19 2011/08/29 14:35:02 joerg Exp $ */
/* $NetBSD: mount_null.c,v 1.20 2016/07/25 04:40:51 erh Exp $ */
/*
* Copyright (c) 1992, 1993, 1994
@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\
#if 0
static char sccsid[] = "@(#)mount_null.c 8.6 (Berkeley) 4/26/95";
#else
__RCSID("$NetBSD: mount_null.c,v 1.19 2011/08/29 14:35:02 joerg Exp $");
__RCSID("$NetBSD: mount_null.c,v 1.20 2016/07/25 04:40:51 erh Exp $");
#endif
#endif /* not lint */
@ -65,7 +65,6 @@ static const struct mntopt mopts[] = {
};
int mount_null(int argc, char **argv);
static int subdir(const char *, const char *);
__dead static void usage(void);
#ifndef MOUNT_NOMAIN
@ -117,8 +116,8 @@ mount_null(int argc, char *argv[])
warnx("using \"%s\" instead.", canon_dir);
}
if (subdir(target, canon_dir) || subdir(canon_dir, target))
errx(1, "%s (%s) and %s (%s) are not distinct paths",
if (strcmp(target, canon_dir) == 0)
errx(1, "%s (%s) and %s (%s) are identical paths",
argv[0], target, argv[1], canon_dir);
args.la.target = target;
@ -128,21 +127,6 @@ mount_null(int argc, char *argv[])
exit(0);
}
static int
subdir(const char *p, const char *dir)
{
int l;
l = strlen(dir);
if (l <= 1)
return (1);
if ((strncmp(p, dir, l) == 0) && (p[l] == '/' || p[l] == '\0'))
return (1);
return (0);
}
static void
usage(void)
{