Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/mountd Add support for multiple exports files. This...



details:   https://anonhg.NetBSD.org/src/rev/dc5fc16906bf
branches:  trunk
changeset: 959506:dc5fc16906bf
user:      hannken <hannken%NetBSD.org@localhost>
date:      Tue Feb 16 10:00:27 2021 +0000

description:
Add support for multiple exports files. This will be useful for example for
ZFS, where we have an automatically generated /etc/zfs/exports file, which
should not be edited directly.

diffstat:

 usr.sbin/mountd/mountd.8 |   7 ++++---
 usr.sbin/mountd/mountd.c |  45 ++++++++++++++++++++++++---------------------
 2 files changed, 28 insertions(+), 24 deletions(-)

diffs (128 lines):

diff -r 3ba9fd2a7c96 -r dc5fc16906bf usr.sbin/mountd/mountd.8
--- a/usr.sbin/mountd/mountd.8  Tue Feb 16 09:58:35 2021 +0000
+++ b/usr.sbin/mountd/mountd.8  Tue Feb 16 10:00:27 2021 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: mountd.8,v 1.38 2016/12/24 08:26:57 abhinav Exp $
+.\"    $NetBSD: mountd.8,v 1.39 2021/02/16 10:00:27 hannken Exp $
 .\"
 .\" Copyright (c) 1989, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)mountd.8   8.4 (Berkeley) 4/28/95
 .\"
-.Dd November 2, 2011
+.Dd February 16, 2021
 .Dt MOUNTD 8
 .Os
 .Sh NAME
@@ -42,7 +42,7 @@
 .Op Fl dN
 .Op Fl P Ar policy
 .Op Fl p Ar port
-.Op Ar exportsfile
+.Op Ar exportsfile ...
 .Sh DESCRIPTION
 .Nm
 is the server for
@@ -101,6 +101,7 @@
 .Ar exportsfile
 argument specifies an alternative location
 for the exports file.
+There can many exports files.
 .El
 .Pp
 When
diff -r 3ba9fd2a7c96 -r dc5fc16906bf usr.sbin/mountd/mountd.c
--- a/usr.sbin/mountd/mountd.c  Tue Feb 16 09:58:35 2021 +0000
+++ b/usr.sbin/mountd/mountd.c  Tue Feb 16 10:00:27 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mountd.c,v 1.133 2021/02/16 09:58:35 hannken Exp $      */
+/*     $NetBSD: mountd.c,v 1.134 2021/02/16 10:00:27 hannken Exp $      */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char     sccsid[] = "@(#)mountd.c  8.15 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: mountd.c,v 1.133 2021/02/16 09:58:35 hannken Exp $");
+__RCSID("$NetBSD: mountd.c,v 1.134 2021/02/16 10:00:27 hannken Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -226,7 +226,8 @@
 static struct exportlist *exphead;
 static struct mountlist *mlhead;
 static struct grouplist *grphead;
-static const char *exname;
+static char *const exnames_default[] = { __UNCONST(_PATH_EXPORTS), NULL };
+static char *const *exnames;
 static struct uucred def_anon = {
        1,
        (uid_t) -2,
@@ -384,15 +385,15 @@
 #ifdef IPSEC
                            " [-P policy]"
 #endif
-                           " [-p port] [exportsfile]\n", getprogname());
+                           " [-p port] [exportsfile ...]\n", getprogname());
                        exit(1);
                };
        argc -= optind;
        argv += optind;
-       if (argc == 1)
-               exname = *argv;
+       if (argc > 0)
+               exnames = argv;
        else
-               exname = _PATH_EXPORTS;
+               exnames = exnames_default;
 
        s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
        if (s < 0)
@@ -408,7 +409,7 @@
 
        sem_init(&exportsem, 0, 0);
        pthread_create(&ptdummy, NULL, exportlist_thread, NULL);
-       exname = _PATH_EXPORTS;
+       exnames = exnames_default;
        have_v6 = 0;
        (void)signal(SIGHUP, signal_get_exportlist);
 #endif
@@ -1261,20 +1262,22 @@
         * Read in the exports file and build the list, calling
         * mount() as we go along to push the export rules into the kernel.
         */
-       if ((exp_file = fopen(exname, "r")) == NULL) {
-               /*
-                * Don't exit here; we can still reload the config
-                * after a SIGHUP.
-                */
-               if (mountd_debug)
-                       (void)fprintf(stderr, "Can't open %s: %s\n", exname,
-                           strerror(errno));
-               return;
+       for (i = 0; exnames[i] != NULL; i++) {
+               if ((exp_file = fopen(exnames[i], "r")) == NULL) {
+                       /*
+                        * Don't exit here; we can still reload the config
+                        * after a SIGHUP.
+                        */
+                       if (mountd_debug)
+                               (void)fprintf(stderr, "Can't open %s: %s\n",
+                                   exnames[i], strerror(errno));
+                       continue;
+               }
+
+               get_exportlist_one(exp_file);
+
+               (void)fclose(exp_file);
        }
-
-       get_exportlist_one(exp_file);
-
-       (void)fclose(exp_file);
 }
 
 /*



Home | Main Index | Thread Index | Old Index