mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-05 15:15:44 +00:00
cpukit: Raise internal error if we cannot open stdin with fileno 0
If someone manages to open a file before rtems_libio_post_driver is run, open() may allocate a file number other than 0 for stdin. This leads to a silent failure of the logic in rtems_libio_post_driver, and confusing behavior because your BSP behaves as if it doesn't have a console. Instead of failing silently, raise an internal error if open() succeeds but gives us an unexpected file number for stdin.
This commit is contained in:
committed by
Chris Johns
parent
897a8d3094
commit
d8ba01ec52
@@ -232,7 +232,8 @@ typedef enum {
|
||||
INTERNAL_ERROR_IDLE_THREAD_CREATE_FAILED = 43,
|
||||
INTERNAL_ERROR_NO_MEMORY_FOR_IDLE_TASK_STORAGE = 44,
|
||||
INTERNAL_ERROR_IDLE_THREAD_STACK_TOO_SMALL = 45,
|
||||
INTERNAL_ERROR_CANNOT_DISABLE_DATA_CACHE = 46
|
||||
INTERNAL_ERROR_CANNOT_DISABLE_DATA_CACHE = 46,
|
||||
INTERNAL_ERROR_LIBIO_STDIN_FD_OPEN_FAILED = 47,
|
||||
} Internal_errors_Core_list;
|
||||
|
||||
typedef CPU_Uint32ptr Internal_errors_t;
|
||||
|
||||
@@ -47,14 +47,22 @@
|
||||
*/
|
||||
void rtems_libio_post_driver(void)
|
||||
{
|
||||
int fd = 0;
|
||||
/*
|
||||
* Attempt to open /dev/console.
|
||||
*/
|
||||
if ( open( CONSOLE_DEVICE_NAME, O_RDONLY, 0 ) != STDIN_FILENO ) {
|
||||
if ( ( fd = open( CONSOLE_DEVICE_NAME, O_RDONLY, 0 ) ) != STDIN_FILENO ) {
|
||||
/*
|
||||
* There may not be a console driver so this is OK.
|
||||
*/
|
||||
return;
|
||||
if ( fd < 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* If open succeeds, but doesn't give us the stdin fileno we expect, bail out...
|
||||
*/
|
||||
_Internal_error( INTERNAL_ERROR_LIBIO_STDIN_FD_OPEN_FAILED );
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -86,7 +86,8 @@ static const char *const internal_error_text[] = {
|
||||
"INTERNAL_ERROR_RTEMS_INIT_TASK_CONSTRUCT_FAILED",
|
||||
"INTERNAL_ERROR_IDLE_THREAD_CREATE_FAILED",
|
||||
"INTERNAL_ERROR_NO_MEMORY_FOR_IDLE_TASK_STORAGE",
|
||||
"INTERNAL_ERROR_IDLE_THREAD_STACK_TOO_SMALL"
|
||||
"INTERNAL_ERROR_IDLE_THREAD_STACK_TOO_SMALL",
|
||||
"INTERNAL_ERROR_LIBIO_STDIN_FD_OPEN_FAILED"
|
||||
};
|
||||
|
||||
const char *rtems_internal_error_text( rtems_fatal_code error )
|
||||
|
||||
Reference in New Issue
Block a user