device-mapper-multipath/0017-libmultipath-sysfs-cleanup-file-descriptors-on-pthre.patch
Benjamin Marzinski ef9089f4e8 device-mapper-multipath-0.9.0-3
Update to the head of the upstream staging branch
  * Patches 0005-0042 are from the upstream staging branch
  * Previous patches 0005 & 0006 are now patches 0023 & 0005
Rename redhat patches
  * Previous patches 0007-0017 are now patches 0043-0053
Change from using readline to libedit
  * readline is licensed GPL v3, and multipathd includes code
    licensed gpl v2.
Remove README.alua
  * information moved to README.md
2022-08-19 12:48:04 -05:00

72 lines
2.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martin Wilck <mwilck@suse.com>
Date: Tue, 5 Jul 2022 18:07:57 +0200
Subject: [PATCH] libmultipath: sysfs: cleanup file descriptors on
pthread_cancel()
Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/sysfs.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/libmultipath/sysfs.c b/libmultipath/sysfs.c
index 9c84af70..64946385 100644
--- a/libmultipath/sysfs.c
+++ b/libmultipath/sysfs.c
@@ -49,7 +49,7 @@ static ssize_t __sysfs_attr_get_value(struct udev_device *dev, const char *attr_
{
const char *syspath;
char devpath[PATH_MAX];
- int fd;
+ long fd;
ssize_t size = -1;
if (!dev || !attr_name || !value || !value_len) {
@@ -74,6 +74,8 @@ static ssize_t __sysfs_attr_get_value(struct udev_device *dev, const char *attr_
__func__, devpath, strerror(errno));
return -errno;
}
+ pthread_cleanup_push(close_fd, (void *)fd);
+
size = read(fd, value, value_len);
if (size < 0) {
size = -errno;
@@ -90,7 +92,7 @@ static ssize_t __sysfs_attr_get_value(struct udev_device *dev, const char *attr_
size = strchop(value);
}
- close(fd);
+ pthread_cleanup_pop(1);
return size;
}
@@ -112,7 +114,7 @@ ssize_t sysfs_attr_set_value(struct udev_device *dev, const char *attr_name,
{
const char *syspath;
char devpath[PATH_MAX];
- int fd;
+ long fd;
ssize_t size = -1;
if (!dev || !attr_name || !value || !value_len) {
@@ -138,6 +140,7 @@ ssize_t sysfs_attr_set_value(struct udev_device *dev, const char *attr_name,
__func__, devpath, strerror(errno));
return -errno;
}
+ pthread_cleanup_push(close_fd, (void *)fd);
size = write(fd, value, value_len);
if (size < 0) {
@@ -148,7 +151,7 @@ ssize_t sysfs_attr_set_value(struct udev_device *dev, const char *attr_name,
condlog(3, "%s: underflow writing %zu bytes to %s. Wrote %zd bytes",
__func__, value_len, devpath, size);
- close(fd);
+ pthread_cleanup_pop(1);
return size;
}