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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. /** @file
  25. *
  26. * VMware logfile console
  27. *
  28. */
  29. #include <string.h>
  30. #include <ipxe/console.h>
  31. #include <ipxe/lineconsole.h>
  32. #include <ipxe/init.h>
  33. #include <ipxe/guestrpc.h>
  34. #include <config/console.h>
  35. /** VMware logfile console buffer size */
  36. #define VMCONSOLE_BUFSIZE 128
  37. /* Set default console usage if applicable */
  38. #if ! ( defined ( CONSOLE_VMWARE ) && CONSOLE_EXPLICIT ( CONSOLE_VMWARE ) )
  39. #undef CONSOLE_VMWARE
  40. #define CONSOLE_VMWARE ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_TUI )
  41. #endif
  42. /** VMware logfile console GuestRPC channel */
  43. static int vmconsole_channel;
  44. /** VMware logfile console line buffer */
  45. static struct {
  46. char prefix[4];
  47. char message[VMCONSOLE_BUFSIZE];
  48. } vmconsole_buffer = {
  49. .prefix = "log ",
  50. };
  51. /** VMware logfile console ANSI escape sequence handlers */
  52. static struct ansiesc_handler vmconsole_handlers[] = {
  53. { 0, NULL }
  54. };
  55. /** VMware logfile line console */
  56. static struct line_console vmconsole_line = {
  57. .buffer = vmconsole_buffer.message,
  58. .len = sizeof ( vmconsole_buffer.message ),
  59. .ctx = {
  60. .handlers = vmconsole_handlers,
  61. },
  62. };
  63. /** VMware logfile console recursion marker */
  64. static int vmconsole_entered;
  65. /**
  66. * Print a character to VMware logfile console
  67. *
  68. * @v character Character to be printed
  69. */
  70. static void vmconsole_putchar ( int character ) {
  71. int rc;
  72. /* Ignore if we are already mid-logging */
  73. if ( vmconsole_entered )
  74. return;
  75. /* Fill line buffer */
  76. if ( line_putchar ( &vmconsole_line, character ) == 0 )
  77. return;
  78. /* Guard against re-entry */
  79. vmconsole_entered = 1;
  80. /* Send log message */
  81. if ( ( rc = guestrpc_command ( vmconsole_channel,
  82. vmconsole_buffer.prefix, NULL, 0 ) ) <0){
  83. DBG ( "VMware console could not send log message: %s\n",
  84. strerror ( rc ) );
  85. }
  86. /* Clear re-entry flag */
  87. vmconsole_entered = 0;
  88. }
  89. /** VMware logfile console driver */
  90. struct console_driver vmconsole __console_driver = {
  91. .putchar = vmconsole_putchar,
  92. .disabled = CONSOLE_DISABLED,
  93. .usage = CONSOLE_VMWARE,
  94. };
  95. /**
  96. * Initialise VMware logfile console
  97. *
  98. */
  99. static void vmconsole_init ( void ) {
  100. int rc;
  101. /* Attempt to open console */
  102. vmconsole_channel = guestrpc_open();
  103. if ( vmconsole_channel < 0 ) {
  104. rc = vmconsole_channel;
  105. DBG ( "VMware console could not be initialised: %s\n",
  106. strerror ( rc ) );
  107. return;
  108. }
  109. /* Mark console as available */
  110. vmconsole.disabled = 0;
  111. }
  112. /**
  113. * VMware logfile console initialisation function
  114. */
  115. struct init_fn vmconsole_init_fn __init_fn ( INIT_CONSOLE ) = {
  116. .initialise = vmconsole_init,
  117. };