]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[syslog] Include hostname within syslog messages where possible
authorMichael Brown <mcb30@ipxe.org>
Wed, 20 Jun 2012 13:39:33 +0000 (14:39 +0100)
committerMichael Brown <mcb30@ipxe.org>
Wed, 20 Jun 2012 13:59:06 +0000 (14:59 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/syslog.h
src/net/tcp/syslogs.c
src/net/udp/syslog.c

index 035ca67000089f478ee78eee8f4eb269d38f307a..131692654ead023fadeb0f5b4b169d4ffcd51e9a 100644 (file)
@@ -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 */
index e7480e56a551827127d377f2e601596f7650fbb4..854e21524e3da0ea0c46e6d1f1fc1153d7638f54 100644 (file)
@@ -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 ) );
        }
index 4a2653148dbe1efd5b602d7f2c7fe75ba7b1af7a..9e55d211ba4e839ca9c3716d80914377626df23c 100644 (file)
@@ -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>
@@ -58,6 +59,41 @@ static struct interface_descriptor syslogger_desc =
 /** The syslog UDP interface */
 static struct interface syslogger = INTF_INIT ( syslogger_desc );
 
+/******************************************************************************
+ *
+ * Console driver
+ *
+ ******************************************************************************
+ */
+
+/** 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
@@ -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;