mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
logging: always NUL-terminate circular buffer
* src/util/logging.c (virLogStartup, virLogSetBufferSize): Over-allocate, so that a debugger can just print the circular buffer. Suggested by Daniel Veillard.
This commit is contained in:
parent
009bd51b94
commit
60dea30b7d
@ -197,14 +197,14 @@ int virLogStartup(void) {
|
|||||||
|
|
||||||
virLogInitialized = 1;
|
virLogInitialized = 1;
|
||||||
virLogLock();
|
virLogLock();
|
||||||
if (VIR_ALLOC_N(virLogBuffer, virLogSize) < 0) {
|
if (VIR_ALLOC_N(virLogBuffer, virLogSize + 1) < 0) {
|
||||||
/*
|
/*
|
||||||
* The debug buffer is not a critical component, allow startup
|
* The debug buffer is not a critical component, allow startup
|
||||||
* even in case of failure to allocate it in case of a
|
* even in case of failure to allocate it in case of a
|
||||||
* configuration mistake.
|
* configuration mistake.
|
||||||
*/
|
*/
|
||||||
virLogSize = 64 * 1024;
|
virLogSize = 64 * 1024;
|
||||||
if (VIR_ALLOC_N(virLogBuffer, virLogSize) < 0) {
|
if (VIR_ALLOC_N(virLogBuffer, virLogSize + 1) < 0) {
|
||||||
pbm = "Failed to allocate debug buffer: deactivating debug log\n";
|
pbm = "Failed to allocate debug buffer: deactivating debug log\n";
|
||||||
virLogSize = 0;
|
virLogSize = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -249,14 +249,14 @@ virLogSetBufferSize(int size) {
|
|||||||
oldsize = virLogSize;
|
oldsize = virLogSize;
|
||||||
oldLogBuffer = virLogBuffer;
|
oldLogBuffer = virLogBuffer;
|
||||||
|
|
||||||
if (INT_MAX / 1024 < size) {
|
if (INT_MAX / 1024 <= size) {
|
||||||
pbm = "Requested log size of %d kB too large\n";
|
pbm = "Requested log size of %d kB too large\n";
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
virLogSize = size * 1024;
|
virLogSize = size * 1024;
|
||||||
if (VIR_ALLOC_N(virLogBuffer, virLogSize) < 0) {
|
if (VIR_ALLOC_N(virLogBuffer, virLogSize + 1) < 0) {
|
||||||
pbm = "Failed to allocate debug buffer of %d kB\n";
|
pbm = "Failed to allocate debug buffer of %d kB\n";
|
||||||
virLogBuffer = oldLogBuffer;
|
virLogBuffer = oldLogBuffer;
|
||||||
virLogSize = oldsize;
|
virLogSize = oldsize;
|
||||||
|
Loading…
Reference in New Issue
Block a user