summaryrefslogtreecommitdiff
path: root/lib/ldb
diff options
context:
space:
mode:
authorGarming Sam <garming@catalyst.net.nz>2018-03-05 16:04:03 +1300
committerAndrew Bartlett <abartlet@samba.org>2018-05-23 02:27:11 +0200
commit95d1e474cfe24ea65f3cd0bca82d531e6f56e363 (patch)
tree97622cb3ba945be97a3b4685145b5ef1ae755c25 /lib/ldb
parente4e6d794ee667b84db9bb1f248bf5ed411e5f5be (diff)
downloadsamba-95d1e474cfe24ea65f3cd0bca82d531e6f56e363.tar.gz
ldb_mdb: Store pid to change destructor on fork
Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'lib/ldb')
-rw-r--r--lib/ldb/ldb_mdb/ldb_mdb.c22
-rw-r--r--lib/ldb/ldb_mdb/ldb_mdb.h2
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/ldb/ldb_mdb/ldb_mdb.c b/lib/ldb/ldb_mdb/ldb_mdb.c
index d154ede8ede..e073e17da3c 100644
--- a/lib/ldb/ldb_mdb/ldb_mdb.c
+++ b/lib/ldb/ldb_mdb/ldb_mdb.c
@@ -595,6 +595,25 @@ static int lmdb_pvt_destructor(struct lmdb_private *lmdb)
{
struct lmdb_trans *ltx = NULL;
+ /* Check if this is a forked child */
+ if (getpid() != lmdb->pid) {
+ int fd = 0;
+ /*
+ * We cannot call mdb_env_close or commit any transactions,
+ * otherwise they might appear finished in the parent.
+ *
+ */
+
+ if (mdb_env_get_fd(lmdb->env, &fd) == 0) {
+ close(fd);
+ }
+
+ /* Remove the pointer, so that no access should occur */
+ lmdb->env = NULL;
+
+ return 0;
+ }
+
/*
* Close the read transaction if it's open
*/
@@ -685,6 +704,9 @@ static int lmdb_pvt_open(TALLOC_CTX *mem_ctx,
return ldb_mdb_err_map(ret);
}
+ /* Store the original pid during the LMDB open */
+ lmdb->pid = getpid();
+
return LDB_SUCCESS;
}
diff --git a/lib/ldb/ldb_mdb/ldb_mdb.h b/lib/ldb/ldb_mdb/ldb_mdb.h
index d4a635ca693..8f21493927b 100644
--- a/lib/ldb/ldb_mdb/ldb_mdb.h
+++ b/lib/ldb/ldb_mdb/ldb_mdb.h
@@ -41,6 +41,8 @@ struct lmdb_private {
int error;
MDB_txn *read_txn;
+ pid_t pid;
+
};
struct lmdb_trans {