Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Sep 2001 15:09:40 -0700 (PDT)
From:      Todd Wagner <toddwagn@yahoo.com>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/30654: Added ability for newsyslog to archive logs with a timestamp.
Message-ID:  <20010918220940.59020.qmail@web10903.mail.yahoo.com>

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

>Number:         30654
>Category:       bin
>Synopsis:       Added ability for newsyslog to archive logs
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 18 15:10:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Todd Wagner
>Release:        FreeBSD 4.4-RELEASE i386
>Organization:
self
>Environment:
System: FreeBSD cims-la1-01.catt.exodus.net
4.4-RELEASE FreeBSD 
4.4-RELEASE #0: Mon Sep 17 23:25:16 GMT 2001 
root@cims-la1-01.catt.exodus.net:/usr/obj/usr/src/sys/CIMS-SMP
i386


	
>Description:
	Added the ability for newsyslog to archive logs with
a timestamp, in 
addition to the normal log rotation.  
	In addition, the number of log files to maintain
(numlogs) was not 
checked and caused newsyslog to hang when it was set
to a negative value 
in /etc/newsyslog.conf.  The included patch now checks
this value.
	The man page was also updated to describe the new
functionality.
>How-To-Repeat:
	Set the number of log files to maintain to a negative
value in 
/etc/newsyslog.conf and run newsyslog.  It will not
complete.
>Fix:


*** newsyslog.c.orig	Mon Sep 17 22:20:06 2001
--- newsyslog.c	Tue Sep 18 20:26:53 2001
***************
*** 351,357 ****
  		if (!*parse)
  			errx(1, "malformed line (missing fields):\n%s",
errline);
  		*parse = '\0';
! 		if (!sscanf(q, "%d", &working->numlogs))
  			errx(1, "error in config file; bad number:\n%s",
  			    errline);
  
--- 351,357 ----
  		if (!*parse)
  			errx(1, "malformed line (missing fields):\n%s",
errline);
  		*parse = '\0';
! 		if (!sscanf(q, "%d", &working->numlogs) ||
working->numlogs < -1)
  			errx(1, "error in config file; bad number:\n%s",
  			    errline);
  
***************
*** 480,488 ****
--- 480,491 ----
  	char dirpart[MAXPATHLEN], namepart[MAXPATHLEN];
  	char file1[MAXPATHLEN], file2[MAXPATHLEN];
  	char zfile1[MAXPATHLEN], zfile2[MAXPATHLEN];
+ 	char tmp[MAXPATHLEN];
+ 	char logdate[BUFSIZ];
  	int notified, need_notification, fd, _numdays;
  	struct stat st;
  	pid_t pid;
