summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorrandi <randi@FreeBSD.org>2010-07-07 22:53:58 +0000
committerrandi <randi@FreeBSD.org>2010-07-07 22:53:58 +0000
commit1b6dcbe4ec4f5695b968c17a3cf97501be50ef40 (patch)
tree7dd4e7886f05d6a1b851eb31317512dc02a2214e /usr.sbin
parentd729021fb8c50c0ee2ce0b12345ee671779b99e0 (diff)
downloadFreeBSD-src-1b6dcbe4ec4f5695b968c17a3cf97501be50ef40.zip
FreeBSD-src-1b6dcbe4ec4f5695b968c17a3cf97501be50ef40.tar.gz
Add support for remote logging to syslogd via an install.cfg variable.
Approved by: cperciva (mentor) MFC after: 3 weeks
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/sysinstall/install.cfg3
-rw-r--r--usr.sbin/sysinstall/msg.c84
-rw-r--r--usr.sbin/sysinstall/sysinstall.h1
3 files changed, 82 insertions, 6 deletions
diff --git a/usr.sbin/sysinstall/install.cfg b/usr.sbin/sysinstall/install.cfg
index ad53f8e..4de2962 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 4625ce2..f11c72b 100644
--- a/usr.sbin/sysinstall/msg.c
+++ b/usr.sbin/sysinstall/msg.c
@@ -34,10 +34,18 @@
*
*/
-#include "sysinstall.h"
-#include <stdarg.h>
#include <sys/ioctl.h>
#include <sys/consio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <netdb.h>
+
+#include <stdarg.h>
+#include <syslog.h>
+
+#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 d3cb109..767bb32 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"
OpenPOWER on IntegriCloud