]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - support/export/export.c
libexport.a: Allow client_init() to fail instead of exit
[nfs-utils.git] / support / export / export.c
index e5e6cb0504158447d006c8855c58e54a4e5c581e..3e4da699091110645362457b3d2f3e264949233e 100644 (file)
@@ -28,6 +28,34 @@ static int   export_check(nfs_export *, struct hostent *, char *);
 static nfs_export *
                export_allowed_internal(struct hostent *hp, char *path);
 
 static nfs_export *
                export_allowed_internal(struct hostent *hp, char *path);
 
+static void
+export_free(nfs_export *exp)
+{
+       xfree(exp->m_export.e_squids);
+       xfree(exp->m_export.e_sqgids);
+       free(exp->m_export.e_mountpoint);
+       free(exp->m_export.e_fslocdata);
+
+       xfree(exp->m_export.e_hostname);
+       xfree(exp);
+}
+
+static void warn_duplicated_exports(nfs_export *exp, struct exportent *eep)
+{
+       if (exp->m_export.e_flags != eep->e_flags) {
+               xlog(L_ERROR, "incompatible duplicated export entries:");
+               xlog(L_ERROR, "\t%s:%s (0x%x) [IGNORED]", eep->e_hostname,
+                               eep->e_path, eep->e_flags);
+               xlog(L_ERROR, "\t%s:%s (0x%x)", exp->m_export.e_hostname,
+                               exp->m_export.e_path, exp->m_export.e_flags);
+       } else {
+               xlog(L_ERROR, "duplicated export entries:");
+               xlog(L_ERROR, "\t%s:%s", eep->e_hostname, eep->e_path);
+               xlog(L_ERROR, "\t%s:%s", exp->m_export.e_hostname,
+                               exp->m_export.e_path);
+       }
+}
+
 int
 export_read(char *fname)
 {
 int
 export_read(char *fname)
 {
@@ -36,27 +64,13 @@ export_read(char *fname)
 
        setexportent(fname, "r");
        while ((eep = getexportent(0,1)) != NULL) {
 
        setexportent(fname, "r");
        while ((eep = getexportent(0,1)) != NULL) {
-         exp = export_lookup(eep->e_hostname, eep->e_path, 0);
-         if (!exp)
-           export_create(eep,0);
-         else {
-           if (exp->m_export.e_flags != eep->e_flags) {
-             xlog(L_ERROR, "incompatible duplicated export entries:");
-             xlog(L_ERROR, "\t%s:%s (0x%x) [IGNORED]", eep->e_hostname,
-                  eep->e_path, eep->e_flags);
-             xlog(L_ERROR, "\t%s:%s (0x%x)", exp->m_export.e_hostname,
-                  exp->m_export.e_path, exp->m_export.e_flags);
-           }
-           else {
-             xlog(L_ERROR, "duplicated export entries:");
-             xlog(L_ERROR, "\t%s:%s", eep->e_hostname, eep->e_path);
-             xlog(L_ERROR, "\t%s:%s", exp->m_export.e_hostname,
-                  exp->m_export.e_path);
-           }
-         }
+               exp = export_lookup(eep->e_hostname, eep->e_path, 0);
+               if (!exp)
+                       export_create(eep, 0);
+               else
+                       warn_duplicated_exports(exp, eep);
        }
        endexportent();
        }
        endexportent();
-
        return 0;
 }
 
        return 0;
 }
 
@@ -115,6 +129,10 @@ export_dup(nfs_export *exp, struct hostent *hp)
        if (exp->m_export.e_hostname)
                new->m_export.e_hostname = xstrdup(exp->m_export.e_hostname);
        clp = client_dup(exp->m_client, hp);
        if (exp->m_export.e_hostname)
                new->m_export.e_hostname = xstrdup(exp->m_export.e_hostname);
        clp = client_dup(exp->m_client, hp);
+       if (clp == NULL) {
+               export_free(new);
+               return NULL;
+       }
        clp->m_count++;
        new->m_client = clp;
        new->m_mayexport = exp->m_mayexport;
        clp->m_count++;
        new->m_client = clp;
        new->m_mayexport = exp->m_mayexport;
@@ -126,6 +144,7 @@ export_dup(nfs_export *exp, struct hostent *hp)
 
        return new;
 }
 
        return new;
 }
+
 /*
  * Add export entry to hash table
  */
 /*
  * Add export entry to hash table
  */
@@ -257,6 +276,10 @@ export_check(nfs_export *exp, struct hostent *hp, char *path)
        return client_check(exp->m_client, hp);
 }
 
        return client_check(exp->m_client, hp);
 }
 
+/**
+ * export_freeall - deallocate all nfs_export records
+ *
+ */
 void
 export_freeall(void)
 {
 void
 export_freeall(void)
 {
@@ -267,22 +290,13 @@ export_freeall(void)
                for (exp = exportlist[i].p_head; exp; exp = nxt) {
                        nxt = exp->m_next;
                        client_release(exp->m_client);
                for (exp = exportlist[i].p_head; exp; exp = nxt) {
                        nxt = exp->m_next;
                        client_release(exp->m_client);
-                       if (exp->m_export.e_squids)
-                               xfree(exp->m_export.e_squids);
-                       if (exp->m_export.e_sqgids)
-                               xfree(exp->m_export.e_sqgids);
-                       if (exp->m_export.e_mountpoint)
-                               free(exp->m_export.e_mountpoint);
-                       if (exp->m_export.e_fslocdata)
-                               xfree(exp->m_export.e_fslocdata);
-                       xfree(exp->m_export.e_hostname);
-                       xfree(exp);
+                       export_free(exp);
+               }
+               for (j = 0; j < HASH_TABLE_SIZE; j++) {
+                       exportlist[i].entries[j].p_first = NULL;
+                       exportlist[i].entries[j].p_last = NULL;
                }
                }
-      for(j = 0; j < HASH_TABLE_SIZE; j++) {
-        exportlist[i].entries[j].p_first = NULL;
-        exportlist[i].entries[j].p_last = NULL;
-      }
-      exportlist[i].p_head = NULL;
+               exportlist[i].p_head = NULL;
        }
        client_freeall();
 }
        }
        client_freeall();
 }