Skip to content

Commit

Permalink
Fix #1330, better warning about malformed startup line
Browse files Browse the repository at this point in the history
This improves the log message when a line in the startup script is
not formed correctly, such as being too long or having too many
tokens.
  • Loading branch information
jphickey committed Apr 16, 2021
1 parent e80aae9 commit 469d970
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion modules/core_private/ut-stubs/src/ut_osprintf_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const char *UT_OSP_MESSAGES[] = {
/* Warning: System Log full, log entry discarded. */
[UT_OSP_SYSTEM_LOG_FULL] = "Warning: System Log full, log entry discarded.\n",
/* ES Startup: ES Startup File Line is too long: 137 bytes. */
[UT_OSP_FILE_LINE_TOO_LONG] = "ES Startup: ES Startup File Line is too long: %u bytes.\n",
[UT_OSP_FILE_LINE_TOO_LONG] = "ES Startup: **WARNING** File Line %u is malformed: %u bytes, %u tokens.\n",
/* ES Startup: Load Shared Library Init Error. */
[UT_OSP_SHARED_LIBRARY_INIT] = "ES Startup: Load Shared Library Init Error = 0x%08x\n",
/* ES Startup: Error Removing Volatile(RAM) Volume. EC = 0x~ */
Expand Down
19 changes: 14 additions & 5 deletions modules/es/fsw/src/cfe_es_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath)
char ScriptFileName[OS_MAX_PATH_LEN];
const char *TokenList[CFE_ES_STARTSCRIPT_MAX_TOKENS_PER_LINE];
uint32 NumTokens;
uint32 NumLines;
uint32 BuffLen; /* Length of the current buffer */
osal_id_t AppFile = OS_OBJECT_ID_UNDEFINED;
int32 Status;
Expand Down Expand Up @@ -151,6 +152,7 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath)
memset(ES_AppLoadBuffer, 0x0, ES_START_BUFF_SIZE);
BuffLen = 0;
NumTokens = 0;
NumLines = 0;
TokenList[0] = ES_AppLoadBuffer;

/*
Expand Down Expand Up @@ -197,14 +199,18 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath)
}
BuffLen++;

if (NumTokens < (CFE_ES_STARTSCRIPT_MAX_TOKENS_PER_LINE - 1))
++NumTokens;
if (NumTokens < CFE_ES_STARTSCRIPT_MAX_TOKENS_PER_LINE)
{
/*
* NOTE: pointer never deferenced unless "LineTooLong" is false.
*/
++NumTokens;
TokenList[NumTokens] = &ES_AppLoadBuffer[BuffLen];
}
else
{
LineTooLong = true;
}
}
else if (c != ';')
{
Expand All @@ -223,13 +229,16 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath)
}
else
{
++NumLines;

if (LineTooLong == true)
{
/*
** The was too big for the buffer
** The line was not formed correctly
*/
CFE_ES_WriteToSysLog("ES Startup: ES Startup File Line is too long: %u bytes.\n",
(unsigned int)BuffLen);
CFE_ES_WriteToSysLog(
"ES Startup: **WARNING** File Line %u is malformed: %u bytes, %u tokens.\n",
(unsigned int)NumLines, (unsigned int)BuffLen, (unsigned int)NumTokens);
LineTooLong = false;
}
else
Expand Down

0 comments on commit 469d970

Please sign in to comment.