+ 	time_t logtime;
  
  #ifdef _IBMR2
  	/*
***************
*** 493,498 ****
--- 496,504 ----
  	if (owner_uid == -1)
  		owner_uid = geteuid();
  #endif
+ 	/* build date extension */
+ 	logtime = time(NULL);
+ 	(void) strftime(logdate, BUFSIZ-1, "%Y%m%d%H%M%S", 
localtime(&logtime));
  
  	if (archtodir) {
  		char *p;
***************
*** 520,534 ****
  		else
  			strlcpy(namepart, p + 1, sizeof(namepart));
  
! 		/* name of oldest log */
! 		(void) snprintf(file1, sizeof(file1), "%s/%s.%d",
dirpart, 
namepart, numdays);
  		(void) snprintf(zfile1, sizeof(zfile1), "%s%s",
file1,
  		    COMPRESS_POSTFIX);
  	} else {
! 		/* name of oldest log */
! 		(void) snprintf(file1, sizeof(file1), "%s.%d",
log, numdays);
  		(void) snprintf(zfile1, sizeof(zfile1), "%s%s",
file1,
  		    COMPRESS_POSTFIX);
  	}
  
  	if (noaction) {
--- 526,553 ----
  		else
  			strlcpy(namepart, p + 1, sizeof(namepart));
  
! 		if (numdays > -1) {
! 			/* name of oldest log */
! 			(void) snprintf(file1, sizeof(file1), "%s/%s.%d",
dirpart, 
namepart, numdays);
! 		} else {
! 			/* name of dated log */
! 			(void) snprintf(file1, sizeof(file1), "%s/%s.%s",
dirpart, 
namepart, logdate);
! 		}
! 		/* name of compressed log */
  		(void) snprintf(zfile1, sizeof(zfile1), "%s%s",
file1,
  		    COMPRESS_POSTFIX);
+ 
  	} else {
! 		if (numdays > -1) {
! 			/* name of oldest log */
! 			(void) snprintf(file1, sizeof(file1), "%s/%s.%d",
dirpart, 
namepart, numdays);
! 		} else {
! 			/* name of dated log */
! 			(void) snprintf(file1, sizeof(file1), "%s.%s",
log, logdate);
! 		}
  		(void) snprintf(zfile1, sizeof(zfile1), "%s%s",
file1,
  		    COMPRESS_POSTFIX);
+ 
  	}
  
  	if (noaction) {
***************
*** 541,547 ****
  
  	/* Move down log files */
  	_numdays = numdays;	/* preserve */
! 	while (numdays--) {
  
  		(void) strlcpy(file2, file1, sizeof(file2));
  
--- 560,566 ----
  
  	/* Move down log files */
  	_numdays = numdays;	/* preserve */
! 	while (--numdays > 0) {
  
  		(void) strlcpy(file2, file1, sizeof(file2));
  
***************
*** 628,634 ****
  		if (need_notification && !notified)
  			warnx("log %s not compressed because daemon not
notified", log);
  		else if (noaction)
! 			printf("Compress %s.0\n", log);
  		else {
  			if (notified) {
  				if (verbose)
--- 647,656 ----
  		if (need_notification && !notified)
  			warnx("log %s not compressed because daemon not
notified", log);
  		else if (noaction)
! 			if (numdays > -1)
! 				printf("Compress %s.0\n", log);
! 			else
! 				printf("Compress %s.%s\n", log, logdate);
  		else {
  			if (notified) {
  				if (verbose)
***************
*** 636,645 ****
  				sleep(10);
  			}
  			if (archtodir) {
! 				(void) snprintf(file1, sizeof(file1), "%s/%s",
dirpart, 
namepart);
  				compress_log(file1);
  			} else {
! 				compress_log(log);
  			}
  		}
  	}
--- 658,671 ----
  				sleep(10);
  			}
  			if (archtodir) {
! 				/* (void) snprintf(file1, sizeof(file1),
"%s/%s", dirpart, 
namepart); */
  				compress_log(file1);
  			} else {
! 				if (numdays > 0)
! 					(void) snprintf(tmp, sizeof(tmp), "%s.0", log);
! 				else
! 					(void) snprintf(tmp, sizeof(tmp), "%s.%s", log,
logdate);
! 				compress_log(tmp);
  			}
  		}
  	}
***************
*** 665,678 ****
  compress_log(char *log)
  {
  	pid_t pid;
- 	char tmp[MAXPATHLEN];
  
- 	(void) snprintf(tmp, sizeof(tmp), "%s.0", log);
  	pid = fork();
  	if (pid < 0)
  		err(1, "fork");
  	else if (!pid) {
! 		(void) execl(_PATH_GZIP, _PATH_GZIP, "-f", tmp,
0);
  		err(1, _PATH_GZIP);
  	}
  }
--- 691,702 ----
  compress_log(char *log)
  {
  	pid_t pid;
  
  	pid = fork();
  	if (pid < 0)
  		err(1, "fork");
  	else if (!pid) {
! 		(void) execl(_PATH_GZIP, _PATH_GZIP, "-f", log,
0);
  		err(1, _PATH_GZIP);
  	}
  }


*** newsyslog.8.orig	Mon Sep 17 22:20:06 2001
--- newsyslog.8	Tue Sep 18 21:29:42 2001
***************
*** 99,105 ****
  Specify the mode of the log file and archives.
  .It Ar count
  Specify the number of archive files to be kept
! besides the log file itself.
  .It Ar size
  When the size of the log file reaches
  .Ar size
--- 99,105 ----
  Specify the mode of the log file and archives.
  .It Ar count
  Specify the number of archive files to be kept
! besides the log file itself.  If '-1' is specified,
then the file 
will be archived with a timestamp appended, instead of
the rotation 
number, and all archived files will be retained.  For
example, 'my.log' would 
be archived as 'my.log.YYYYMMDDHHMMSS'.
  .It Ar size
  When the size of the log file reaches
  .Ar size

__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/
>Release-Note:
>Audit-Trail:
>Unformatted:
 with a 
 timestamp.

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?20010918220940.59020.qmail>