From 525eed33fad84e59f66b2d911c9704c194a23ff8 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sat, 8 Aug 2015 12:12:13 +0000 Subject: [PATCH] Print nanoseconds along with seconds in stat family syscalls * configure.ac (AC_CHECK_MEMBERS): Add stat.st_atim.tv_nsec, stat.st_ctim.tv_nsec, stat.st_mtim.tv_nsec, stat.st_atime_nsec, stat.st_atime_csec, and stat.st_mtime_nsec. * file.c: Explicitly define HAVE_STRUCT_STAT_ST_ATIME_NSEC, HAVE_STRUCT_STAT_ST_CTIME_NSEC and HAVE_STRUCT_STAT_ST_MTIME_NSEC for locally defined types. * printstat.h (DO_PRINTSTAT): Print st_atime_nsec, st_ctime_nsec, and st_mtime_nsec members. * tests/stat.c [_FILE_OFFSET_BITS == 64]: Use st_atime_nsec, st_ctime_nsec, and st_mtime_nsec via st_atim.tv_nsec, st_ctim.tv_nsec, and st_mtim.tv_nsec. (main): Print st_atime_nsec, st_ctime_nsec, and st_mtime_nsec members. This fixes Fedora bug #1251176. --- configure.ac | 10 ++++++++++ file.c | 8 ++++++++ printstat.h | 24 ++++++++++++++++++------ tests/stat.c | 27 +++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 359402b9..f66fb002 100644 --- a/configure.ac +++ b/configure.ac @@ -206,11 +206,14 @@ AC_HEADER_STDBOOL AC_HEADER_DIRENT AC_HEADER_STAT AC_CHECK_MEMBERS(m4_normalize([ + struct stat.st_atim.tv_nsec, struct stat.st_blksize, struct stat.st_blocks, + struct stat.st_ctim.tv_nsec, struct stat.st_flags, struct stat.st_fstype, struct stat.st_gen, + struct stat.st_mtim.tv_nsec, struct stat.st_rdev ])) @@ -288,6 +291,13 @@ AC_CHECK_HEADERS([netinet/tcp.h netinet/udp.h],,, [#include ]) AC_CHECK_TYPES([struct mmsghdr],,, [#include ]) AC_CHECK_MEMBERS([struct msghdr.msg_control],,, [#include ]) +AC_CHECK_MEMBERS(m4_normalize([ + struct stat.st_atime_nsec, + struct stat.st_ctime_nsec, + struct stat.st_mtime_nsec +]),,, [#include +#include ]) + AC_CHECK_TYPES([struct stat64],,, [#include #include ]) AC_CHECK_TYPES([struct __old_kernel_stat],,, [#include ]) diff --git a/file.c b/file.c index 30929944..78d86f2d 100644 --- a/file.c +++ b/file.c @@ -87,6 +87,14 @@ #include "printstat.h" +/* all locally defined structures provide these fields */ +#undef HAVE_STRUCT_STAT_ST_ATIME_NSEC +#define HAVE_STRUCT_STAT_ST_ATIME_NSEC 1 +#undef HAVE_STRUCT_STAT_ST_CTIME_NSEC +#define HAVE_STRUCT_STAT_ST_CTIME_NSEC 1 +#undef HAVE_STRUCT_STAT_ST_MTIME_NSEC +#define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1 + #undef STAT32_PERSONALITY #if SUPPORTED_PERSONALITIES > 1 # if defined AARCH64 || defined X86_64 || defined X32 diff --git a/printstat.h b/printstat.h index 033d4a0a..0908355f 100644 --- a/printstat.h +++ b/printstat.h @@ -59,15 +59,27 @@ DO_PRINTSTAT(struct tcb *tcp, const STRUCT_STAT *statbuf) if (!abbrev(tcp)) { const bool cast = sizeof(statbuf->st_atime) == sizeof(int); - tprintf("st_atime=%s, ", - sprinttime(cast ? (time_t) (int) statbuf->st_atime: + tprints("st_atime="); + tprints(sprinttime(cast ? (time_t) (int) statbuf->st_atime: (time_t) statbuf->st_atime)); - tprintf("st_mtime=%s, ", - sprinttime(cast ? (time_t) (int) statbuf->st_mtime: +#ifdef HAVE_STRUCT_STAT_ST_ATIME_NSEC + if (statbuf->st_atime_nsec) + tprintf(".%09lu", (unsigned long) statbuf->st_atime_nsec); +#endif + tprints(", st_mtime="); + tprints(sprinttime(cast ? (time_t) (int) statbuf->st_mtime: (time_t) statbuf->st_mtime)); - tprintf("st_ctime=%s", - sprinttime(cast ? (time_t) (int) statbuf->st_ctime: +#ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC + if (statbuf->st_mtime_nsec) + tprintf(".%09lu", (unsigned long) statbuf->st_mtime_nsec); +#endif + tprints(", st_ctime="); + tprints(sprinttime(cast ? (time_t) (int) statbuf->st_ctime: (time_t) statbuf->st_ctime)); +#ifdef HAVE_STRUCT_STAT_ST_CTIME_NSEC + if (statbuf->st_ctime_nsec) + tprintf(".%09lu", (unsigned long) statbuf->st_ctime_nsec); +#endif #ifdef HAVE_STRUCT_STAT_ST_FLAGS tprintf(", st_flags=%u", (unsigned int) statbuf->st_flags); #endif diff --git a/tests/stat.c b/tests/stat.c index 0dbbb721..9146b739 100644 --- a/tests/stat.c +++ b/tests/stat.c @@ -20,6 +20,21 @@ #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 # include # define STAT_PREFIX "(stat(64)?\\(|newfstatat\\(AT_FDCWD, )" +# undef HAVE_STRUCT_STAT_ST_ATIME_NSEC +# ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC +# define HAVE_STRUCT_STAT_ST_ATIME_NSEC 1 +# define st_atime_nsec st_atim.tv_nsec +# endif +# undef HAVE_STRUCT_STAT_ST_MTIME_NSEC +# ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC +# define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1 +# define st_mtime_nsec st_mtim.tv_nsec +# endif +# undef HAVE_STRUCT_STAT_ST_CTIME_NSEC +# ifdef HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC +# define HAVE_STRUCT_STAT_ST_CTIME_NSEC 1 +# define st_ctime_nsec st_ctim.tv_nsec +# endif #else # include # if defined __NR_stat @@ -154,10 +169,22 @@ main(int ac, const char **av) printf(", st_atime="); print_time(stb.st_atime); +#ifdef HAVE_STRUCT_STAT_ST_ATIME_NSEC + if (stb.st_atime_nsec) + printf(".%09lu", (unsigned long) stb.st_atime_nsec); +#endif printf(", st_mtime="); print_time(stb.st_mtime); +#ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC + if (stb.st_mtime_nsec) + printf(".%09lu", (unsigned long) stb.st_mtime_nsec); +#endif printf(", st_ctime="); print_time(stb.st_ctime); +#ifdef HAVE_STRUCT_STAT_ST_CTIME_NSEC + if (stb.st_ctime_nsec) + printf(".%09lu", (unsigned long) stb.st_ctime_nsec); +#endif printf("(, st_flags=[0-9]+)?"); printf("(, st_fstype=[^,]*)?"); printf("(, st_gen=[0-9]+)?"); -- 2.40.0