diff --git a/usr.sbin/sysinstall/install.cfg b/usr.sbin/sysinstall/install.cfg index ad53f8e0e7a8..4de2962f8f49 100644 --- a/usr.sbin/sysinstall/install.cfg +++ b/usr.sbin/sysinstall/install.cfg @@ -17,6 +17,9 @@ ipaddr=204.216.27.230 netmask=255.255.255.240 ################################ +# Log to a remote syslogd server +syslogdServer=10.0.1.1 + ################################ # Which installation device to use - ftp is pointed directly at my local # machine and the installation device is my WD8013 ethernet interface. diff --git a/usr.sbin/sysinstall/msg.c b/usr.sbin/sysinstall/msg.c index 4625ce2f7752..f11c72b17fc3 100644 --- a/usr.sbin/sysinstall/msg.c +++ b/usr.sbin/sysinstall/msg.c @@ -34,10 +34,18 @@ * */ -#include "sysinstall.h" -#include #include #include +#include +#include + +#include +#include + +#include +#include + +#include "sysinstall.h" Boolean isDebug(void) @@ -47,6 +55,50 @@ isDebug(void) return (cp = variable_get(VAR_DEBUG)) && strcmp(cp, "no"); } +static Boolean +isNetworkUp(void) +{ + if (!(RunningAsInit) || + (variable_check("NETWORK_CONFIGURED=NO")) != TRUE) { + return TRUE; + } + + return FALSE; +} + +void +msgSyslog(const char *errstr) +{ + struct sockaddr_in server; + struct hostent *hp; + char *host, *line; + int sock; + + if (!isNetworkUp()) + return; + + if (!(host = variable_get(VAR_SYSLOG_SERVER))) + return; + + if (!(hp = gethostbyname2(host, AF_INET))) + return; + + if (!(sock = socket(AF_INET, SOCK_DGRAM, 0))) + return; + + bzero(&server, sizeof(struct sockaddr_in)); + server.sin_family = AF_INET; + server.sin_port = htons(514); + bcopy((char *)hp->h_addr, (char *)&server.sin_addr, hp->h_length); + + asprintf(&line, "<%d>%s", LOG_NOTICE, errstr); + sendto(sock, line, strlen(line), 0, (struct sockaddr *)&server, + sizeof(struct sockaddr_in)); + + close(sock); + free(line); +} + /* Whack up an informational message on the status line, in stand-out */ void msgYap(char *fmt, ...) @@ -99,6 +151,8 @@ msgInfo(char *fmt, ...) attrset(attrs); move(StatusLine, 79); refresh(); + + msgSyslog(errstr); } /* Whack up a warning on the status line */ @@ -120,8 +174,15 @@ msgWarn(char *fmt, ...) mvaddstr(StatusLine, 0, errstr); attrset(attrs); refresh(); - if (OnVTY && isDebug()) - msgDebug("Warning message `%s'\n", errstr); + + /* we don't want this hitting syslog twice */ + if (isDebug()) { + if (OnVTY) + msgDebug("Warning message `%s'\n", errstr); + else + msgSyslog(errstr); + } + } /* Whack up an error on the status line */ @@ -143,8 +204,14 @@ msgError(char *fmt, ...) mvaddstr(StatusLine, 0, errstr); attrset(attrs); refresh(); - if (OnVTY && isDebug()) - msgDebug("Error message `%s'\n", errstr); + + /* we don't want this hitting syslog twice */ + if (isDebug()) { + if (OnVTY) + msgDebug("Error message `%s'\n", errstr); + else + msgSyslog(errstr); + } } /* Whack up a fatal error on the status line */ @@ -174,6 +241,8 @@ msgFatal(char *fmt, ...) refresh(); if (OnVTY) msgDebug("Fatal error `%s'!\n", errstr); + else + msgSyslog(errstr); getch(); systemShutdown(1); } @@ -316,6 +385,9 @@ msgDebug(char *fmt, ...) va_start(args, fmt); vsnprintf((char *)(dbg + strlen(dbg)), FILENAME_MAX, fmt, args); va_end(args); + + msgSyslog(dbg); + write(DebugFD, dbg, strlen(dbg)); } diff --git a/usr.sbin/sysinstall/sysinstall.h b/usr.sbin/sysinstall/sysinstall.h index d3cb10928d8f..767bb32bcd87 100644 --- a/usr.sbin/sysinstall/sysinstall.h +++ b/usr.sbin/sysinstall/sysinstall.h @@ -183,6 +183,7 @@ #define VAR_SERIAL_SPEED "serialSpeed" #define VAR_SLOW_ETHER "slowEthernetCard" #define VAR_SWAP_SIZE "swapSize" +#define VAR_SYSLOG_SERVER "syslogdServer" #define VAR_TRY_DHCP "tryDHCP" #define VAR_TRY_RTSOL "tryRTSOL" #define VAR_UFS_PATH "ufs"