summaryrefslogtreecommitdiff
path: root/daemons
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2014-04-18 14:42:39 +0200
committerZdenek Kabelac <zkabelac@redhat.com>2014-04-18 16:52:35 +0200
commit0927605ec3214349f69d849f72d138696231f3e7 (patch)
treef1965516b08c5cdd6ce123687540b27917c0acd5 /daemons
parent3febd2c9d47eb2af60a576a07c4042331930c2c1 (diff)
downloadlvm2-0927605ec3214349f69d849f72d138696231f3e7.tar.gz
cleanup: dmeventd improve _clien_write code
Switch to allocate buffer from heap, since it might be potentially bigger when extremaly large set of volumes would be monitored. In case of allocation failure send ENOMEM message. Also implicitelly ignore msg->size when msg->data is NULL.
Diffstat (limited to 'daemons')
-rw-r--r--daemons/dmeventd/dmeventd.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index f8b547019..b4080db9f 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -1397,18 +1397,27 @@ static int _client_read(struct dm_event_fifos *fifos,
static int _client_write(struct dm_event_fifos *fifos,
struct dm_event_daemon_message *msg)
{
+ uint32_t temp[2];
unsigned bytes = 0;
int ret = 0;
fd_set fds;
- size_t size = 2 * sizeof(uint32_t) + msg->size;
- uint32_t *header = alloca(size);
+ size_t size = 2 * sizeof(uint32_t) + ((msg->data) ? msg->size : 0);
+ uint32_t *header = dm_malloc(size);
char *buf = (char *)header;
- header[0] = htonl(msg->cmd);
- header[1] = htonl(msg->size);
- if (msg->data)
- memcpy(buf + 2 * sizeof(uint32_t), msg->data, msg->size);
+ if (!header) {
+ /* Reply with ENOMEM message */
+ header = temp;
+ size = sizeof(temp);
+ header[0] = htonl(-ENOMEM);
+ header[1] = 0;
+ } else {
+ header[0] = htonl(msg->cmd);
+ header[1] = htonl((msg->data) ? msg->size : 0);
+ if (msg->data)
+ memcpy(buf + 2 * sizeof(uint32_t), msg->data, msg->size);
+ }
while (bytes < size) {
do {
@@ -1423,7 +1432,10 @@ static int _client_write(struct dm_event_fifos *fifos,
break;
}
- return bytes == size;
+ if (header != temp)
+ dm_free(header);
+
+ return (bytes == size);
}
/*