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
24FILE_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 */
50
51/** VMware logfile console line buffer */
52static struct {
53 char prefix[4];
56 .prefix = "log ",
57};
58
59/** VMware logfile console ANSI escape sequence handlers */
61 { 0, NULL }
62};
63
64/** VMware logfile line console */
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 */
75
76/**
77 * Print a character to VMware logfile console
78 *
79 * @v character Character to be printed
80 */
81static void vmconsole_putchar ( int character ) {
82 int rc;
83
84 /* Ignore if we are already mid-logging */
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 */
104}
105
106/** VMware logfile console driver */
108 .putchar = vmconsole_putchar,
109 .disabled = CONSOLE_DISABLED,
110 .usage = CONSOLE_VMWARE,
111};
112
113/**
114 * Initialise VMware logfile console
115 *
116 */
117static 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 */
136struct init_fn vmconsole_init_fn __init_fn ( INIT_CONSOLE ) = {
137 .name = "vmconsole",
138 .initialise = vmconsole_init,
139};
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct golan_eq_context ctx
Definition CIB_PRM.h:0
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
Console configuration.
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define INIT_CONSOLE
Console initialisation.
Definition init.h:31
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
int guestrpc_open(void)
Open GuestRPC channel.
Definition guestrpc.c:67
int guestrpc_command(int channel, const char *command, char *reply, size_t reply_len)
Issue GuestRPC command.
Definition guestrpc.c:242
VMware GuestRPC mechanism.
User interaction.
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition console.h:112
#define __console_driver
Mark a struct console_driver as being part of the console drivers table.
Definition console.h:134
String functions.
#define __init_fn(init_order)
Declare an initialisation functon.
Definition init.h:24
size_t line_putchar(struct line_console *line, int character)
Print a character to a line-based console.
Definition lineconsole.c:44
Line-based console.
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
A handler for an escape sequence.
Definition ansiesc.h:35
A console driver.
Definition console.h:56
An initialisation function.
Definition init.h:15
A line-based console.
Definition lineconsole.h:17
#define VMCONSOLE_BUFSIZE
VMware logfile console buffer size.
Definition vmconsole.c:40
static int vmconsole_channel
VMware logfile console GuestRPC channel.
Definition vmconsole.c:49
static struct @135202313311362371141165321075034132101064071142 vmconsole_buffer
VMware logfile console line buffer.
static struct ansiesc_handler vmconsole_handlers[]
VMware logfile console ANSI escape sequence handlers.
Definition vmconsole.c:60
static struct line_console vmconsole_line
VMware logfile line console.
Definition vmconsole.c:65
char prefix[4]
Definition vmconsole.c:53
static void vmconsole_putchar(int character)
Print a character to VMware logfile console.
Definition vmconsole.c:81
static int vmconsole_entered
VMware logfile console recursion marker.
Definition vmconsole.c:74
static void vmconsole_init(void)
Initialise VMware logfile console.
Definition vmconsole.c:117
char message[VMCONSOLE_BUFSIZE]
Definition vmconsole.c:54
#define CONSOLE_VMWARE
Definition vmconsole.c:45