Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1102, Correct return value bug in VxWorks OS_ShellOutputToFile_Impl #1390

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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