From owner-svn-src-head@freebsd.org Wed Oct 4 08:48:07 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 395C3E32E84; Wed, 4 Oct 2017 08:48:07 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 136767C140; Wed, 4 Oct 2017 08:48:07 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v948m6Om029128; Wed, 4 Oct 2017 08:48:06 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v948m6jn029127; Wed, 4 Oct 2017 08:48:06 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201710040848.v948m6jn029127@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Wed, 4 Oct 2017 08:48:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r324258 - head/usr.sbin/mountd X-SVN-Group: head X-SVN-Commit-Author: manu X-SVN-Commit-Paths: head/usr.sbin/mountd X-SVN-Commit-Revision: 324258 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Oct 2017 08:48:07 -0000 Author: manu Date: Wed Oct 4 08:48:05 2017 New Revision: 324258 URL: https://svnweb.freebsd.org/changeset/base/324258 Log: mountd: Convert mountlist to SLIST Use SLIST from sys/queue.h instead of homebrew linked list for mountlist. Reviewed by: bapt, rmacklem MFC after: 1 week Sponsored by: Gandi.net Differential Revision: https://reviews.freebsd.org/D12504 Modified: head/usr.sbin/mountd/mountd.c Modified: head/usr.sbin/mountd/mountd.c ============================================================================== --- head/usr.sbin/mountd/mountd.c Wed Oct 4 08:43:56 2017 (r324257) +++ head/usr.sbin/mountd/mountd.c Wed Oct 4 08:48:05 2017 (r324258) @@ -92,9 +92,10 @@ __FBSDID("$FreeBSD$"); * Structures for keeping the mount list and export list */ struct mountlist { - struct mountlist *ml_next; char ml_host[MNTNAMLEN+1]; char ml_dirp[MNTPATHLEN+1]; + + SLIST_ENTRY(mountlist) next; }; struct dirlist { @@ -225,7 +226,7 @@ static int xdr_mlist(XDR *, caddr_t); static void terminate(int); static SLIST_HEAD(, exportlist) exphead = SLIST_HEAD_INITIALIZER(exphead); -static struct mountlist *mlhead; +static SLIST_HEAD(, mountlist) mlhead = SLIST_HEAD_INITIALIZER(mlhead); static struct grouplist *grphead; static char *exnames_default[2] = { _PATH_EXPORTS, NULL }; static char **exnames; @@ -447,7 +448,6 @@ main(int argc, char **argv) argc -= optind; argv += optind; grphead = (struct grouplist *)NULL; - mlhead = (struct mountlist *)NULL; if (argc > 0) exnames = argv; else @@ -1254,8 +1254,7 @@ xdr_mlist(XDR *xdrsp, caddr_t cp __unused) int false = 0; char *strp; - mlp = mlhead; - while (mlp) { + SLIST_FOREACH(mlp, &mlhead, next) { if (!xdr_bool(xdrsp, &true)) return (0); strp = &mlp->ml_host[0]; @@ -1264,7 +1263,6 @@ xdr_mlist(XDR *xdrsp, caddr_t cp __unused) strp = &mlp->ml_dirp[0]; if (!xdr_string(xdrsp, &strp, MNTPATHLEN)) return (0); - mlp = mlp->ml_next; } if (!xdr_bool(xdrsp, &false)) return (0); @@ -2946,7 +2944,7 @@ parsecred(char *namelist, struct xucred *cr) static void get_mountlist(void) { - struct mountlist *mlp, **mlpp; + struct mountlist *mlp; char *host, *dirp, *cp; char str[STRSIZ]; FILE *mlfile; @@ -2959,7 +2957,6 @@ get_mountlist(void) return; } } - mlpp = &mlhead; while (fgets(str, STRSIZ, mlfile) != NULL) { cp = str; host = strsep(&cp, " \t\n"); @@ -2973,9 +2970,8 @@ get_mountlist(void) mlp->ml_host[MNTNAMLEN] = '\0'; strncpy(mlp->ml_dirp, dirp, MNTPATHLEN); mlp->ml_dirp[MNTPATHLEN] = '\0'; - mlp->ml_next = (struct mountlist *)NULL; - *mlpp = mlp; - mlpp = &mlp->ml_next; + + SLIST_INSERT_HEAD(&mlhead, mlp, next); } fclose(mlfile); } @@ -2983,23 +2979,16 @@ get_mountlist(void) static void del_mlist(char *hostp, char *dirp) { - struct mountlist *mlp, **mlpp; - struct mountlist *mlp2; + struct mountlist *mlp, *mlp2; FILE *mlfile; int fnd = 0; - mlpp = &mlhead; - mlp = mlhead; - while (mlp) { + SLIST_FOREACH_SAFE(mlp, &mlhead, next, mlp2) { if (!strcmp(mlp->ml_host, hostp) && (!dirp || !strcmp(mlp->ml_dirp, dirp))) { fnd = 1; - mlp2 = mlp; - *mlpp = mlp = mlp->ml_next; - free((caddr_t)mlp2); - } else { - mlpp = &mlp->ml_next; - mlp = mlp->ml_next; + SLIST_REMOVE(&mlhead, mlp, mountlist, next); + free((caddr_t)mlp); } } if (fnd) { @@ -3007,10 +2996,8 @@ del_mlist(char *hostp, char *dirp) syslog(LOG_ERR,"can't update %s", _PATH_RMOUNTLIST); return; } - mlp = mlhead; - while (mlp) { + SLIST_FOREACH(mlp, &mlhead, next) { fprintf(mlfile, "%s %s\n", mlp->ml_host, mlp->ml_dirp); - mlp = mlp->ml_next; } fclose(mlfile); } @@ -3019,17 +3006,14 @@ del_mlist(char *hostp, char *dirp) static void add_mlist(char *hostp, char *dirp) { - struct mountlist *mlp, **mlpp; + struct mountlist *mlp; FILE *mlfile; - mlpp = &mlhead; - mlp = mlhead; - while (mlp) { + SLIST_FOREACH(mlp, &mlhead, next) { if (!strcmp(mlp->ml_host, hostp) && !strcmp(mlp->ml_dirp, dirp)) return; - mlpp = &mlp->ml_next; - mlp = mlp->ml_next; } + mlp = (struct mountlist *)malloc(sizeof (*mlp)); if (mlp == (struct mountlist *)NULL) out_of_mem(); @@ -3037,8 +3021,7 @@ add_mlist(char *hostp, char *dirp) mlp->ml_host[MNTNAMLEN] = '\0'; strncpy(mlp->ml_dirp, dirp, MNTPATHLEN); mlp->ml_dirp[MNTPATHLEN] = '\0'; - mlp->ml_next = (struct mountlist *)NULL; - *mlpp = mlp; + SLIST_INSERT_HEAD(&mlhead, mlp, next); if ((mlfile = fopen(_PATH_RMOUNTLIST, "a")) == NULL) { syslog(LOG_ERR, "can't update %s", _PATH_RMOUNTLIST); return;