Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Aug 2001 12:17:58 +0200 (CEST)
From:      dirk.meyer@dinoex.sub.org
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/29363: [PATCH] newsyslog can support time as extension
Message-ID:  <200108011017.f71AHwF66500@home.dinoex.sub.org>

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

>Number:         29363
>Category:       bin
>Synopsis:       [PATCH] newsyslog can support time as extension
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Aug 01 03:20:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Dirk Meyer
>Release:        FreeBSD 4.3-STABLE i386
>Organization:
privat
>Environment:

System: FreeBSD 4.3-STABLE: Fri Jul 20 22:04:45 CEST 2001 i386

Description:

-------

 If I recall, I suggested that this support optional renaming of files with
 a pre-defined text string of %x variables, which would expand into defined
 values, like the date(1) command:

          messages.072501-01:10.gz

 You wouldn't necessarily need to modify the newsyslog.conf file, but could
 implement this as a commandline switch, which would control this globally
 (not very flexible, but less invasive).  So, one could modify the crontab
 to do:

 0       *       *       *       *       root    newsyslog -T %m%d%y-%H-%M

-------

>Description:
>How-To-Repeat:

>Fix:

Diff for 4.3 Current

Index: newsyslog.8
===================================================================
RCS file: /home/ncvs/src/usr.sbin/newsyslog/newsyslog.8,v
retrieving revision 1.32
diff -u -r1.32 newsyslog.8
--- newsyslog.8	2001/07/30 15:17:17	1.32
+++ newsyslog.8	2001/08/01 10:09:09
@@ -28,6 +28,7 @@
 .Op Fl Fnrv
 .Op Fl f Ar config_file
 .Op Fl a Ar directory
+.Op Fl T Ar timeformat
 .Op Ar
 .Sh DESCRIPTION
 .Nm Newsyslog
@@ -354,6 +355,14 @@
 to trim the logs, even if the trim conditions have not been met.  This
 option is useful for diagnosing system problems by providing you with
 fresh logs that contain only the problems.
+.It Fl T
+Time based extension
+.Nm
+to rename all logs that get trimmed into with an extension based on the
+argument given by this option. This option can be any strfime(3) string.
+ This function is intended for permantely storing of logfiles.  If the
+patten results to an already existing file, operations breaks without
+cleanup, leaving stale logs in place, that might be ovewritten.
 .El
 .Pp
 If additional command line arguments are given,
Index: newsyslog.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/newsyslog/newsyslog.c,v
retrieving revision 1.37
diff -u -r1.37 newsyslog.c
--- newsyslog.c	2001/07/31 16:25:55	1.37
+++ newsyslog.c	2001/08/01 10:09:12
@@ -90,7 +90,9 @@
 int needroot = 1;		/* Root privs are necessary */
 int noaction = 0;		/* Don't do anything, just show it */
 int force = 0;			/* Force the trim no matter what */
-char *archdirname;		/* Directory path to old logfiles archive */
+int timename = 0;		/* Use time of rotation as suffix */
+const char *archdirname;	/* Directory path to old logfiles archive */
+const char *timearg;		/* Pattern to expand into extension */
 const char *conf = _PATH_CONF;	/* Configuration file to use */
 time_t timenow;
 
@@ -227,7 +229,7 @@
 	if ((p = strchr(hostname, '.'))) {
 		*p = '\0';
 	}
-	while ((c = getopt(argc, argv, "nrvFf:a:t:")) != -1)
+	while ((c = getopt(argc, argv, "nrvFf:a:t:T:")) != -1)
 		switch (c) {
 		case 'n':
 			noaction++;
@@ -248,6 +250,10 @@
 		case 'F':
 			force++;
 			break;
+		case 'T':
+			timename++;
+			timearg = optarg;
+			break;
 		default:
 			usage();
 		}
@@ -516,6 +522,7 @@
 	int notified, need_notification, fd, _numdays;
 	struct stat st;
 	pid_t pid;
+	time_t now;
 
 #ifdef _IBMR2
 	/*
@@ -633,6 +640,16 @@
 		if (noaction)
 			printf("mv %s to %s\n", log, file1);
 		else {
+			/* change file1 to hold the new name */
+			if (timename) {
+				now = time( NULL );
+				(void) strftime(file2, sizeof(file2), timearg, localtime( &now ) );
+				if (archtodir)
+					(void) snprintf(file1, sizeof(file1), "%s/%s.%s", dirpart, namepart, file2);
+				else
+					(void) snprintf(file1, sizeof(file1), "%s.%s", log, file2);
+			}
+
 			if (archtodir)
 				movefile(log, file1, perm, owner_uid,
 				    group_gid);
@@ -683,26 +700,18 @@
 			    "log %s not compressed because daemon not notified",
 			    log);
 		else if (noaction)
-			printf("Compress %s.0\n", log);
+			printf("Compress %s\n", file1);
 		else {
 			if (notified) {
 				if (verbose)
 					printf("small pause to allow daemon to close log\n");
 				sleep(10);
-			}
-			if (archtodir) {
-				(void) snprintf(file1, sizeof(file1), "%s/%s",
-				    dirpart, namepart);
-				if (flags & CE_COMPACT)
-					compress_log(file1);
-				else if (flags & CE_BZCOMPACT)
-					bzcompress_log(file1);
-			} else {
-				if (flags & CE_COMPACT)
-					compress_log(log);
-				else if (flags & CE_BZCOMPACT)
-					bzcompress_log(log);
 			}
+			compress_log(file1);
+			if (flags & CE_COMPACT)
+				compress_log(file1);
+			else if (flags & CE_BZCOMPACT)
+				bzcompress_log(file1);
 		}
 	}
 }
