diff --git a/src/os/posix/src/os-impl-shell.c b/src/os/posix/src/os-impl-shell.c index 445ae4d38..18b2f5996 100644 --- a/src/os/posix/src/os-impl-shell.c +++ b/src/os/posix/src/os-impl-shell.c @@ -37,6 +37,7 @@ #include "os-posix.h" #include "os-impl-io.h" +#include "os-shared-file.h" #include "os-shared-shell.h" #include "os-shared-idmap.h" @@ -60,7 +61,6 @@ int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd) { pid_t cpid; - uint32 local_id; int wstat; const char * shell = getenv("SHELL"); OS_impl_file_internal_record_t *impl; @@ -86,13 +86,7 @@ int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd) dup2(impl->fd, STDERR_FILENO); /* close all _other_ filehandles */ - for (local_id = 0; local_id < OS_MAX_NUM_OPEN_FILES; ++local_id) - { - if (OS_global_stream_table[local_id].active_id != 0) - { - close(OS_impl_filehandle_table[local_id].fd); - } - } + OS_CloseAllFiles(); execl(shell, "sh", "-c", Cmd, NULL); /* does not return if successful */ exit(EXIT_FAILURE); diff --git a/src/os/rtems/CMakeLists.txt b/src/os/rtems/CMakeLists.txt index 812ccaf6a..70d9c5947 100644 --- a/src/os/rtems/CMakeLists.txt +++ b/src/os/rtems/CMakeLists.txt @@ -36,15 +36,10 @@ set(RTEMS_IMPL_SRCLIST ../portable/os-impl-posix-dirs.c ) -if (OSAL_CONFIG_INCLUDE_SHELL) - list(APPEND RTEMS_IMPL_SRCLIST - src/os-impl-shell.c - ) -else () - list(APPEND RTEMS_IMPL_SRCLIST - ../portable/os-impl-no-shell.c - ) -endif () +# Currently the "shell output to file" for RTEMS is not implemented +list(APPEND RTEMS_IMPL_SRCLIST + ../portable/os-impl-no-shell.c +) # If some form of module loading is configured, # then build the module loader diff --git a/src/os/rtems/src/os-impl-shell.c b/src/os/rtems/src/os-impl-shell.c deleted file mode 100644 index 7e2f775fb..000000000 --- a/src/os/rtems/src/os-impl-shell.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file os-impl-shell.c - * \ingroup rtems - * \author joseph.p.hickey@nasa.gov - * - */ - -/**************************************************************************************** - INCLUDE FILES - ***************************************************************************************/ - -#include "os-rtems.h" -#include "os-impl-files.h" -#include "os-shared-shell.h" - -/**************************************************************************************** - DEFINES - ***************************************************************************************/ - -#define OS_REDIRECTSTRSIZE 15 - -/**************************************************************************************** - IMPLEMENTATION-SPECIFIC ROUTINES - These are specific to this particular operating system - ****************************************************************************************/ - -/*---------------------------------------------------------------- - * - * Function: OS_ShellOutputToFile_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) -{ - /* - ** this is a #define to avoid a 'variable length array' warning - ** 15 is for the size of the redirection string that is added - ** to the command - */ - char LocalCmd[OS_MAX_CMD_LEN + OS_REDIRECTSTRSIZE]; - int32 Result; - - strncpy(LocalCmd, Cmd, OS_MAX_CMD_LEN + OS_REDIRECTSTRSIZE); - - /* Make sure that we are able to access this file */ - fchmod(OS_impl_filehandle_table[file_id].fd, 0666); - - /* - ** add in the extra chars necessary to perform the redirection - ** 1 for stdout and 2 for stderr. they are redirected to the - ** file descriptor passed in - */ - snprintf(LocalCmd, sizeof(LocalCmd), "%s 1>&%d 2>&%d", Cmd, OS_impl_filehandle_table[file_id].fd, - OS_impl_filehandle_table[file_id].fd); - - Result = system(LocalCmd); - - if (Result != 0) - { - return OS_ERROR; - } - return OS_SUCCESS; -} /* end OS_ShellOutputToFile_Impl */