From b593cc78aeaaa5d79ddfccc46bdbac6296a63890 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 26 Apr 2015 11:02:27 +0200 Subject: [PATCH] lib: Add server_id_db_prune_name With this you can remove a foreign mapping. Required to clean up dead processes. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- lib/util/server_id_db.c | 31 ++++++++++++++++++++----------- lib/util/server_id_db.h | 2 ++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/util/server_id_db.c b/lib/util/server_id_db.c index 7f5b055f171..83547525188 100644 --- a/lib/util/server_id_db.c +++ b/lib/util/server_id_db.c @@ -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); diff --git a/lib/util/server_id_db.h b/lib/util/server_id_db.h index 31b3305f471..ff864360409 100644 --- a/lib/util/server_id_db.h +++ b/lib/util/server_id_db.h @@ -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); -- 2.11.4.GIT