From: Volker Lendecke Date: Mon, 22 May 2017 15:05:57 +0000 (+0200) Subject: g_lock: Heuristically check for server existence X-Git-Tag: ldb-1.1.31~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d19e7709d9b6666f53ccfec47a86f0f0cab70925;p=thirdparty%2Fsamba.git g_lock: Heuristically check for server existence Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c index 9f3d6cc8b5e..93423023822 100644 --- a/source3/lib/g_lock.c +++ b/source3/lib/g_lock.c @@ -272,6 +272,22 @@ static NTSTATUS g_lock_trylock(struct db_record *rec, struct server_id self, my_lock = num_locks; /* doesn't exist yet */ + if ((type == G_LOCK_READ) && (num_locks > 0)) { + /* + * Read locks can stay around forever if the process + * dies. Do a heuristic check for process existence: + * Check one random process for existence. Hopefully + * this will keep runaway read locks under control. + */ + i = generate_random() % num_locks; + + if (!serverid_exists(&locks[i].pid)) { + locks[i] = locks[num_locks-1]; + num_locks -=1; + modified = true; + } + } + for (i=0; i