From 5a0868e53edb03b04a25b10f82b5363181fb978e Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sun, 28 Apr 2019 12:00:10 +0200 Subject: [PATCH] sar: Use nanoseconds to distinguish between saDD and saYYYYMMDD When no input datafile is specified, sar uses the most recent file between saDD and saYYYYMMDD. The comparison had a precision of a second, which is quite enough for normal use. Yet I needed more precision for use in simulation tests. So use now a precision of the nanosecond. Signed-off-by: Sebastien GODARD --- sa_common.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sa_common.c b/sa_common.c index 0b38a4b..d1df4c5 100644 --- a/sa_common.c +++ b/sa_common.c @@ -143,6 +143,7 @@ void guess_sa_name(char *sa_dir, struct tm *rectime, int *sa_name) char filename[MAX_FILE_LEN]; struct stat sb; time_t sa_mtime; + long nsec; /* Use saDD by default */ *sa_name = 0; @@ -159,6 +160,7 @@ void guess_sa_name(char *sa_dir, struct tm *rectime, int *sa_name) /* Cannot find or access saYYYYMMDD, so use saDD */ return; sa_mtime = sb.st_mtime; + nsec = sb.st_mtim.tv_nsec; /* Look for saDD */ snprintf(filename, MAX_FILE_LEN, @@ -172,7 +174,8 @@ void guess_sa_name(char *sa_dir, struct tm *rectime, int *sa_name) return; } - if (sa_mtime > sb.st_mtime) { + if ((sa_mtime > sb.st_mtime) || + ((sa_mtime == sb.st_mtime) && (nsec > sb.st_mtim.tv_nsec))) { /* saYYYYMMDD is more recent than saDD, so use it */ *sa_name = 1; } -- 2.40.0