0001-early-keep-stdio-files-open.patch 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. From 13ebb50d2789de7bd47cebe57e3f6eba58fdcc7e Mon Sep 17 00:00:00 2001
  2. From: Gabor Juhos <[email protected]>
  3. Date: Fri, 19 Jul 2013 08:43:35 +0200
  4. Subject: [PATCH 1/2] early: keep stdio files open
  5. At the end of the 'early_console' function, the
  6. file descriptor is closed unconditionally. This
  7. 'close' call closes the stdio files if the fd
  8. returned by the 'open(dev/console)' call equals
  9. with any of the STD{IN,OUT,ERR}_FILENO values.
  10. When this happens, all subsequent accesses to
  11. the stdio files will fail and early console
  12. access won't work.
  13. To avoid this, don't close the file descriptor if
  14. that equals with any of the STD*_FILENO values.
  15. Signed-off-by: Gabor Juhos <[email protected]>
  16. ---
  17. Note:
  18. The issue happens if Linux is unable to open the
  19. initial console before calling init. In this case,
  20. the 'open(dev/console)' call in the 'early_console'
  21. function returns with zero.
  22. ---
  23. early.c | 6 +++++-
  24. 1 file changed, 5 insertions(+), 1 deletion(-)
  25. diff --git a/early.c b/early.c
  26. index 27d0929..204623b 100644
  27. --- a/early.c
  28. +++ b/early.c
  29. @@ -65,7 +65,11 @@ static void early_console(const char *dev)
  30. dup2(dd, STDIN_FILENO);
  31. dup2(dd, STDOUT_FILENO);
  32. dup2(dd, STDERR_FILENO);
  33. - close(dd);
  34. +
  35. + if (dd != STDIN_FILENO &&
  36. + dd != STDOUT_FILENO &&
  37. + dd != STDERR_FILENO)
  38. + close(dd);
  39. }
  40. static void early_env(void)
  41. --
  42. 1.7.10