mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
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>
This commit is contained in:
parent
e4e6d794ee
commit
95d1e474cf
@ -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;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,8 @@ struct lmdb_private {
|
||||
int error;
|
||||
MDB_txn *read_txn;
|
||||
|
||||
pid_t pid;
|
||||
|
||||
};
|
||||
|
||||
struct lmdb_trans {
|
||||
|
Loading…
Reference in New Issue
Block a user