|
@@ -25,6 +25,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
25
|
25
|
*/
|
26
|
26
|
|
27
|
27
|
#include <stdint.h>
|
|
28
|
+#include <stdlib.h>
|
28
|
29
|
#include <byteswap.h>
|
29
|
30
|
#include <ipxe/xfer.h>
|
30
|
31
|
#include <ipxe/open.h>
|
|
@@ -58,6 +59,41 @@ static struct interface_descriptor syslogger_desc =
|
58
|
59
|
/** The syslog UDP interface */
|
59
|
60
|
static struct interface syslogger = INTF_INIT ( syslogger_desc );
|
60
|
61
|
|
|
62
|
+/******************************************************************************
|
|
63
|
+ *
|
|
64
|
+ * Console driver
|
|
65
|
+ *
|
|
66
|
+ ******************************************************************************
|
|
67
|
+ */
|
|
68
|
+
|
|
69
|
+/** Host name (for log messages) */
|
|
70
|
+static char *syslog_hostname;
|
|
71
|
+
|
|
72
|
+/** Domain name (for log messages) */
|
|
73
|
+static char *syslog_domain;
|
|
74
|
+
|
|
75
|
+/**
|
|
76
|
+ * Transmit formatted syslog message
|
|
77
|
+ *
|
|
78
|
+ * @v xfer Data transfer interface
|
|
79
|
+ * @v severity Severity
|
|
80
|
+ * @v message Message
|
|
81
|
+ * @v terminator Message terminator
|
|
82
|
+ * @ret rc Return status code
|
|
83
|
+ */
|
|
84
|
+int syslog_send ( struct interface *xfer, unsigned int severity,
|
|
85
|
+ const char *message, const char *terminator ) {
|
|
86
|
+
|
|
87
|
+ return xfer_printf ( xfer, "<%d>%s%s%s%sipxe: %s%s",
|
|
88
|
+ SYSLOG_PRIORITY ( SYSLOG_DEFAULT_FACILITY,
|
|
89
|
+ severity ),
|
|
90
|
+ ( syslog_hostname ? syslog_hostname : "" ),
|
|
91
|
+ ( syslog_domain ? "." : "" ),
|
|
92
|
+ ( syslog_domain ? syslog_domain : "" ),
|
|
93
|
+ ( ( syslog_hostname || syslog_domain ) ? " " : ""),
|
|
94
|
+ message, terminator );
|
|
95
|
+}
|
|
96
|
+
|
61
|
97
|
/******************************************************************************
|
62
|
98
|
*
|
63
|
99
|
* Console driver
|
|
@@ -124,10 +160,8 @@ static void syslog_putchar ( int character ) {
|
124
|
160
|
syslog_entered = 1;
|
125
|
161
|
|
126
|
162
|
/* Send log message */
|
127
|
|
- if ( ( rc = xfer_printf ( &syslogger, "<%d>ipxe: %s",
|
128
|
|
- SYSLOG_PRIORITY ( SYSLOG_DEFAULT_FACILITY,
|
129
|
|
- syslog_severity ),
|
130
|
|
- syslog_buffer ) ) != 0 ) {
|
|
163
|
+ if ( ( rc = syslog_send ( &syslogger, syslog_severity,
|
|
164
|
+ syslog_buffer, "" ) ) != 0 ) {
|
131
|
165
|
DBG ( "SYSLOG could not send log message: %s\n",
|
132
|
166
|
strerror ( rc ) );
|
133
|
167
|
}
|
|
@@ -170,6 +204,20 @@ static int apply_syslog_settings ( void ) {
|
170
|
204
|
int len;
|
171
|
205
|
int rc;
|
172
|
206
|
|
|
207
|
+ /* Fetch hostname and domain name */
|
|
208
|
+ free ( syslog_hostname );
|
|
209
|
+ if ( ( len = fetch_string_setting_copy ( NULL, &hostname_setting,
|
|
210
|
+ &syslog_hostname ) ) < 0 ) {
|
|
211
|
+ rc = len;
|
|
212
|
+ DBG ( "SYSLOG could not fetch hostname: %s\n", strerror ( rc ));
|
|
213
|
+ }
|
|
214
|
+ free ( syslog_domain );
|
|
215
|
+ if ( ( len = fetch_string_setting_copy ( NULL, &domain_setting,
|
|
216
|
+ &syslog_domain ) ) < 0 ) {
|
|
217
|
+ rc = len;
|
|
218
|
+ DBG ( "SYSLOG could not fetch domain: %s\n", strerror ( rc ) );
|
|
219
|
+ }
|
|
220
|
+
|
173
|
221
|
/* Fetch log server */
|
174
|
222
|
syslog_console.disabled = 1;
|
175
|
223
|
old_addr.s_addr = sin_logserver->sin_addr.s_addr;
|