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

Return OS_ERROR if OS_ObjectIdGetById fails in vxworks OS_ShellOutputToFile_Impl #1102

Open
skliper opened this issue Jul 14, 2021 · 1 comment · May be fixed by #1390
Open

Return OS_ERROR if OS_ObjectIdGetById fails in vxworks OS_ShellOutputToFile_Impl #1102

skliper opened this issue Jul 14, 2021 · 1 comment · May be fixed by #1390

Comments

@skliper
Copy link
Contributor

skliper commented Jul 14, 2021

Is your feature request related to a problem? Please describe.
Coverage test highlights somewhat unexpected behavior in the VxWorks OS_ShellOutputToFile_impl where it will still return success if OS_ObjectIdGetById doesn't return OS_SUCCESS. There isn't a real case where OS_ObjectIdGetById would fail that I know of, but the logic is a bit strange.

if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_STREAM, fdCmd, &cmd_token) == 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);
/* copy the command to the file, and then seek back to the beginning of the file */
OS_write(fdCmd, Cmd, OS_strnlen(Cmd, OS_MAX_CMD_LEN));
OS_lseek(fdCmd, 0, OS_SEEK_SET);
/* 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
{
taskDelay(sysClkRateGet());
} while (taskNameToId(localShellName) != ((TASK_ID)ERROR));
ReturnCode = OS_SUCCESS;
}

Describe the solution you'd like
Return OS_ERROR if there is an error.

Describe alternatives you've considered
None

Additional context
None

Requester Info
Jacob Hageman - NASA/GSFC

@jphickey
Copy link
Contributor

jphickey commented Jul 14, 2021

Actually I think the issue/error lies here:

Result =
OS_OpenCreate(&fdCmd, OS_SHELL_CMD_INPUT_FILE_NAME, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE);

It should be using ReturnCode instead of Result to hold the value. The former is the OSAL status code, the latter is the VxWorks status code. It's just coincidence that OK and OS_SUCCESS are the same value (0) so it works and this mismatch was not noticed.

jphickey pushed a commit to jphickey/osal that referenced this issue Aug 10, 2022
thnkslprpt added a commit to thnkslprpt/osal that referenced this issue May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants