Skip to content

Commit

Permalink
Fix nasa#373: Correct mutex around log file write
Browse files Browse the repository at this point in the history
The mutex for the log file write during the WriteLogFileCmd
excution was held longer than it should have been.

This lock must *NOT* be held during EVS_SendEvent, as this
will cause deadlock.

This moves the mutex to protect only the area that actually
accesses the log data, and it moves all send event calls
to be AFTER the mutex is released.
  • Loading branch information
jphickey authored and skliper committed Oct 31, 2019
1 parent c3f799a commit bbdf201
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions fsw/cfe-core/src/evs/cfe_evs_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ int32 CFE_EVS_WriteLogDataFileCmd(const CFE_EVS_WriteLogDataFile_t *data)
}
else
{
/* Serialize access to event log control variables */
OS_MutSemTake(CFE_EVS_GlobalData.EVS_SharedDataMutexID);

/* Copy the commanded filename into local buffer to ensure size limitation and to allow for modification */
CFE_SB_MessageStringGet(LogFilename, (const char *)CmdPtr->LogFilename, CFE_PLATFORM_EVS_DEFAULT_LOG_FILE,
OS_MAX_PATH_LEN, sizeof(CmdPtr->LogFilename));
Expand Down Expand Up @@ -198,6 +195,9 @@ int32 CFE_EVS_WriteLogDataFileCmd(const CFE_EVS_WriteLogDataFile_t *data)

if (BytesWritten == sizeof(LogFileHdr))
{
/* Serialize access to event log control variables */
OS_MutSemTake(CFE_EVS_GlobalData.EVS_SharedDataMutexID);

/* Is the log full? -- Doesn't matter if wrap mode is enabled */
if (CFE_EVS_GlobalData.EVS_LogPtr->LogCount == CFE_PLATFORM_EVS_LOG_MAX)
{
Expand Down Expand Up @@ -228,13 +228,12 @@ int32 CFE_EVS_WriteLogDataFileCmd(const CFE_EVS_WriteLogDataFile_t *data)
}
else
{
EVS_SendEvent(CFE_EVS_ERR_WRLOGFILE_EID, CFE_EVS_EventType_ERROR,
"Write Log File Command Error: OS_write = 0x%08X, filename = %s",
(unsigned int)BytesWritten, LogFilename);
break;
}
}

OS_MutSemGive(CFE_EVS_GlobalData.EVS_SharedDataMutexID);

/* Process command handler success result */
if (i == CFE_EVS_GlobalData.EVS_LogPtr->LogCount)
{
Expand All @@ -243,13 +242,17 @@ int32 CFE_EVS_WriteLogDataFileCmd(const CFE_EVS_WriteLogDataFile_t *data)
(int)CFE_EVS_GlobalData.EVS_LogPtr->LogCount, LogFilename);
Result = CFE_SUCCESS;
}
else
{
EVS_SendEvent(CFE_EVS_ERR_WRLOGFILE_EID, CFE_EVS_EventType_ERROR,
"Write Log File Command Error: OS_write = 0x%08X, filename = %s",
(unsigned int)BytesWritten, LogFilename);
}
}

OS_close(LogFileHandle);
}

OS_MutSemGive(CFE_EVS_GlobalData.EVS_SharedDataMutexID);

}

return(Result);
Expand Down

0 comments on commit bbdf201

Please sign in to comment.