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.
This commit is contained in:
hannken 2021-02-16 10:00:27 +00:00
parent 3067a266c7
commit b1564e28a9
2 changed files with 28 additions and 24 deletions

View File

@ -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 @@ mount requests
.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 @@ The
.Ar exportsfile
argument specifies an alternative location
for the exports file.
There can many exports files.
.El
.Pp
When

View File

@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\
#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 @@ __dead static void no_nfs(int);
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 @@ main(int argc, char **argv)
#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 @@ main(int argc, char **argv)
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 @@ get_exportlist(int n)
* 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) {
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", exname,
strerror(errno));
return;
(void)fprintf(stderr, "Can't open %s: %s\n",
exnames[i], strerror(errno));
continue;
}
get_exportlist_one(exp_file);
(void)fclose(exp_file);
}
}
/*