2
0
mirror of https://github.com/xcat2/xNBA.git synced 2025-02-16 18:48:12 +00:00

[syslog] Include hostname within syslog messages where possible

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2012-06-20 14:39:33 +01:00
parent 7ea6764031
commit cbc54bf559
3 changed files with 57 additions and 8 deletions

View 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 */

View 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 ) );
}

View 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;