@@ -729,7 +738,7 @@
 	pid_t pid;
 	char tmp[MAXPATHLEN];
 
-	(void) snprintf(tmp, sizeof(tmp), "%s.0", log);
+	(void) snprintf(tmp, sizeof(tmp), "%s", log);
 	pid = fork();
 	if (pid < 0)
 		err(1, "gzip fork");


Diff for 4.3 Stable before BZIP support.

Index: newsyslog/newsyslog.8
===================================================================
RCS file: /home/ncvs/src/usr.sbin/newsyslog/newsyslog.8,v
retrieving revision 1.31
diff -u -r1.31 newsyslog.8
--- newsyslog/newsyslog.8	2001/07/19 15:52:02	1.31
+++ newsyslog/newsyslog.8	2001/07/24 13:49:04
@@ -28,6 +28,7 @@
 .Op Fl Fnrv
 .Op Fl f Ar config_file
 .Op Fl a Ar directory
+.Op Fl T Ar timeformat
 .Op Ar
 .Sh DESCRIPTION
 .Nm Newsyslog
@@ -349,6 +350,14 @@
 to trim the logs, even if the trim conditions have not been met.  This
 option is useful for diagnosing system problems by providing you with
 fresh logs that contain only the problems.
+.It Fl T
+Time based extension
+.Nm
+to rename all logs that get trimmed into with an extension based on the
+argument given by this option. This option can be any strfime(3) string.
+ This function is intended for permantely storing of logfiles.  If the
+patten results to an already existing file, operations breaks without
+cleanup, leaving stale logs in place, that might be ovewritten.
 .El
 .Pp
 If additional command line arguments are given,
Index: newsyslog/newsyslog.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/newsyslog/newsyslog.c,v
retrieving revision 1.31
diff -u -r1.31 newsyslog.c
--- newsyslog/newsyslog.c	2001/07/09 09:24:00	1.31
+++ newsyslog/newsyslog.c	2001/07/24 13:49:07
@@ -86,7 +86,9 @@
 int needroot = 1;		/* Root privs are necessary */
 int noaction = 0;		/* Don't do anything, just show it */
 int force = 0;			/* Force the trim no matter what */
+int timename = 0;		/* Use time of rotation as suffix */
 char *archdirname;		/* Directory path to old logfiles archive */
+char *timearg;			/* Pattern to expand into extension */
 char *conf = _PATH_CONF;	/* Configuration file to use */
 time_t timenow;
 
@@ -214,7 +216,7 @@
 	if ((p = strchr(hostname, '.'))) {
 		*p = '\0';
 	}
-	while ((c = getopt(argc, argv, "nrvFf:a:t:")) != -1)
+	while ((c = getopt(argc, argv, "nrvFf:a:t:T:")) != -1)
 		switch (c) {
 		case 'n':
 			noaction++;
@@ -235,6 +237,10 @@
 		case 'F':
 			force++;
 			break;
+		case 'T':
+			timename++;
+			timearg = optarg;
+			break;
 		default:
 			usage();
 		}
@@ -483,6 +489,7 @@
 	int notified, need_notification, fd, _numdays;
 	struct stat st;
 	pid_t pid;
+	time_t now;
 
 #ifdef _IBMR2
 	/*
@@ -581,6 +588,16 @@
 		if (noaction)
 			printf("mv %s to %s\n", log, file1);
 		else {
+			/* change file1 to hold the new name */
+			if (timename) {
+				now = time( NULL );
+				(void) strftime(file2, sizeof(file2), timearg, localtime( &now ) );
+				if (archtodir)
+					(void) snprintf(file1, sizeof(file1), "%s/%s.%s", dirpart, namepart, file2);
+				else
+					(void) snprintf(file1, sizeof(file1), "%s.%s", log, file2);
+			}
+
 			if (archtodir)
 				movefile(log, file1, perm, owner_uid, group_gid);
 			else
@@ -628,19 +645,14 @@
 		if (need_notification && !notified)
 			warnx("log %s not compressed because daemon not notified", log);
 		else if (noaction)
-			printf("Compress %s.0\n", log);
+			printf("Compress %s\n", file1);
 		else {
 			if (notified) {
 				if (verbose)
 					printf("small pause to allow daemon to close log\n");
 				sleep(10);
-			}
-			if (archtodir) {
-				(void) snprintf(file1, sizeof(file1), "%s/%s", dirpart, namepart);
-				compress_log(file1);
-			} else {
-				compress_log(log);
 			}
+			compress_log(file1);
 		}
 	}
 }
@@ -667,7 +679,7 @@
 	pid_t pid;
 	char tmp[MAXPATHLEN];
 
-	(void) snprintf(tmp, sizeof(tmp), "%s.0", log);
+	(void) snprintf(tmp, sizeof(tmp), "%s", log);
 	pid = fork();
 	if (pid < 0)
 		err(1, "fork");
>Release-Note:
>Audit-Trail:
>Unformatted:

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




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