Skip to content

Commit

Permalink
Fix nasa#1102, Correct return value bug in VxWorks `OS_ShellOutputToF…
Browse files Browse the repository at this point in the history
…ile_Impl`
  • Loading branch information
thnkslprpt committed May 18, 2023
1 parent 5036fed commit 3115335
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 18 additions & 14 deletions src/os/vxworks/src/os-impl-shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
*-----------------------------------------------------------------*/
int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd)
{
int32 ReturnCode = OS_ERROR;
int32 ReturnCode;
int32 Result;
osal_id_t fdCmd;
OS_impl_file_internal_record_t *out_impl;
Expand All @@ -64,15 +64,17 @@ int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd)
snprintf(localShellName, sizeof(localShellName), "shll_%08lx", OS_ObjectIdToInteger(OS_TaskGetId()));

/* Create a file to write the command to (or write over the old one) */
Result =
ReturnCode =
OS_OpenCreate(&fdCmd, OS_SHELL_CMD_INPUT_FILE_NAME, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE);

if (Result < OS_SUCCESS)
if (ReturnCode < OS_SUCCESS)
{
return Result;
return ReturnCode;
}

if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_STREAM, fdCmd, &cmd_token) == OS_SUCCESS)
ReturnCode = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_STREAM, fdCmd, &cmd_token);

if (ReturnCode == OS_SUCCESS)
{
out_impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token);
cmd_impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, cmd_token);
Expand All @@ -84,17 +86,19 @@ int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd)
/* Create a shell task the will run the command in the file, push output to OS_fd */
Result = shellGenericInit("INTERPRETER=Cmd", 0, localShellName, NULL, false, false, cmd_impl->fd, out_impl->fd,
out_impl->fd);
}

if (Result == OK)
{
/* Wait for the command to terminate */
do
if (Result == OK)
{
taskDelay(sysClkRateGet());
} while (taskNameToId(localShellName) != ((TASK_ID)ERROR));

ReturnCode = OS_SUCCESS;
/* Wait for the command to terminate */
do
{
taskDelay(sysClkRateGet());
} while (taskNameToId(localShellName) != ((TASK_ID)ERROR));
}
else
{
ReturnCode = OS_ERROR;
}
}

/* Close the file descriptor */
Expand Down
2 changes: 1 addition & 1 deletion src/unit-test-coverage/vxworks/src/coveragetest-shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void Test_OS_ShellOutputToFile_Impl(void)
/* ID failure */
UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OCS_taskNameToId), -1);
OSAPI_TEST_FUNCTION_RC(OS_ShellOutputToFile_Impl(&token, "TestCmd"), OS_SUCCESS);
OSAPI_TEST_FUNCTION_RC(OS_ShellOutputToFile_Impl(&token, "TestCmd"), OS_ERROR);
}

/* ------------------- End of test cases --------------------------------------*/
Expand Down

0 comments on commit 3115335

Please sign in to comment.