fix(storage/vfs_console): stop new console opens from overwriting existing fds

This commit is contained in:
Tomáš Rohlínek
2025-03-12 20:06:31 +08:00
committed by Tomas Rohlinek
parent 061ba0c99e
commit c6d24bddf7
4 changed files with 85 additions and 2 deletions
@@ -5,6 +5,7 @@
*/
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "sdkconfig.h"
#include "esp_rom_uart.h"
@@ -49,10 +50,29 @@ static void console_none_print(void)
}
#endif
#if CONFIG_VFS_SUPPORT_IO
static void console_open_close_check(void)
{
printf("Opening /dev/console\n");
int fd = open("/dev/console", O_RDWR);
assert(fd >= 0 && "Could not open file");
const char *msg = "This should be printed to stdout\n";
write(fd, msg, strlen(msg));
printf("Closing /dev/console\n");
close(fd);
printf("This should be printed to stdout\n");
}
#endif // CONFIG_VFS_SUPPORT_IO
void app_main(void)
{
printf("Hello World\n");
#if CONFIG_VFS_SUPPORT_IO
int fd = open("/dev/null", O_RDWR);
assert(fd >= 0 && "Could not open file"); // Standard check
@@ -61,8 +81,14 @@ void app_main(void)
assert(fd > 2 && "Incorrect file descriptor returned, stdin, stdout, stderr were not correctly assigned");
close(fd);
#endif // CONFIG_VFS_SUPPORT_IO
#if CONFIG_ESP_CONSOLE_NONE
console_none_print();
#endif // CONFIG_ESP_CONSOLE_NONE
#if CONFIG_VFS_SUPPORT_IO
console_open_close_check();
#endif // CONFIG_VFS_SUPPORT_IO
}