Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Jan 2003 21:40:02 -0800 (PST)
From:      dirk.meyer@dinoex.sub.org (Dirk Meyer)
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/29363: [BPATCH] newsyslog can support time as extension
Message-ID:  <200301290540.h0T5e2nk085646@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/29363; it has been noted by GNATS.

From: dirk.meyer@dinoex.sub.org (Dirk Meyer)
To: FreeBSD-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/29363: [BPATCH] newsyslog can support time as
	extension
Date: Wed, 29 Jan 2003 06:29:24 +0100

 Here the merge to CURRENT:
 
 This patch does:
 - Add option T for timeformat
 - reduce warnings using const
 - Fix warnings on non static funtions sob() and son()
 - reduce duplicate code, by using the filename already set
 
 Tested and verified with the arguments:
 $ newsyslog -v -n -T %Y-%m-%d-%H:%M -a /tmp
 $ newsyslog -v -n -T %Y-%m-%d-%H:%M
 $ newsyslog -v -n
 (and without -n) 
 
 kind regards Dirk
 
 - Dirk Meyer, Im Grund 4, 34317 Habichtswald, Germany
 - [dirk.meyer@dinoex.sub.org],[dirk.meyer@guug.de],[dinoex@FreeBSD.org]
 
 Index: newsyslog/newsyslog.8
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/newsyslog/newsyslog.8,v
 retrieving revision 1.38
 diff -u -r1.38 newsyslog.8
 --- newsyslog/newsyslog.8	27 Dec 2002 12:15:38 -0000	1.38
 +++ newsyslog/newsyslog.8	29 Jan 2003 04:04:41 -0000
 @@ -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
  The
 @@ -387,6 +388,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.49
 diff -u -r1.49 newsyslog.c
 --- newsyslog/newsyslog.c	21 Dec 2002 22:27:26 -0000	1.49
 +++ newsyslog/newsyslog.c	29 Jan 2003 04:04:45 -0000
 @@ -95,7 +95,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;
  
 @@ -248,7 +250,7 @@
  	if ((p = strchr(hostname, '.'))) {
  		*p = '\0';
  	}
 -	while ((c = getopt(argc, argv, "nrvFf:a:")) != -1)
 +	while ((c = getopt(argc, argv, "nrvFf:a:T:")) != -1)
  		switch (c) {
  		case 'n':
  			noaction++;
 @@ -269,6 +271,10 @@
  		case 'F':
  			force++;
  			break;
 +		case 'T':
 +			timename++;
 +			timearg = optarg;
 +			break;
  		default:
  			usage();
  		}
 @@ -554,6 +560,7 @@
  	int notified, need_notification, fd, _numdays;
  	struct stat st;
  	pid_t pid;
 +	time_t now;
  
  #ifdef _IBMR2
  	/*
 @@ -668,6 +675,18 @@
  		else
  			(void) unlink(log);
  	} else {
 +		if (timename) {
 +			/* change file1 to hold the new name */
 +			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 (noaction)
  			printf("mv %s to %s\n", log, file1);
  		else {
 @@ -729,30 +748,19 @@
  			    "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,
 -					    flags & CE_COMPACTWAIT);
 -				else if (flags & CE_BZCOMPACT)
 -					bzcompress_log(file1,
 -					    flags & CE_COMPACTWAIT);
 -			} else {
 -				if (flags & CE_COMPACT)
 -					compress_log(log,
 -					    flags & CE_COMPACTWAIT);
 -				else if (flags & CE_BZCOMPACT)
 -					bzcompress_log(log,
 -					    flags & CE_COMPACTWAIT);
 -			}
 +			if (flags & CE_COMPACT)
 +				compress_log(file1,
 +				    flags & CE_COMPACTWAIT);
 +			else if (flags & CE_BZCOMPACT)
 +				bzcompress_log(file1,
 +				    flags & CE_COMPACTWAIT);
  		}
  	}
  }
 @@ -781,7 +789,7 @@
  
  	while (dowait && (wait(NULL) > 0 || errno == EINTR))
  		;
 -	(void) snprintf(tmp, sizeof(tmp), "%s.0", log);
 +	(void) snprintf(tmp, sizeof(tmp), "%s", log);
  	pid = fork();
  	if (pid < 0)
  		err(1, "gzip fork");
 @@ -800,7 +808,7 @@
  
  	while (dowait && (wait(NULL) > 0 || errno == EINTR))
  		;
 -	snprintf(tmp, sizeof(tmp), "%s.0", log);
 +	snprintf(tmp, sizeof(tmp), "%s", log);
  	pid = fork();
  	if (pid < 0)
  		err(1, "bzip2 fork");
 @@ -888,7 +896,7 @@
  }
  
  /* Skip Over Blanks */
 -char *
 +static char *
  sob(char *p)
  {
  	while (p && *p && isspace(*p))
 @@ -897,7 +905,7 @@
  }
  
  /* Skip Over Non-Blanks */
 -char *
 +static char *
  son(char *p)
  {
  	while (p && *p && !isspace(*p))

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?200301290540.h0T5e2nk085646>