]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/test/external-agent.c
tdb2: use failtest for opening and checking database.
[ccan] / ccan / tdb2 / test / external-agent.c
index bcf5d215a7a210baf3d8beafa23b0c173c22e556..353148029736ac635d456077bb0716815c92fc8a 100644 (file)
@@ -1,5 +1,6 @@
 #include "external-agent.h"
 #include "logging.h"
+#include "lock-tracking.h"
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
 
 static struct tdb_context *tdb;
 
-#if 1 /* FIXME */
-static unsigned int locking_would_block = 0;
-static bool nonblocking_locks = false;
-#endif
-
 static enum agent_return do_operation(enum operation op, const char *name)
 {
        TDB_DATA k;
@@ -32,6 +28,8 @@ static enum agent_return do_operation(enum operation op, const char *name)
                return OTHER_FAILURE;
        }
 
+       diag("external: %s", operation_name(op));
+
        k.dptr = (void *)name;
        k.dsize = strlen(name);
 
@@ -46,6 +44,7 @@ static enum agent_return do_operation(enum operation op, const char *name)
                if (!tdb) {
                        if (!locking_would_block)
                                diag("Opening tdb gave %s", strerror(errno));
+                       forget_locking();
                        ret = OTHER_FAILURE;
                } else
                        ret = SUCCESS;
@@ -68,7 +67,6 @@ static enum agent_return do_operation(enum operation op, const char *name)
        case STORE:
                ret = tdb_store(tdb, k, k, 0) == 0 ? SUCCESS : OTHER_FAILURE;
                break;
-#if 0 /* FIXME */
        case TRANSACTION_START:
                ret = tdb_transaction_start(tdb) == 0 ? SUCCESS : OTHER_FAILURE;
                break;
@@ -78,7 +76,6 @@ static enum agent_return do_operation(enum operation op, const char *name)
        case NEEDS_RECOVERY:
                ret = tdb_needs_recovery(tdb) ? SUCCESS : FAILED;
                break;
-#endif
        case CHECK:
                ret = tdb_check(tdb, NULL, NULL) == 0 ? SUCCESS : OTHER_FAILURE;
                break;
@@ -183,12 +180,17 @@ const char *operation_name(enum operation op)
        case FETCH: return "FETCH";
        case STORE: return "STORE";
        case CHECK: return "CHECK";
-#if 0
        case TRANSACTION_START: return "TRANSACTION_START";
        case TRANSACTION_COMMIT: return "TRANSACTION_COMMIT";
        case NEEDS_RECOVERY: return "NEEDS_RECOVERY";
-#endif
        case CLOSE: return "CLOSE";
        }
        return "**INVALID**";
 }
+
+void free_external_agent(struct agent *agent)
+{
+       close(agent->cmdfd);
+       close(agent->responsefd);
+       free(agent);
+}