Skip site navigation (1)Skip section navigation (2)
Date:      08 May 2000 21:00:09 +0200
From:      Dag-Erling Smorgrav <des@flood.ping.uio.no>
To:        hackers@freebsd.org
Subject:   newsyslog(8) hack
Message-ID:  <868zxkamva.fsf@md5.follo.net>

next in thread | raw e-mail | index | archive | help
--=-=-=

I've hacked newsyslog(8) to accept a list of log files to process on
the command line (very useful in combination with -F). See attached
patches. I'll commit this in a few days if noone objects.

DES
-- 
Dag-Erling Smorgrav - des@flood.ping.uio.no


--=-=-=
Content-Disposition: attachment; filename=diff
Content-Description: newsyslog(8) patches

Index: newsyslog.8
===================================================================
RCS file: /home/ncvs/src/usr.sbin/newsyslog/newsyslog.8,v
retrieving revision 1.24
diff -u -r1.24 newsyslog.8
--- newsyslog.8	2000/04/04 08:50:01	1.24
+++ newsyslog.8	2000/05/08 18:57:20
@@ -28,6 +28,7 @@
 .Op Fl Fnrv
 .Op Fl f Ar config_file
 .Op Fl a Ar directory
+.Op Ar file ...
 .Sh DESCRIPTION
 .Nm Newsyslog
 is a program that should be scheduled to run periodically by
@@ -355,6 +356,11 @@
 option is useful for diagnosing system problems by providing you with
 fresh logs that contain only the problems.
 .El
+.Pp
+If additional command line arguments are given,
+.Nm
+will only examine log files that match those arguments; otherwise, it
+will examine all files listed in the configuration file.
 .Sh FILES
 .Bl -tag -width /etc/newsyslog.confxxxx -compact
 .It Pa /etc/newsyslog.conf
Index: newsyslog.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/newsyslog/newsyslog.c,v
retrieving revision 1.27
diff -u -r1.27 newsyslog.c
--- newsyslog.c	2000/04/04 08:50:01	1.27
+++ newsyslog.c	2000/05/08 18:52:47
@@ -95,7 +95,7 @@
 char hostname[MAXHOSTNAMELEN + 1];	/* hostname */
 char *daytime;			/* timenow in human readable form */
 
-static struct conf_entry *parse_file();
+static struct conf_entry *parse_file(char **files);
 static char *sob(char *p);
 static char *son(char *p);
 static char *missing_field(char *p, char *errline);
@@ -121,7 +121,7 @@
 	PRS(argc, argv);
 	if (needroot && getuid() && geteuid())
 		errx(1, "must have root privs");
-	p = q = parse_file();
+	p = q = parse_file(argv + optind);
 
 	while (p) {
 		do_entry(p);
@@ -214,7 +214,6 @@
 	if ((p = strchr(hostname, '.'))) {
 		*p = '\0';
 	}
-	optind = 1;		/* Start options parsing */
 	while ((c = getopt(argc, argv, "nrvFf:a:t:")) != -1)
 		switch (c) {
 		case 'n':
@@ -253,11 +252,12 @@
  * process
  */
 static struct conf_entry *
-parse_file(void)
+parse_file(char **files)
 {
 	FILE *f;
 	char line[BUFSIZ], *parse, *q;
 	char *errline, *group;
+	char **p;
 	struct conf_entry *first = NULL;
 	struct conf_entry *working = NULL;
 	struct passwd *pass;
@@ -274,6 +274,21 @@
 		if ((line[0] == '\n') || (line[0] == '#'))
 			continue;
 		errline = strdup(line);
+
+		q = parse = missing_field(sob(line), errline);
+		parse = son(line);
+		if (!*parse)
+			errx(1, "malformed line (missing fields):\n%s", errline);
+		*parse = '\0';
+
+		if (*files) {
+			for (p = files; *p; ++p)
+				if (strcmp(*p, q) == 0)
+					break;
+			if (!*p)
+				continue;
+		}
+
 		if (!first) {
 			working = (struct conf_entry *) malloc(sizeof(struct conf_entry));
 			first = working;
@@ -281,12 +296,6 @@
 			working->next = (struct conf_entry *) malloc(sizeof(struct conf_entry));
 			working = working->next;
 		}
-
-		q = parse = missing_field(sob(line), errline);
-		parse = son(line);
-		if (!*parse)
-			errx(1, "malformed line (missing fields):\n%s", errline);
-		*parse = '\0';
 		working->log = strdup(q);
 
 		q = parse = missing_field(sob(++parse), errline);

--=-=-=--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




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