Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin Refactor remaining mount_* commands to use the common p...



details:   https://anonhg.NetBSD.org/src/rev/f8f68582f7ba
branches:  trunk
changeset: 936359:f8f68582f7ba
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sun Jul 26 08:20:22 2020 +0000

description:
Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.

diffstat:

 sbin/mount/pathadj.c                 |  11 +++++++----
 sbin/mount_ados/Makefile             |   4 ++--
 sbin/mount_ados/mount_ados.c         |  22 ++++++----------------
 sbin/mount_autofs/Makefile           |   8 ++++++--
 sbin/mount_autofs/mount_autofs.c     |  12 ++++--------
 sbin/mount_fdesc/Makefile            |   8 ++++++--
 sbin/mount_fdesc/mount_fdesc.c       |  12 ++++--------
 sbin/mount_filecore/Makefile         |   4 ++--
 sbin/mount_filecore/mount_filecore.c |  23 +++++------------------
 sbin/mount_kernfs/Makefile           |   8 ++++++--
 sbin/mount_kernfs/mount_kernfs.c     |  12 ++++--------
 sbin/mount_null/Makefile             |   8 +++++---
 sbin/mount_null/mount_null.c         |  21 ++++++---------------
 sbin/mount_overlay/Makefile          |   8 +++++---
 sbin/mount_overlay/mount_overlay.c   |  21 ++++++---------------
 sbin/mount_procfs/Makefile           |   8 ++++++--
 sbin/mount_procfs/mount_procfs.c     |  13 +++++--------
 sbin/mount_ptyfs/Makefile            |   8 ++++++--
 sbin/mount_ptyfs/mount_ptyfs.c       |  13 +++++--------
 sbin/mount_umap/Makefile             |   8 +++++---
 sbin/mount_umap/mount_umap.c         |  21 ++++++---------------
 sbin/mount_union/Makefile            |   8 +++++---
 sbin/mount_union/mount_union.c       |  21 ++++++---------------
 23 files changed, 118 insertions(+), 164 deletions(-)

diffs (truncated from 736 to 300 lines):

