From: Sebastien Godard Date: Tue, 8 May 2012 13:12:15 +0000 (+0200) Subject: sadc now overwrites its daily data file when it is from a previous month. X-Git-Tag: v10.0.5~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0aced09880c724952a02b86fdaf142b01e1bc988;p=sysstat sadc now overwrites its daily data file when it is from a previous month. When the output file is specified as "-", sadc now overwrites the daily data file if it is from a previous month. This is useful to prevent data from several months from being saved in the same file. Mail from Vitezslav Cizek : Hi, /var/log/sa/saXX files don't get overwritten when new month comes. The new data is appended to the end. Reproduced with several versions of sysstat. I browsed the code, but couldn't find any part relevant to the date checking when opening files. It works as advertised in manpage with the attached patch. (Against 10.0.4) The patch doesn't check whether it operates on the standard file or not. --- diff --git a/CHANGES b/CHANGES index 4ec78b4..494897a 100644 --- a/CHANGES +++ b/CHANGES @@ -4,12 +4,14 @@ xxxx/xx/xx: Version 10.0.5 - Sebastien Godard (sysstat orange.fr) * [Alain Chereau]: Options -g and -T added to iostat. These options enable the user to display statistics for groups of devices. + * [Vitezslav Cizek]: sadc now overwrites its standard daily + data file when this file is from a past month. * sadf: Change time format from HH-MM-SS to HH:MM:SS in the various reports displayed by sadf. * XSD document updated: Added a maxOccurs indicator for the timestamp element. * [Peter Schiffer]: Set exit code to 0 for sa2 shell script. - * iostat manual page updated. + * iostat and sadc manual pages updated. * CREDITS file updated. 2012/03/07: Version 10.0.4 - Sebastien Godard (sysstat orange.fr) diff --git a/CREDITS b/CREDITS index 8705565..3631be0 100644 --- a/CREDITS +++ b/CREDITS @@ -146,6 +146,7 @@ I would also thank the following people for their hints or bug reports Xavier Bru Jason Burnett Fabricio Ceolin Mark J. Cox Jean Dagenais Nicolas Denis diff --git a/man/sadc.in b/man/sadc.in index 360c3de..9a5f3a9 100644 --- a/man/sadc.in +++ b/man/sadc.in @@ -1,4 +1,4 @@ -.TH SADC 8 "SEPTEMBER 2010" Linux "Linux User's Manual" -*- nroff -*- +.TH SADC 8 "MAY 2012" Linux "Linux User's Manual" -*- nroff -*- .SH NAME sadc \- System activity data collector. .SH SYNOPSIS @@ -25,6 +25,9 @@ is set to -, then uses the standard system activity daily data file, the .IR @SA_DIR@/sa dd file, where the dd parameter indicates the current day. +In this case, +.B sadc +will overwrite the file if it is from a previous month. By default .B sadc collects all the data available from the kernel. diff --git a/sadc.c b/sadc.c index 3f93dd5..af42fba 100644 --- a/sadc.c +++ b/sadc.c @@ -677,6 +677,7 @@ void open_ofile(int *ofd, char ofile[]) { struct file_magic file_magic; struct file_activity file_act; + struct tm rectime; ssize_t sz; int i, p; @@ -720,6 +721,21 @@ void open_ofile(int *ofd, char ofile[]) handle_invalid_sa_file(ofd, &file_magic, ofile, 0); } + /* + * If we are using the standard daily data file (file specified + * as "-" on the command line) and it is from a past month, + * then overwrite (truncate) it. + */ + get_time(&rectime); + + if (((file_hdr.sa_month != rectime.tm_mon) || + (file_hdr.sa_year != rectime.tm_year)) && + WANT_SA_ROTAT(flags)) { + close(*ofd); + create_sa_file(ofd, ofile); + return; + } + /* * OK: It's a true system activity file. * List of activities from the file prevails over that of the user.