void-packages/srcpkgs/lvm2/patches/lvm2-2_02_99-close-dmeventd-fifo-fds-on-exec.patch

109 lines
3.5 KiB
Diff

commit b7e453f3821c4a896e00a29800351687d3365f64
Author: Peter Rajnoha <prajnoha@redhat.com>
Date: Tue May 14 11:26:40 2013 +0200
lvm2-2_02_99-close-dmeventd-fifo-fds-on-exec.patch
---
WHATS_NEW_DM | 1 +
daemons/dmeventd/dmeventd.c | 37 ++++++++++++++++++++++++++++---------
2 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 9574fdf..30d01f9 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.78 -
===================================
+ Close open dmeventd FIFO file descriptors on exec (FD_CLOEXEC).
Add DM_DISABLE_UDEV environment variable to manage dev nodes by libdm only.
Automatically deactivate failed preloaded dm tree node.
Fix dm_task_set_cookie to properly process udev flags if udev_sync disabled.
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 13148c3..5f2339f 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -1237,7 +1237,8 @@ static int _get_timeout(struct message_data *message_data)
/* Initialize a fifos structure with path names. */
static void _init_fifos(struct dm_event_fifos *fifos)
{
- memset(fifos, 0, sizeof(*fifos));
+ fifos->client = -1;
+ fifos->server = -1;
fifos->client_path = DM_EVENT_FIFO_CLIENT;
fifos->server_path = DM_EVENT_FIFO_SERVER;
@@ -1254,7 +1255,7 @@ static int _open_fifos(struct dm_event_fifos *fifos)
syslog(LOG_ERR, "%s: Failed to create client fifo %s: %m.\n",
__func__, fifos->client_path);
(void) dm_prepare_selinux_context(NULL, 0);
- return 0;
+ goto fail;
}
/* Create server fifo. */
@@ -1263,7 +1264,7 @@ static int _open_fifos(struct dm_event_fifos *fifos)
syslog(LOG_ERR, "%s: Failed to create server fifo %s: %m.\n",
__func__, fifos->server_path);
(void) dm_prepare_selinux_context(NULL, 0);
- return 0;
+ goto fail;
}
(void) dm_prepare_selinux_context(NULL, 0);
@@ -1281,31 +1282,49 @@ static int _open_fifos(struct dm_event_fifos *fifos)
if (chmod(fifos->client_path, 0600)) {
syslog(LOG_ERR, "Unable to set correct file permissions on %s: %m.\n",
fifos->client_path);
- return 0;
+ goto fail;
}
if (chmod(fifos->server_path, 0600)) {
syslog(LOG_ERR, "Unable to set correct file permissions on %s: %m.\n",
fifos->server_path);
- return 0;
+ goto fail;
}
/* Need to open read+write or we will block or fail */
if ((fifos->server = open(fifos->server_path, O_RDWR)) < 0) {
syslog(LOG_ERR, "Failed to open fifo server %s: %m.\n",
fifos->server_path);
- return 0;
+ goto fail;
+ }
+
+ if (fcntl(fifos->server, F_SETFD, FD_CLOEXEC) < 0) {
+ syslog(LOG_ERR, "Failed to set FD_CLOEXEC for fifo server %s: %m.\n",
+ fifos->server_path);
+ goto fail;
}
/* Need to open read+write for select() to work. */
if ((fifos->client = open(fifos->client_path, O_RDWR)) < 0) {
syslog(LOG_ERR, "Failed to open fifo client %s: %m", fifos->client_path);
- if (close(fifos->server))
- syslog(LOG_ERR, "Failed to close fifo server %s: %m", fifos->server_path);
- return 0;
+ goto fail;
+ }
+
+ if (fcntl(fifos->client, F_SETFD, FD_CLOEXEC) < 0) {
+ syslog(LOG_ERR, "Failed to set FD_CLOEXEC for fifo client %s: %m.\n",
+ fifos->client_path);
+ goto fail;
}
return 1;
+fail:
+ if (fifos->server >= 0 && close(fifos->server))
+ syslog(LOG_ERR, "Failed to close fifo server %s: %m", fifos->server_path);
+
+ if (fifos->client >= 0 && close(fifos->client))
+ syslog(LOG_ERR, "Failed to close fifo client %s: %m", fifos->client_path);
+
+ return 0;
}
/*