opr: export softsig functions
[openafs.git] / tests / common / config.c
index 7574465..6a0e3e1 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <hcrypto/des.h>
 
+#include <tests/tap/basic.h>
 #include "common.h"
 
 static FILE *
@@ -74,6 +75,9 @@ char *
 afstest_BuildTestConfig(void) {
     char *dir = NULL;
     FILE *file;
+    struct hostent *host;
+    char hostname[255];
+    struct in_addr iaddr;
 
     if (asprintf(&dir, "%s/afs_XXXXXX", gettmpdir()) == -1)
        goto fail;
@@ -81,10 +85,20 @@ afstest_BuildTestConfig(void) {
     if (mkdtemp(dir) == NULL)
        goto fail;
 
-    /* Create a CellServDB */
+    /* Work out which IP address to use in our CellServDB. We figure this out
+     * according to the IP address which ubik is most likely to pick for one of
+     * our db servers */
+
+    gethostname(hostname, sizeof(hostname));
+    host = gethostbyname(hostname);
+    if (!host)
+       return NULL;
+
+    memcpy(&iaddr, host->h_addr, 4);
+
     file = openConfigFile(dir, "CellServDB");
     fprintf(file, ">example.org # An example cell\n");
-    fprintf(file, "127.0.0.1 #test.example.org\n");
+    fprintf(file, "%s #test.example.org\n", inet_ntoa(iaddr));
     fclose(file);
 
     /* Create a ThisCell file */
@@ -107,11 +121,20 @@ fail:
 void
 afstest_UnlinkTestConfig(char *dir)
 {
-    unlinkConfigFile(dir, "KeyFile");
-    unlinkConfigFile(dir, "CellServDB");
-    unlinkConfigFile(dir, "ThisCell");
-    unlinkConfigFile(dir, "UserList");
-    rmdir(dir);
+    DIR *dirp;
+    struct dirent *de;
+
+    /* Sanity check, only zap directories that look like ours */
+    if (!strstr(dir, "afs_"))
+       return;
+    if (getenv("MAKECHECK") != NULL) {
+       dirp = opendir(dir);
+       if (!dirp)
+           return;
+       while ((de = readdir(dirp)))
+           unlinkConfigFile(dir, de->d_name);
+       rmdir(dir);
+    }
 }
 
 int