Update the error log functionality to avoid losing writes
This commit is contained in:
1 parent
bb5f12b2fa
commit
b334ec80bb
3 files changed
+34
-9
No files matched your search
@@ -615,28 +615,44 @@ int errlogInit(int bufsize)
|
||||
return errlogInit2(bufsize, DEFAULT_MAX_MSG_SIZE);
|
||||
}
|
||||
|
||||
void errlogBufResize(int bufsize, int maxMsgSize)
|
||||
int errlogBufResize(int bufsize, int maxMsgSize)
|
||||
{
|
||||
char* logbuf = NULL;
|
||||
char* printbuf = NULL;
|
||||
|
||||
epicsMutexMustLock(pvt.bufSizeLock);
|
||||
|
||||
// Only increasing the buffer size is allowed!
|
||||
if (bufsize < pvt.bufSize) {
|
||||
epicsMutexUnlock(pvt.bufSizeLock);
|
||||
fprintf(stderr, "Shrinking the errorlog buffer is not allowed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (bufsize < MIN_BUFFER_SIZE)
|
||||
bufsize = MIN_BUFFER_SIZE;
|
||||
|
||||
if (maxMsgSize < MIN_MESSAGE_SIZE)
|
||||
maxMsgSize = MIN_MESSAGE_SIZE;
|
||||
else if (maxMsgSize > MAX_MESSAGE_SIZE)
|
||||
maxMsgSize = MAX_MESSAGE_SIZE;
|
||||
|
||||
errlogFlush();
|
||||
logbuf = calloc(1, bufsize);
|
||||
printbuf = calloc(1, bufsize);
|
||||
|
||||
epicsMutexMustLock(pvt.bufSizeLock);
|
||||
epicsMutexMustLock(pvt.msgQueueLock);
|
||||
|
||||
memcpy(logbuf, pvt.log->base, pvt.bufSize);
|
||||
free(pvt.log->base);
|
||||
pvt.log->base = logbuf;
|
||||
|
||||
memcpy(printbuf, &pvt.print->base, pvt.bufSize);
|
||||
free(pvt.print->base);
|
||||
pvt.print->base = printbuf;
|
||||
|
||||
pvt.bufSize = bufsize;
|
||||
pvt.maxMsgSize = maxMsgSize;
|
||||
|
||||
free(pvt.log->base);
|
||||
pvt.log->base = callocMustSucceed(1, pvt.bufSize, "Failed to allocate memory for errorlog buffer");
|
||||
free(pvt.print->base);
|
||||
pvt.print->base = callocMustSucceed(1, pvt.bufSize, "Failed to allocate memory for errorlog buffer");
|
||||
|
||||
epicsMutexUnlock(pvt.msgQueueLock);
|
||||
epicsMutexUnlock(pvt.bufSizeLock);
|
||||
}
|
||||
|
||||
@@ -224,6 +224,15 @@ LIBCOM_API int errlogInit(int bufsize);
|
||||
*/
|
||||
LIBCOM_API int errlogInit2(int bufsize, int maxMsgSize);
|
||||
|
||||
/**
|
||||
* errlogBufResize can be used to reinitialize the error logging system with a larger buffer and maximum message size.
|
||||
* The default buffer size is 1280 bytes, and the default maximum message size is 256.
|
||||
*
|
||||
* \param bufsize The desired buffer size
|
||||
* \param maxMsgSize The desired max message size
|
||||
*/
|
||||
LIBCOM_API int errlogBufResize(int bufsize, int maxMsgSize);
|
||||
|
||||
/** Wakes up the errlog task and then waits until all messages are flushed from the queue. */
|
||||
LIBCOM_API void errlogFlush(void);
|
||||
|
||||
|
||||
@@ -304,7 +304,7 @@ static const iocshFuncDef errlogBufResizeFuncDef = {
|
||||
};
|
||||
static void errlogBufResizeCallFunc(const iocshArgBuf *args)
|
||||
{
|
||||
errlogBufResize(args[0].ival, args[1].ival);
|
||||
iocshSetError(errlogBufResize(args[0].ival, args[1].ival));
|
||||
}
|
||||
|
||||
/* errlogShow */
|
||||
|
||||
Reference in new issue
Block a user