Page MenuHomeFreeBSD

D12504.diff
No OneTemporary

D12504.diff

Index: head/usr.sbin/mountd/mountd.c
===================================================================
--- head/usr.sbin/mountd/mountd.c
+++ head/usr.sbin/mountd/mountd.c
@@ -92,9 +92,10 @@
* 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 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 @@
argc -= optind;
argv += optind;
grphead = (struct grouplist *)NULL;
- mlhead = (struct mountlist *)NULL;
if (argc > 0)
exnames = argv;
else
@@ -1254,8 +1254,7 @@
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 @@
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 @@
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 @@
return;
}
}
- mlpp = &mlhead;
while (fgets(str, STRSIZ, mlfile) != NULL) {
cp = str;
host = strsep(&cp, " \t\n");
@@ -2973,9 +2970,8 @@
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 @@
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 @@
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 @@
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 @@
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;

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 17, 6:16 AM (14 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31582998
Default Alt Text
D12504.diff (3 KB)

Event Timeline