Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Jul 2010 22:53:59 +0000 (UTC)
From:      Randi Harper <randi@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r209782 - head/usr.sbin/sysinstall
Message-ID:  <201007072253.o67MrxkL028447@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: randi
Date: Wed Jul  7 22:53:58 2010
New Revision: 209782
URL: http://svn.freebsd.org/changeset/base/209782

Log:
  Add support for remote logging to syslogd via an install.cfg variable.
  
  Approved by:	cperciva (mentor)
  MFC after:	3 weeks

Modified:
  head/usr.sbin/sysinstall/install.cfg
  head/usr.sbin/sysinstall/msg.c
  head/usr.sbin/sysinstall/sysinstall.h

Modified: head/usr.sbin/sysinstall/install.cfg
==============================================================================
--- head/usr.sbin/sysinstall/install.cfg	Wed Jul  7 21:00:17 2010	(r209781)
+++ head/usr.sbin/sysinstall/install.cfg	Wed Jul  7 22:53:58 2010	(r209782)
@@ -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.

Modified: head/usr.sbin/sysinstall/msg.c
==============================================================================
--- head/usr.sbin/sysinstall/msg.c	Wed Jul  7 21:00:17 2010	(r209781)
+++ head/usr.sbin/sysinstall/msg.c	Wed Jul  7 22:53:58 2010	(r209782)
@@ -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));
 }
 

Modified: head/usr.sbin/sysinstall/sysinstall.h
==============================================================================
--- head/usr.sbin/sysinstall/sysinstall.h	Wed Jul  7 21:00:17 2010	(r209781)
+++ head/usr.sbin/sysinstall/sysinstall.h	Wed Jul  7 22:53:58 2010	(r209782)
@@ -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"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007072253.o67MrxkL028447>