1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

dmeventd: event string parser handles empty field

Improve event string parser to avoid unneeded alloc+free.

Daemon talk function uses '-' to mark NULL/missing field.
So restore the NULL pointer back on parser.

This should have made old tools like 'dmevent_tool' work again.
As now 'uuid' or 'dso' could become NULL and then be
properly used in _want_registered_device() function.

Since lvm2 always fill these parameters, this change should
have no effect on lvm2.
This commit is contained in:
Zdenek Kabelac 2015-10-27 11:12:59 +01:00
parent 3b5939bbbb
commit 5d76bdcdbd
2 changed files with 32 additions and 17 deletions

View File

@ -1,5 +1,6 @@
Version 1.02.110 - Version 1.02.110 -
====================================== ======================================
Fix/restore parsing of empty field '-' when processing dmeventd event.
Enhance dm_tree_node_size_changed() to recognize size reduction. Enhance dm_tree_node_size_changed() to recognize size reduction.
Support exit on idle for dmenventd (1 hour). Support exit on idle for dmenventd (1 hour).
Add support to allow unmonitor device from plugin itself. Add support to allow unmonitor device from plugin itself.

View File

@ -473,34 +473,48 @@ static int _pthread_create_smallstack(pthread_t *t, void *(*fun)(void *), void *
/* /*
* Fetch a string off src and duplicate it into *ptr. * Fetch a string off src and duplicate it into *ptr.
* Pay attention to zero-length strings. * Pay attention to zero-length and 'empty' strings ('-').
*/ */
/* FIXME? move to libdevmapper to share with the client lib (need to /* FIXME? move to libdevmapper to share with the client lib (need to
make delimiter a parameter then) */ make delimiter a parameter then) */
static int _fetch_string(char **ptr, char **src, const int delimiter) static int _fetch_string(char **ptr, char **src, const int delimiter)
{ {
int ret = 0; int ret = 1;
char *p; char *p;
size_t len; size_t len;
*ptr = NULL; /* Empty field returns NULL pointer */
if ((p = strchr(*src, delimiter))) if ((*src)[0] == '-') {
*p = 0; /* Could be empty field '-', handle without allocation */
if ((*src)[1] == '\0') {
if ((*ptr = dm_strdup(*src))) {
if ((len = strlen(*ptr)))
*src += len;
else {
dm_free(*ptr);
*ptr = NULL;
}
(*src)++; (*src)++;
ret = 1; goto out;
} else if ((*src)[1] == delimiter) {
(*src) += 2;
goto out;
}
} }
if (p) if ((p = strchr(*src, delimiter))) {
if (*src < p) {
*p = 0; /* Temporary exit with \0 */
if (!(*ptr = dm_strdup(*src))) {
log_error("Failed to fetch item %s.", *src);
ret = 0; /* Allocation fail */
}
*p = delimiter; *p = delimiter;
*src = p;
}
(*src)++; /* Skip delmiter, next field */
} else if ((len = strlen(*src))) {
/* No delimiter, item ends with '\0' */
if (!(*ptr = dm_strdup(*src))) {
log_error("Failed to fetch last item %s.", *src);
ret = 0; /* Fail */
}
*src += len + 1;
}
out:
return ret; return ret;
} }