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.
This commit is contained in:
Дмитрий Левин 2015-08-08 12:12:13 +00:00
parent 30ac0627f2
commit 525eed33fa
4 changed files with 63 additions and 6 deletions

View File

@ -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 <netinet/in.h>])
AC_CHECK_TYPES([struct mmsghdr],,, [#include <sys/socket.h>])
AC_CHECK_MEMBERS([struct msghdr.msg_control],,, [#include <sys/socket.h>])
AC_CHECK_MEMBERS(m4_normalize([
struct stat.st_atime_nsec,
struct stat.st_ctime_nsec,
struct stat.st_mtime_nsec
]),,, [#include <sys/types.h>
#include <asm/stat.h>])
AC_CHECK_TYPES([struct stat64],,, [#include <sys/types.h>
#include <asm/stat.h>])
AC_CHECK_TYPES([struct __old_kernel_stat],,, [#include <asm/stat.h>])

8
file.c
View File

@ -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

View File

@ -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

View File

@ -20,6 +20,21 @@
#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64
# include <sys/stat.h>
# 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 <sys/syscall.h>
# 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]+)?");