mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-18 10:04:20 +03:00
Unfortunately, blank lines are sometimes produced by config serializer, and
this interferes with their role as message separator in the lvmetad protocol. Switch to using "##" on an otherwise blank line as a separator.
This commit is contained in:
parent
d540685159
commit
f43c89bf71
@ -38,7 +38,7 @@ int read_buffer(int fd, char **buffer) {
|
|||||||
*buffer = new;
|
*buffer = new;
|
||||||
} else {
|
} else {
|
||||||
(*buffer)[bytes] = 0;
|
(*buffer)[bytes] = 0;
|
||||||
if ((end = strstr((*buffer) + bytes - 2, "\n\n"))) {
|
if ((end = strstr((*buffer) + bytes - 4, "\n##\n"))) {
|
||||||
*end = 0;
|
*end = 0;
|
||||||
break; /* success, we have the full message now */
|
break; /* success, we have the full message now */
|
||||||
}
|
}
|
||||||
@ -58,18 +58,29 @@ fail:
|
|||||||
*
|
*
|
||||||
* TODO use select on EWOULDBLOCK/EAGAIN to avoid useless spinning
|
* TODO use select on EWOULDBLOCK/EAGAIN to avoid useless spinning
|
||||||
*/
|
*/
|
||||||
int write_buffer(int fd, char *buffer, int length) {
|
int write_buffer(int fd, const char *buffer, int length) {
|
||||||
|
int done = 0;
|
||||||
int written = 0;
|
int written = 0;
|
||||||
|
write:
|
||||||
while (1) {
|
while (1) {
|
||||||
int result = write(fd, buffer + written, length - written);
|
int result = write(fd, buffer + written, length - written);
|
||||||
if (result > 0)
|
if (result > 0)
|
||||||
written += result;
|
written += result;
|
||||||
if (result < 0 && errno != EWOULDBLOCK && errno != EAGAIN)
|
if (result < 0 && errno != EWOULDBLOCK && errno != EAGAIN)
|
||||||
break; /* too bad */
|
return 0; /* too bad */
|
||||||
if (written == length)
|
if (written == length) {
|
||||||
return 1; /* done */
|
if (done)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
break; /* done */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
const char *terminate = "\n##\n";
|
||||||
|
buffer = terminate;
|
||||||
|
length = 4;
|
||||||
|
written = 0;
|
||||||
|
done = 1;
|
||||||
|
goto write;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *format_buffer(const char *what, const char *id, va_list ap)
|
char *format_buffer(const char *what, const char *id, va_list ap)
|
||||||
@ -106,10 +117,6 @@ char *format_buffer(const char *what, const char *id, va_list ap)
|
|||||||
if (!buffer) goto fail;
|
if (!buffer) goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
old = buffer;
|
|
||||||
dm_asprintf(&buffer, "%s\n", buffer);
|
|
||||||
dm_free(old);
|
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
fail:
|
fail:
|
||||||
dm_free(buffer);
|
dm_free(buffer);
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
#include <libdevmapper.h>
|
#include <libdevmapper.h>
|
||||||
|
|
||||||
int read_buffer(int fd, char **buffer);
|
int read_buffer(int fd, char **buffer);
|
||||||
int write_buffer(int fd, char *buffer, int length);
|
int write_buffer(int fd, const char *buffer, int length);
|
||||||
char *format_buffer(const char *what, const char *id, va_list ap);
|
char *format_buffer(const char *what, const char *id, va_list ap);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user