iPXE
vmconsole.c
Go to the documentation of this file.
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 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 /** @file
27  *
28  * VMware logfile console
29  *
30  */
31 
32 #include <string.h>
33 #include <ipxe/console.h>
34 #include <ipxe/lineconsole.h>
35 #include <ipxe/init.h>
36 #include <ipxe/guestrpc.h>
37 #include <config/console.h>
38 
39 /** VMware logfile console buffer size */
40 #define VMCONSOLE_BUFSIZE 128
41 
42 /* Set default console usage if applicable */
43 #if ! ( defined ( CONSOLE_VMWARE ) && CONSOLE_EXPLICIT ( CONSOLE_VMWARE ) )
44 #undef CONSOLE_VMWARE
45 #define CONSOLE_VMWARE ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_TUI )
46 #endif
47 
48 /** VMware logfile console GuestRPC channel */
49 static int vmconsole_channel;
50 
51 /** VMware logfile console line buffer */
52 static struct {
53  char prefix[4];
55 } vmconsole_buffer = {
56  .prefix = "log ",
57 };
58 
59 /** VMware logfile console ANSI escape sequence handlers */
61  { 0, NULL }
62 };
63 
64 /** VMware logfile line console */
65 static struct line_console vmconsole_line = {
66  .buffer = vmconsole_buffer.message,
67  .len = sizeof ( vmconsole_buffer.message ),
68  .ctx = {
69  .handlers = vmconsole_handlers,
70  },
71 };
72 
73 /** VMware logfile console recursion marker */
74 static int vmconsole_entered;
75 
76 /**
77  * Print a character to VMware logfile console
78  *
79  * @v character Character to be printed
80  */
81 static void vmconsole_putchar ( int character ) {
82  int rc;
83 
84  /* Ignore if we are already mid-logging */
85  if ( vmconsole_entered )
86  return;
87 
88  /* Fill line buffer */
89  if ( line_putchar ( &vmconsole_line, character ) == 0 )
90  return;
91 
92  /* Guard against re-entry */
94 
95  /* Send log message */
97  vmconsole_buffer.prefix, NULL, 0 ) ) <0){
98  DBG ( "VMware console could not send log message: %s\n",
99  strerror ( rc ) );
100  }
101 
102  /* Clear re-entry flag */
103  vmconsole_entered = 0;
104 }
105 
106 /** VMware logfile console driver */
107 struct console_driver vmconsole __console_driver = {
109  .disabled = CONSOLE_DISABLED,
110  .usage = CONSOLE_VMWARE,
111 };
112 
113 /**
114  * Initialise VMware logfile console
115  *
116  */
117 static void vmconsole_init ( void ) {
118  int rc;
119 
120  /* Attempt to open console */
122  if ( vmconsole_channel < 0 ) {
124  DBG ( "VMware console could not be initialised: %s\n",
125  strerror ( rc ) );
126  return;
127  }
128 
129  /* Mark console as available */
130  vmconsole.disabled = 0;
131 }
132 
133 /**
134  * VMware logfile console initialisation function
135  */
136 struct init_fn vmconsole_init_fn __init_fn ( INIT_CONSOLE ) = {
138 };
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A handler for an escape sequence.
Definition: ansiesc.h:34
void(* initialise)(void)
Definition: init.h:15
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int guestrpc_open(void)
Open GuestRPC channel.
Definition: guestrpc.c:67
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:111
static int vmconsole_channel
VMware logfile console GuestRPC channel.
Definition: vmconsole.c:49
char prefix[4]
Definition: vmconsole.c:53
#define CONSOLE_VMWARE
Definition: vmconsole.c:45
static void vmconsole_putchar(int character)
Print a character to VMware logfile console.
Definition: vmconsole.c:81
A line-based console.
Definition: lineconsole.h:16
struct console_driver vmconsole __console_driver
VMware logfile console driver.
Definition: vmconsole.c:107
Line-based console.
static int vmconsole_entered
VMware logfile console recursion marker.
Definition: vmconsole.c:74
static struct line_console vmconsole_line
VMware logfile line console.
Definition: vmconsole.c:65
size_t line_putchar(struct line_console *line, int character)
Print a character to a line-based console.
Definition: lineconsole.c:43
struct init_fn vmconsole_init_fn __init_fn(INIT_CONSOLE)
VMware logfile console initialisation function.
An initialisation function.
Definition: init.h:14
void(* putchar)(int character)
Write a character to the console.
Definition: console.h:68
VMware GuestRPC mechanism.
static void vmconsole_init(void)
Initialise VMware logfile console.
Definition: vmconsole.c:117
int guestrpc_command(int channel, const char *command, char *reply, size_t reply_len)
Issue GuestRPC command.
Definition: guestrpc.c:242
User interaction.
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static struct @444 vmconsole_buffer
VMware logfile console line buffer.
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
#define VMCONSOLE_BUFSIZE
VMware logfile console buffer size.
Definition: vmconsole.c:40
Console configuration.
#define INIT_CONSOLE
Console initialisation.
Definition: init.h:29
char * buffer
Data buffer.
Definition: lineconsole.h:21
A console driver.
Definition: console.h:55
static struct ansiesc_handler vmconsole_handlers[]
VMware logfile console ANSI escape sequence handlers.
Definition: vmconsole.c:60
char message[VMCONSOLE_BUFSIZE]
Definition: vmconsole.c:54
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
String functions.