You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vmconsole.c 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. /** @file
  21. *
  22. * VMware logfile console
  23. *
  24. */
  25. #include <string.h>
  26. #include <ipxe/console.h>
  27. #include <ipxe/lineconsole.h>
  28. #include <ipxe/init.h>
  29. #include <ipxe/guestrpc.h>
  30. #include <config/console.h>
  31. /** VMware logfile console buffer size */
  32. #define VMCONSOLE_BUFSIZE 128
  33. /* Set default console usage if applicable */
  34. #if ! ( defined ( CONSOLE_VMWARE ) && CONSOLE_EXPLICIT ( CONSOLE_VMWARE ) )
  35. #undef CONSOLE_VMWARE
  36. #define CONSOLE_VMWARE ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_TUI )
  37. #endif
  38. /** VMware logfile console GuestRPC channel */
  39. static int vmconsole_channel;
  40. /** VMware logfile console line buffer */
  41. static struct {
  42. char prefix[4];
  43. char message[VMCONSOLE_BUFSIZE];
  44. } vmconsole_buffer = {
  45. .prefix = "log ",
  46. };
  47. /** VMware logfile console ANSI escape sequence handlers */
  48. static struct ansiesc_handler vmconsole_handlers[] = {
  49. { 0, NULL }
  50. };
  51. /** VMware logfile line console */
  52. static struct line_console vmconsole_line = {
  53. .buffer = vmconsole_buffer.message,
  54. .len = sizeof ( vmconsole_buffer.message ),
  55. .ctx = {
  56. .handlers = vmconsole_handlers,
  57. },
  58. };
  59. /** VMware logfile console recursion marker */
  60. static int vmconsole_entered;
  61. /**
  62. * Print a character to VMware logfile console
  63. *
  64. * @v character Character to be printed
  65. */
  66. static void vmconsole_putchar ( int character ) {
  67. int rc;
  68. /* Ignore if we are already mid-logging */
  69. if ( vmconsole_entered )
  70. return;
  71. /* Fill line buffer */
  72. if ( line_putchar ( &vmconsole_line, character ) == 0 )
  73. return;
  74. /* Guard against re-entry */
  75. vmconsole_entered = 1;
  76. /* Send log message */
  77. if ( ( rc = guestrpc_command ( vmconsole_channel,
  78. vmconsole_buffer.prefix, NULL, 0 ) ) <0){
  79. DBG ( "VMware console could not send log message: %s\n",
  80. strerror ( rc ) );
  81. }
  82. /* Clear re-entry flag */
  83. vmconsole_entered = 0;
  84. }
  85. /** VMware logfile console driver */
  86. struct console_driver vmconsole __console_driver = {
  87. .putchar = vmconsole_putchar,
  88. .disabled = 1,
  89. .usage = CONSOLE_VMWARE,
  90. };
  91. /**
  92. * Initialise VMware logfile console
  93. *
  94. */
  95. static void vmconsole_init ( void ) {
  96. int rc;
  97. /* Attempt to open console */
  98. vmconsole_channel = guestrpc_open();
  99. if ( vmconsole_channel < 0 ) {
  100. rc = vmconsole_channel;
  101. DBG ( "VMware console could not be initialised: %s\n",
  102. strerror ( rc ) );
  103. return;
  104. }
  105. /* Mark console as available */
  106. vmconsole.disabled = 0;
  107. }
  108. /**
  109. * VMware logfile console initialisation function
  110. */
  111. struct init_fn vmconsole_init_fn __init_fn ( INIT_CONSOLE ) = {
  112. .initialise = vmconsole_init,
  113. };