lib: Add server_id_db_prune_name
authorVolker Lendecke <vl@samba.org>
Sun, 26 Apr 2015 09:02:27 +0000 (11:02 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 7 Jul 2015 21:51:23 +0000 (23:51 +0200)
With this you can remove a foreign mapping. Required to clean up dead
processes.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/util/server_id_db.c
lib/util/server_id_db.h

index 7f5b055f1715fc6ead2cdb056293328c62b44c21..83547525188ce3f6aff64cb6e7a4970fc8ebca29 100644 (file)
@@ -118,22 +118,18 @@ int server_id_db_add(struct server_id_db *db, const char *name)
        return 0;
 }
 
-int server_id_db_remove(struct server_id_db *db, const char *name)
+int server_id_db_prune_name(struct server_id_db *db, const char *name,
+                           struct server_id server)
 {
        struct tdb_context *tdb = db->tdb->tdb;
        struct server_id_buf buf;
        TDB_DATA key;
        uint8_t *data;
-       char *ids, *n, *id;
+       char *ids, *id;
        int ret;
 
-       n = strv_find(db->names, name);
-       if (n == NULL) {
-               return ENOENT;
-       }
-
        key = string_term_tdb_data(name);
-       server_id_str_buf(db->pid, &buf);
+       server_id_str_buf(server, &buf);
 
        ret = tdb_chainlock(tdb, key);
        if (ret == -1) {
@@ -162,9 +158,22 @@ int server_id_db_remove(struct server_id_db *db, const char *name)
 
        tdb_chainunlock(tdb, key);
 
-       if (ret == -1) {
-               enum TDB_ERROR err = tdb_error(tdb);
-               return map_unix_error_from_tdb(err);
+       return 0;
+}
+
+int server_id_db_remove(struct server_id_db *db, const char *name)
+{
+       char *n;
+       int ret;
+
+       n = strv_find(db->names, name);
+       if (n == NULL) {
+               return ENOENT;
+       }
+
+       ret = server_id_db_prune_name(db, name, db->pid);
+       if (ret != 0) {
+               return ret;
        }
 
        strv_delete(&db->names, n);
index 31b3305f47154c7932704c0eb33a9283bc094c6d..ff864360409a0a3fd13bedb0d63f6dd0dd45621e 100644 (file)
@@ -32,6 +32,8 @@ struct server_id_db *server_id_db_init(TALLOC_CTX *mem_ctx,
 void server_id_db_reinit(struct server_id_db *db, struct server_id pid);
 int server_id_db_add(struct server_id_db *db, const char *name);
 int server_id_db_remove(struct server_id_db *db, const char *name);
+int server_id_db_prune_name(struct server_id_db *db, const char *name,
+                           struct server_id server);
 int server_id_db_lookup(struct server_id_db *db, const char *name,
                        TALLOC_CTX *mem_ctx, unsigned *num_servers,
                        struct server_id **servers);