changeset 954:3ca84f048d8e

PSARC/2004/613 logadm additional options 4824041 logadm(1m) does not use localtime for logfile timestamps (PSARC/2004/613)
author gm149974
date Mon, 21 Nov 2005 02:26:46 -0800
parents 785d08a4a320
children c52aa32ada37
files usr/src/cmd/logadm/kw.c usr/src/cmd/logadm/main.c usr/src/cmd/logadm/tester
diffstat 3 files changed, 55 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/logadm/kw.c	Mon Nov 21 01:08:40 2005 -0800
+++ b/usr/src/cmd/logadm/kw.c	Mon Nov 21 02:26:46 2005 -0800
@@ -20,7 +20,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  *
  * logadm/kw.c -- manage keywords table
@@ -192,7 +192,7 @@
 	boolean_t hasn = B_FALSE;
 	struct fn *kw = fn_new(NULL);
 	char *ptr;
-	struct tm *gmt_tm = gmtime(&Now);
+	struct tm *gmt_tm = localtime(&Now);
 
 	while ((c = fn_getc(src)) != '\0')
 		switch (c) {
--- a/usr/src/cmd/logadm/main.c	Mon Nov 21 01:08:40 2005 -0800
+++ b/usr/src/cmd/logadm/main.c	Mon Nov 21 02:26:46 2005 -0800
@@ -20,7 +20,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  *
  * logadm/main.c -- main routines for logadm
@@ -93,6 +93,7 @@
 	{ "e", OPTTYPE_STRING,	NULL,			OPTF_CLI|OPTF_CONF },
 	{ "f", OPTTYPE_STRING,	NULL,			OPTF_CLI },
 	{ "h", OPTTYPE_BOOLEAN,	NULL,			OPTF_CLI },
+	{ "l", OPTTYPE_BOOLEAN, NULL,			OPTF_CLI },
 	{ "N", OPTTYPE_BOOLEAN,	NULL,			OPTF_CLI|OPTF_CONF },
 	{ "n", OPTTYPE_BOOLEAN,	NULL,			OPTF_CLI },
 	{ "r", OPTTYPE_BOOLEAN,	NULL,			OPTF_CLI },
@@ -125,7 +126,7 @@
  * in the first form.  In other words, it is not allowed to run logadm
  * with any of these options unless at least one logname is also provided.
  */
-#define	OPTIONS_NOT_FIRST_FORM	"eNrwpPsabcgmoRtzACEST"
+#define	OPTIONS_NOT_FIRST_FORM	"eNrwpPsabcglmoRtzACEST"
 
 /* text that we spew with the -h flag */
 #define	HELP1 \
@@ -158,6 +159,7 @@
 "        -b cmd          execute cmd before taking actions\n"\
 "        -c              copy & truncate logfile, don't rename\n"\
 "        -g group        new empty log file group\n"\
+"        -l              rotate log file with local time rather than UTC\n"\
 "        -m mode         new empty log file mode\n"\
 "        -M cmd          execute cmd to rotate the log file\n"\
 "        -o owner        new empty log file owner\n"\
@@ -668,9 +670,25 @@
 
 	if (Debug)
 		(void) fprintf(stderr, "rotatelog: conditions met\n");
+	if (opts_count(opts, "l")) {
+		/* Change the time zone to local time zone */
+		if (putenv("TZ="))
+			err(EF_SYS, "putenv TZ");
+		tzset();
+		Now = time(0);
 
-	/* rename the log file */
-	rotateto(fnp, opts, 0, recentlog, B_FALSE);
+		/* rename the log file */
+		rotateto(fnp, opts, 0, recentlog, B_FALSE);
+
+		/* Change the time zone to UTC */
+		if (putenv("TZ=UTC"))
+			err(EF_SYS, "putenv TZ");
+		tzset();
+		Now = time(0);
+	} else {
+		/* rename the log file */
+		rotateto(fnp, opts, 0, recentlog, B_FALSE);
+	}
 
 	/* determine owner, group, mode for empty log file */
 	if (opts_count(opts, "o"))
--- a/usr/src/cmd/logadm/tester	Mon Nov 21 01:08:40 2005 -0800
+++ b/usr/src/cmd/logadm/tester	Mon Nov 21 02:26:46 2005 -0800
@@ -21,7 +21,7 @@
 # CDDL HEADER END
 #
 #
-# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
 #ident	"%Z%%M%	%I%	%E% SMI"
@@ -91,6 +91,7 @@
 	"logadm16",
 	"logadm17",
 	"logadm18",
+	"logadm19",
 );
 
 use Getopt::Std;
@@ -607,6 +608,7 @@
 	$secondblob =~ s/%d/$percentd/mg;
 	$secondblob =~ s/%Y/$percentY/mg;
 	$secondblob =~ s/ISA/$isa/mg;
+	$utcenv = "TZ=UTC export TZ";
 	chomp $secondblob;
 	set_file('sed.out.expect', <<"EOF");
             basename syslog
@@ -638,6 +640,7 @@
 	set_file('runtest', <<"EOF");
 # test "kwtest1"
 $envsetup
+$utcenv
 exec $bindir/$kwtest >std.out 2>std.err
 EOF
 }
@@ -1882,6 +1885,7 @@
         -b cmd          execute cmd before taking actions
         -c              copy & truncate logfile, don't rename
         -g group        new empty log file group
+        -l              rotate log file with local time rather than UTC
         -m mode         new empty log file mode
         -M cmd          execute cmd to rotate the log file
         -o owner        new empty log file owner
@@ -1987,3 +1991,29 @@
 exec $bindir/logadm -f logadm.conf >std.out 2>std.err
 EOF
 }
+
+#############################################################################
+#
+#         logadm19 -- test of  -l
+#
+#############################################################################
+sub logadm19 {
+        set_file('logfile', 'initially logfile');
+
+        set_file('checktest', <<'EOF');
+[ -s std.err ] && exit 1
+[ -s std.out ] && exit 1
+[ -s logfile ] && exit 1
+TZ= export TZ
+d=`/bin/date +\%d\%H\%M`
+[ -f logfile.$d ] || exit 1
+[ "xinitially logfile" = "x`/bin/cat logfile.$d`" ] || exit 1
+exit 0
+EOF
+
+        set_file('runtest', <<"EOF");
+# test "logadm4"
+$envsetup
+exec $bindir/logadm -f /dev/null -l -p now logfile -t '\$file.\%d\%H\%M' >std.out 2>std.err
+EOF
+}