Blame SOURCES/autofs-5.1.7-add-ext_mount_hash_mutex-lock-helpers.patch

29d2b9
autofs-5.1.7 - add ext_mount_hash_mutex lock helpers
29d2b9
29d2b9
From: Ian Kent <raven@themaw.net>
29d2b9
29d2b9
Coverity: check_return: Calling "pthread_mutex_lock" without checking
29d2b9
	  return value.
29d2b9
29d2b9
Well, I use helpers to do this in many places so can't really disagree.
29d2b9
29d2b9
Signed-off-by: Ian Kent <raven@themaw.net>
29d2b9
---
29d2b9
 CHANGELOG    |    1 +
29d2b9
 lib/mounts.c |   26 ++++++++++++++++++++------
29d2b9
 2 files changed, 21 insertions(+), 6 deletions(-)
29d2b9
29d2b9
diff --git a/CHANGELOG b/CHANGELOG
29d2b9
index b1b28888..ff44ac25 100644
29d2b9
--- a/CHANGELOG
29d2b9
+++ b/CHANGELOG
29d2b9
@@ -65,6 +65,7 @@
29d2b9
 - fix double free in parse_mapent().
29d2b9
 - refactor lookup_prune_one_cache() a bit.
29d2b9
 - cater for empty mounts list in mnts_get_expire_list().
29d2b9
+- add ext_mount_hash_mutex lock helpers.
29d2b9
 
29d2b9
 25/01/2021 autofs-5.1.7
29d2b9
 - make bind mounts propagation slave by default.
29d2b9
diff --git a/lib/mounts.c b/lib/mounts.c
29d2b9
index 3996eb5e..c24d1a88 100644
29d2b9
--- a/lib/mounts.c
29d2b9
+++ b/lib/mounts.c
29d2b9
@@ -788,6 +788,20 @@ char *make_mnt_name_string(char *path)
29d2b9
 	return mnt_name;
29d2b9
 }
29d2b9
 
29d2b9
+static void ext_mount_hash_mutex_lock(void)
29d2b9
+{
29d2b9
+	int status = pthread_mutex_lock(&ext_mount_hash_mutex);
29d2b9
+	if (status)
29d2b9
+		fatal(status);
29d2b9
+}
29d2b9
+
29d2b9
+static void ext_mount_hash_mutex_unlock(void)
29d2b9
+{
29d2b9
+	int status = pthread_mutex_unlock(&ext_mount_hash_mutex);
29d2b9
+	if (status)
29d2b9
+		fatal(status);
29d2b9
+}
29d2b9
+
29d2b9
 static struct ext_mount *ext_mount_lookup(const char *mp)
29d2b9
 {
29d2b9
 	uint32_t hval = hash(mp, HASH_SIZE(ext_mounts_hash));
29d2b9
@@ -806,7 +820,7 @@ int ext_mount_add(const char *path, const char *umount)
29d2b9
 	struct ext_mount *em;
29d2b9
 	int ret = 0;
29d2b9
 
29d2b9
-	pthread_mutex_lock(&ext_mount_hash_mutex);
29d2b9
+	ext_mount_hash_mutex_lock();
29d2b9
 
29d2b9
 	em = ext_mount_lookup(path);
29d2b9
 	if (em) {
29d2b9
@@ -840,7 +854,7 @@ int ext_mount_add(const char *path, const char *umount)
29d2b9
 
29d2b9
 	ret = 1;
29d2b9
 done:
29d2b9
-	pthread_mutex_unlock(&ext_mount_hash_mutex);
29d2b9
+	ext_mount_hash_mutex_unlock();
29d2b9
 	return ret;
29d2b9
 }
29d2b9
 
29d2b9
@@ -849,7 +863,7 @@ int ext_mount_remove(const char *path)
29d2b9
 	struct ext_mount *em;
29d2b9
 	int ret = 0;
29d2b9
 
29d2b9
-	pthread_mutex_lock(&ext_mount_hash_mutex);
29d2b9
+	ext_mount_hash_mutex_lock();
29d2b9
 
29d2b9
 	em = ext_mount_lookup(path);
29d2b9
 	if (!em)
29d2b9
@@ -867,7 +881,7 @@ int ext_mount_remove(const char *path)
29d2b9
 		ret = 1;
29d2b9
 	}
29d2b9
 done:
29d2b9
-	pthread_mutex_unlock(&ext_mount_hash_mutex);
29d2b9
+	ext_mount_hash_mutex_unlock();
29d2b9
 	return ret;
29d2b9
 }
29d2b9
 
29d2b9
@@ -876,13 +890,13 @@ int ext_mount_inuse(const char *path)
29d2b9
 	struct ext_mount *em;
29d2b9
 	int ret = 0;
29d2b9
 
29d2b9
-	pthread_mutex_lock(&ext_mount_hash_mutex);
29d2b9
+	ext_mount_hash_mutex_lock();
29d2b9
 	em = ext_mount_lookup(path);
29d2b9
 	if (!em)
29d2b9
 		goto done;
29d2b9
 	ret = em->ref;
29d2b9
 done:
29d2b9
-	pthread_mutex_unlock(&ext_mount_hash_mutex);
29d2b9
+	ext_mount_hash_mutex_unlock();
29d2b9
 	return ret;
29d2b9
 }
29d2b9