summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brown2012-06-20 15:39:33 +0200
committerMichael Brown2012-06-20 15:59:06 +0200
commitcbc54bf559ce257991a4c87001d7a5c41dbe1869 (patch)
tree0f613faffe79fd02f6146854d0b2bac4653fd80e /src
parent[settings] Move "domain" setting from dns.c to settings.c (diff)
downloadipxe-cbc54bf559ce257991a4c87001d7a5c41dbe1869.tar.gz
ipxe-cbc54bf559ce257991a4c87001d7a5c41dbe1869.tar.xz
ipxe-cbc54bf559ce257991a4c87001d7a5c41dbe1869.zip
[syslog] Include hostname within syslog messages where possible
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
-rw-r--r--src/include/ipxe/syslog.h3
-rw-r--r--src/net/tcp/syslogs.c6
-rw-r--r--src/net/udp/syslog.c56
3 files changed, 57 insertions, 8 deletions
diff --git a/src/include/ipxe/syslog.h b/src/include/ipxe/syslog.h
index 035ca6700..131692654 100644
--- a/src/include/ipxe/syslog.h
+++ b/src/include/ipxe/syslog.h
@@ -35,4 +35,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
/** Syslog priority */
#define SYSLOG_PRIORITY( facility, severity ) ( 8 * (facility) + (severity) )
+extern int syslog_send ( struct interface *xfer, unsigned int severity,
+ const char *message, const char *terminator );
+
#endif /* _IPXE_SYSLOG_H */
diff --git a/src/net/tcp/syslogs.c b/src/net/tcp/syslogs.c
index e7480e56a..854e21524 100644
--- a/src/net/tcp/syslogs.c
+++ b/src/net/tcp/syslogs.c
@@ -162,10 +162,8 @@ static void syslogs_putchar ( int character ) {
syslogs_entered = 1;
/* Send log message */
- if ( ( rc = xfer_printf ( &syslogs, "<%d>ipxe: %s\n",
- SYSLOG_PRIORITY ( SYSLOG_DEFAULT_FACILITY,
- syslogs_severity ),
- syslogs_buffer ) ) != 0 ) {
+ if ( ( rc = syslog_send ( &syslogs, syslogs_severity,
+ syslogs_buffer, "\n" ) ) != 0 ) {
DBG ( "SYSLOGS could not send log message: %s\n",
strerror ( rc ) );
}
diff --git a/src/net/udp/syslog.c b/src/net/udp/syslog.c
index 4a2653148..9e55d211b 100644
--- a/src/net/udp/syslog.c
+++ b/src/net/udp/syslog.c
@@ -25,6 +25,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
*/
#include <stdint.h>
+#include <stdlib.h>
#include <byteswap.h>
#include <ipxe/xfer.h>
#include <ipxe/open.h>
@@ -65,6 +66,41 @@ static struct interface syslogger = INTF_INIT ( syslogger_desc );
******************************************************************************
*/
+/** Host name (for log messages) */
+static char *syslog_hostname;
+
+/** Domain name (for log messages) */
+static char *syslog_domain;
+
+/**
+ * Transmit formatted syslog message
+ *
+ * @v xfer Data transfer interface
+ * @v severity Severity
+ * @v message Message
+ * @v terminator Message terminator
+ * @ret rc Return status code
+ */
+int syslog_send ( struct interface *xfer, unsigned int severity,
+ const char *message, const char *terminator ) {
+
+ return xfer_printf ( xfer, "<%d>%s%s%s%sipxe: %s%s",
+ SYSLOG_PRIORITY ( SYSLOG_DEFAULT_FACILITY,
+ severity ),
+ ( syslog_hostname ? syslog_hostname : "" ),
+ ( syslog_domain ? "." : "" ),
+ ( syslog_domain ? syslog_domain : "" ),
+ ( ( syslog_hostname || syslog_domain ) ? " " : ""),
+ message, terminator );
+}
+
+/******************************************************************************
+ *
+ * Console driver
+ *
+ ******************************************************************************
+ */
+
/** Syslog line buffer */
static char syslog_buffer[SYSLOG_BUFSIZE];
@@ -124,10 +160,8 @@ static void syslog_putchar ( int character ) {
syslog_entered = 1;
/* Send log message */
- if ( ( rc = xfer_printf ( &syslogger, "<%d>ipxe: %s",
- SYSLOG_PRIORITY ( SYSLOG_DEFAULT_FACILITY,
- syslog_severity ),
- syslog_buffer ) ) != 0 ) {
+ if ( ( rc = syslog_send ( &syslogger, syslog_severity,
+ syslog_buffer, "" ) ) != 0 ) {
DBG ( "SYSLOG could not send log message: %s\n",
strerror ( rc ) );
}
@@ -170,6 +204,20 @@ static int apply_syslog_settings ( void ) {
int len;
int rc;
+ /* Fetch hostname and domain name */
+ free ( syslog_hostname );
+ if ( ( len = fetch_string_setting_copy ( NULL, &hostname_setting,
+ &syslog_hostname ) ) < 0 ) {
+ rc = len;
+ DBG ( "SYSLOG could not fetch hostname: %s\n", strerror ( rc ));
+ }
+ free ( syslog_domain );
+ if ( ( len = fetch_string_setting_copy ( NULL, &domain_setting,
+ &syslog_domain ) ) < 0 ) {
+ rc = len;
+ DBG ( "SYSLOG could not fetch domain: %s\n", strerror ( rc ) );
+ }
+
/* Fetch log server */
syslog_console.disabled = 1;
old_addr.s_addr = sin_logserver->sin_addr.s_addr;