diff -r 3cfac90002c4 -r f8f68582f7ba sbin/mount/pathadj.c
--- a/sbin/mount/pathadj.c      Sun Jul 26 08:08:41 2020 +0000
+++ b/sbin/mount/pathadj.c      Sun Jul 26 08:20:22 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pathadj.c,v 1.2 2011/02/17 16:57:46 pooka Exp $        */
+/*     $NetBSD: pathadj.c,v 1.3 2020/07/26 08:20:22 mlelstv Exp $      */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation.  All Rights Reserved.
@@ -37,10 +37,13 @@
 pathadj(const char *input, char *adjusted)
 {
 
-       if (realpath(input, adjusted) == NULL)
+       if (realpath(input, adjusted) == NULL) {
                warn("Warning: realpath %s", input);
-       if (strncmp(input, adjusted, MAXPATHLEN)) {
-               warnx("\"%s\" is a non-resolved or relative path.", input);
+               return;
+       }
+
+       if (input[0] != '/') {
+               warnx("\"%s\" is a relative path.", input);
                warnx("using \"%s\" instead.", adjusted);
        }
 }
diff -r 3cfac90002c4 -r f8f68582f7ba sbin/mount_ados/Makefile
--- a/sbin/mount_ados/Makefile  Sun Jul 26 08:08:41 2020 +0000
+++ b/sbin/mount_ados/Makefile  Sun Jul 26 08:20:22 2020 +0000
@@ -1,9 +1,9 @@
-#      $NetBSD: Makefile,v 1.13 2005/06/27 01:00:05 christos Exp $
+#      $NetBSD: Makefile,v 1.14 2020/07/26 08:20:22 mlelstv Exp $
 
 .include <bsd.own.mk>
 
 PROG=  mount_ados
-SRCS=  mount_ados.c fattr.c
+SRCS=  mount_ados.c fattr.c pathadj.c
 MAN=   mount_ados.8
 
 MOUNT= ${NETBSDSRCDIR}/sbin/mount
diff -r 3cfac90002c4 -r f8f68582f7ba sbin/mount_ados/mount_ados.c
--- a/sbin/mount_ados/mount_ados.c      Sun Jul 26 08:08:41 2020 +0000
+++ b/sbin/mount_ados/mount_ados.c      Sun Jul 26 08:20:22 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mount_ados.c,v 1.29 2011/08/29 14:35:00 joerg Exp $ */
+/* $NetBSD: mount_ados.c,v 1.30 2020/07/26 08:20:22 mlelstv Exp $ */
 
 /*
  * Copyright (c) 1994 Christopher G. Demetriou
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: mount_ados.c,v 1.29 2011/08/29 14:35:00 joerg Exp $");
+__RCSID("$NetBSD: mount_ados.c,v 1.30 2020/07/26 08:20:22 mlelstv Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -120,21 +120,11 @@
        dev = argv[optind];
        dir = argv[optind + 1];
 
-       if (realpath(dev, canon_dev) == NULL)        /* Check device path */
-               err(1, "realpath %s", dev);
-       if (strncmp(dev, canon_dev, MAXPATHLEN)) {
-               warnx("\"%s\" is a relative path.", dev);
-               dev = canon_dev;
-               warnx("using \"%s\" instead.", dev);
-       }
+       pathadj(dev, canon_dev);
+       dev = canon_dev;
 
-       if (realpath(dir, canon_dir) == NULL)        /* Check mounton path */
-               err(1, "realpath %s", dir);
-       if (strncmp(dir, canon_dir, MAXPATHLEN)) {
-               warnx("\"%s\" is a relative path.", dir);
-               dir = canon_dir;
-               warnx("using \"%s\" instead.", dir);
-       }
+       pathadj(dir, canon_dir);
+       dir = canon_dir;
 
        args.fspec = dev;
        if (!set_gid || !set_uid || !set_mask) {
diff -r 3cfac90002c4 -r f8f68582f7ba sbin/mount_autofs/Makefile
--- a/sbin/mount_autofs/Makefile        Sun Jul 26 08:08:41 2020 +0000
+++ b/sbin/mount_autofs/Makefile        Sun Jul 26 08:20:22 2020 +0000
@@ -1,12 +1,16 @@
-#      $NetBSD: Makefile,v 1.2 2018/01/22 09:45:32 kamil Exp $
+#      $NetBSD: Makefile,v 1.3 2020/07/26 08:20:22 mlelstv Exp $
 #      @(#)Makefile    8.2 (Berkeley) 3/27/94
 
 .include <bsd.own.mk>
 
 PROG=  mount_autofs
-SRCS=  mount_autofs.c
+SRCS=  mount_autofs.c pathadj.c
 MAN=   mount_autofs.8
 
+MOUNT=  ${NETBSDSRCDIR}/sbin/mount
+CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${MOUNT}
+.PATH:  ${MOUNT}
+
 DPADD+=${LIBUTIL}
 LDADD+=-lutil
 
diff -r 3cfac90002c4 -r f8f68582f7ba sbin/mount_autofs/mount_autofs.c
--- a/sbin/mount_autofs/mount_autofs.c  Sun Jul 26 08:08:41 2020 +0000
+++ b/sbin/mount_autofs/mount_autofs.c  Sun Jul 26 08:20:22 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mount_autofs.c,v 1.4 2019/11/20 17:18:35 tkusumi Exp $ */
+/*     $NetBSD: mount_autofs.c,v 1.5 2020/07/26 08:20:22 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: mount_autofs.c,v 1.4 2019/11/20 17:18:35 tkusumi Exp $");
+__RCSID("$NetBSD: mount_autofs.c,v 1.5 2020/07/26 08:20:22 mlelstv Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -46,6 +46,7 @@
 
 #include <fs/autofs/autofs_mount.h>
 
+#include "mountprog.h"
 #include "mount_autofs.h"
 
 static const struct mntopt mopts[] = {
@@ -102,12 +103,7 @@
                usage();
 
        strlcpy(canon_dev, argv[0], MAXPATHLEN);
-       if (realpath(argv[1], canon_dir) == NULL)    /* Check mounton path */
-               err(EXIT_FAILURE, "realpath %s", canon_dir);
-       if (strncmp(argv[1], canon_dir, MAXPATHLEN)) {
-               warnx("\"%s\" is a relative path.", argv[1]);
-               warnx("using \"%s\" instead.", canon_dir);
-       }
+       pathadj(argv[1], canon_dir);
 }
 
 int
diff -r 3cfac90002c4 -r f8f68582f7ba sbin/mount_fdesc/Makefile
--- a/sbin/mount_fdesc/Makefile Sun Jul 26 08:08:41 2020 +0000
+++ b/sbin/mount_fdesc/Makefile Sun Jul 26 08:20:22 2020 +0000
@@ -1,12 +1,16 @@
-#      $NetBSD: Makefile,v 1.13 2005/06/27 01:00:05 christos Exp $
+#      $NetBSD: Makefile,v 1.14 2020/07/26 08:20:22 mlelstv Exp $
 #      @(#)Makefile    8.2 (Berkeley) 3/27/94
 
 .include <bsd.own.mk>
 
 PROG=  mount_fdesc
-SRCS=  mount_fdesc.c
+SRCS=  mount_fdesc.c pathadj.c
 MAN=   mount_fdesc.8
 
+MOUNT=  ${NETBSDSRCDIR}/sbin/mount
+CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${MOUNT}
+.PATH:  ${MOUNT}
+
 DPADD+=${LIBUTIL}
 LDADD+=-lutil
 
diff -r 3cfac90002c4 -r f8f68582f7ba sbin/mount_fdesc/mount_fdesc.c
--- a/sbin/mount_fdesc/mount_fdesc.c    Sun Jul 26 08:08:41 2020 +0000
+++ b/sbin/mount_fdesc/mount_fdesc.c    Sun Jul 26 08:20:22 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mount_fdesc.c,v 1.26 2011/08/29 14:35:00 joerg Exp $   */
+/*     $NetBSD: mount_fdesc.c,v 1.27 2020/07/26 08:20:22 mlelstv Exp $ */
 
 /*
  * Copyright (c) 1992, 1993, 1994
@@ -77,7 +77,7 @@
 #if 0
 static char sccsid[] = "@(#)mount_fdesc.c      8.3 (Berkeley) 4/26/95";
 #else
-__RCSID("$NetBSD: mount_fdesc.c,v 1.26 2011/08/29 14:35:00 joerg Exp $");
+__RCSID("$NetBSD: mount_fdesc.c,v 1.27 2020/07/26 08:20:22 mlelstv Exp $");
 #endif
 #endif /* not lint */
 
@@ -92,6 +92,7 @@
 
 #include <mntopts.h>
 
+#include "mountprog.h"
 #include "mount_fdesc.h"
 
 static const struct mntopt mopts[] = {
@@ -142,12 +143,7 @@
                exit(0);
 
        strlcpy(canon_dev, argv[0], MAXPATHLEN);
-       if (realpath(argv[1], canon_dir) == NULL)    /* Check mounton path */
-               err(1, "realpath %s", argv[1]);
-       if (strncmp(argv[1], canon_dir, MAXPATHLEN)) {
-               warnx("\"%s\" is a relative path.", argv[1]);
-               warnx("using \"%s\" instead.", canon_dir);
-       }
+       pathadj(argv[1], canon_dir);
 }
 
 int
diff -r 3cfac90002c4 -r f8f68582f7ba sbin/mount_filecore/Makefile
--- a/sbin/mount_filecore/Makefile      Sun Jul 26 08:08:41 2020 +0000
+++ b/sbin/mount_filecore/Makefile      Sun Jul 26 08:20:22 2020 +0000
@@ -1,11 +1,11 @@
-#      $NetBSD: Makefile,v 1.8 2005/06/27 01:00:05 christos Exp $
+#      $NetBSD: Makefile,v 1.9 2020/07/26 08:20:22 mlelstv Exp $
 #
 #      Makefile        1.0     1998/6/26
 
 .include <bsd.own.mk>
 
 PROG=  mount_filecore
-SRCS=  mount_filecore.c fattr.c
+SRCS=  mount_filecore.c fattr.c pathadj.c
 MAN=   mount_filecore.8
 
 MOUNT= ${NETBSDSRCDIR}/sbin/mount
diff -r 3cfac90002c4 -r f8f68582f7ba sbin/mount_filecore/mount_filecore.c
--- a/sbin/mount_filecore/mount_filecore.c      Sun Jul 26 08:08:41 2020 +0000
+++ b/sbin/mount_filecore/mount_filecore.c      Sun Jul 26 08:20:22 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mount_filecore.c,v 1.20 2011/08/29 14:35:01 joerg Exp $ */
+/* $NetBSD: mount_filecore.c,v 1.21 2020/07/26 08:20:22 mlelstv Exp $ */
 
 /*
  * Copyright (c) 1992, 1993, 1994 The Regents of the University of California.
@@ -165,24 +165,11 @@
        if (argc != 2)
                usage();
 
-       dev = argv[0];
-       dir = argv[1];
+       pathadj(argv[0], canon_dev);
+       dev = canon_dev;
 
-       if (realpath(dev, canon_dev) == NULL)        /* Check device path */
-               err(1, "realpath %s", dev);
-       if (strncmp(dev, canon_dev, MAXPATHLEN)) {
-               warnx("\"%s\" is a relative path.", dev);
-               dev = canon_dev;
-               warnx("using \"%s\" instead.", dev);
-       }
-
-       if (realpath(dir, canon_dir) == NULL)        /* Check mounton path */
-               err(1, "realpath %s", dir);
-       if (strncmp(dir, canon_dir, MAXPATHLEN)) {
-               warnx("\"%s\" is a relative path.", dir);
-               dir = canon_dir;
-               warnx("using \"%s\" instead.", dir);
-       }
+       pathadj(argv[0], canon_dir);
+       dir = canon_dir;
 
 #define DEFAULT_ROOTUID        -2
        /*
diff -r 3cfac90002c4 -r f8f68582f7ba sbin/mount_kernfs/Makefile
--- a/sbin/mount_kernfs/Makefile        Sun Jul 26 08:08:41 2020 +0000
+++ b/sbin/mount_kernfs/Makefile        Sun Jul 26 08:20:22 2020 +0000
@@ -1,12 +1,16 @@
-#      $NetBSD: Makefile,v 1.13 2005/06/27 01:00:06 christos Exp $
+#      $NetBSD: Makefile,v 1.14 2020/07/26 08:20:22 mlelstv Exp $
 #      @(#)Makefile    8.2 (Berkeley) 3/27/94
 
 .include <bsd.own.mk>
 
 PROG=  mount_kernfs
-SRCS=  mount_kernfs.c
+SRCS=  mount_kernfs.c pathadj.c
 MAN=   mount_kernfs.8
 
+MOUNT=  ${NETBSDSRCDIR}/sbin/mount
+CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${MOUNT}
+.PATH:  ${MOUNT}
+
 DPADD+=${LIBUTIL}
 LDADD+=-lutil
 
diff -r 3cfac90002c4 -r f8f68582f7ba sbin/mount_kernfs/mount_kernfs.c
--- a/sbin/mount_kernfs/mount_kernfs.c  Sun Jul 26 08:08:41 2020 +0000
+++ b/sbin/mount_kernfs/mount_kernfs.c  Sun Jul 26 08:20:22 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mount_kernfs.c,v 1.25 2011/08/29 14:35:01 joerg Exp $  */
+/*     $NetBSD: mount_kernfs.c,v 1.26 2020/07/26 08:20:22 mlelstv Exp $        */
 
 /*
  * Copyright (c) 1992, 1993, 1994
@@ -77,7 +77,7 @@
 #if 0
 static char sccsid[] = "@(#)mount_kernfs.c     8.3 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: mount_kernfs.c,v 1.25 2011/08/29 14:35:01 joerg Exp $");



Home | Main Index | Thread Index | Old Index