autoconf check for utimensat(2)
PATCH v3 1/3 autoconf check for utimensat(2)
In reply to a message not in the archiveUnfortunately, not all distributions have utimensat(2) defined (old glibc), so we need a way to check it in our code.
--- configure.ac | 1 + m4/ltp-utimensat.m4 | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 0 deletions(-) create mode 100644 m4/ltp-utimensat.m4
configure.ac +1 -0
@@ -162,6 +162,7 @@ LTP_CHECK_SYSCALL_NUMA LTP_CHECK_SYSCALL_QUOTACTL LTP_CHECK_SYSCALL_SIGNALFD LTP_CHECK_SYSCALL_UNSHARE +LTP_CHECK_SYSCALL_UTIMENSAT LTP_CHECK_TASKSTATS LTP_CHECK_TIME LTP_CHECK_MADVISE
m4/ltp-utimensat.m4 new file +44 -0
44 lines not on this page · raw message
Signature · 12 lines
1.7.1 ------------------------------------------------------------------------------ Sponsored by Intel(R) XDK Develop, test and display web and hybrid apps with a single code base. Download it for free now! http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
PATCH v3 3/3 safe_touch: use utimes(2) if utimensat(2) is not defined
In reply to a message not in the archiveIf utimensat(2) is not defined on the platform we switch to using utimes(2).
--- include/safe_file_ops.h | 1 + lib/safe_file_ops.c | 53 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-)
include/safe_file_ops.h +1 -0
@@ -36,6 +36,7 @@#include <sys/stat.h> +#include "lapi/utime.h" #include "test.h" /*
lib/safe_file_ops.c +51 -2
78 lines not on this page · raw message
Signature · 12 lines
1.7.1 ------------------------------------------------------------------------------ Sponsored by Intel(R) XDK Develop, test and display web and hybrid apps with a single code base. Download it for free now! http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
PATCH v3 2/3 created lapi/utime.h
In reply to a message not in the archiveAnd put there some definitions which are needed, even if the libc doesn't provide them.
--- include/lapi/utime.h | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-) create mode 100644 include/lapi/utime.h
include/lapi/utime.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef __UTIME_H__ + +#ifndef UTIME_NOW +# define UTIME_NOW ((1l << 30) - 1l) +#endif + +#ifndef UTIME_OMIT +# define UTIME_OMIT ((1l << 30) - 2l) +#endif + +#endif /* __UTIME_H__ */
Signature · 12 lines
1.7.1 ------------------------------------------------------------------------------ Sponsored by Intel(R) XDK Develop, test and display web and hybrid apps with a single code base. Download it for free now! http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Re: [LTP] [PATCH V3 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined
In reply to Stanislav KholmanskikhHi!
Quoted 50 lines
If utimensat(2) is not defined on the platform we switch to using utimes(2).
Signed-off-by Stanislav Kholmanskikh <[email protected]>--- include/safe_file_ops.h | 1 + lib/safe_file_ops.c | 53 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-)include/safe_file_ops.h +1
-0@@ -36,6 +36,7 @@#include <sys/stat.h> +#include "lapi/utime.h" #include "test.h" /* lib/safe_file_ops.c +9
-0@@ -21,11 +21,15 @@* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "config.h" #include <stdarg.h> #include <stdio.h> +#include <sys/time.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <unistd.h> +#include <utime.h> #include "safe_file_ops.h" @@ -69,6 +73,22 @@ static int count_scanf_conversions(const char *fmt)return cnt; } +static void set_time (struct timeval *res,struct timespec *src, +long cur_tv_sec,long cur_tv_usec) +{ +switch (src->tv_nsec) { +case UTIME_NOW :
lib/safe_file_ops.c static int count_scanf_conversions(const char *fmt) · line 90
Quoted 10 lines
lib/safe_file_ops.c +10
-0+break ; +case UTIME_OMIT : + res->tv_sec = cur_tv_sec; + res->tv_usec = cur_tv_usec; +break ; +default : + res->tv_sec = src->tv_sec; + res->tv_usec = src->tv_nsec /1000 ; + } +}
I've added an #ifndef HAVE_UTIMENSAT around this block, because otherwise we will get unused function warning when HAVE_UTIMENSAT is defined.
Quoted 32 lines
lib/safe_file_ops.c +24
-0void safe_file_scanf (const char *file,const int lineno,void (*cleanup_fn) (void ),const char *path,const char *fmt, ...)@@ -186,10 +206,39 @@ void safe_touch(const char *file, const int lineno, pathname, file, lineno); } + +#if HAVE_UTIMENSAT ret =utimensat (AT_FDCWD , pathname, times,0 ); +#else +if (times ==NULL ) { + ret =utimes (pathname,NULL ); + }else { +struct stat sb; +struct timeval cotimes[2 ]; + + ret =stat (pathname, &sb); +if (ret ==-1 ) +tst_brkm (TBROK |TERRNO , cleanup_fn, +"Failed to stat file '%s' at %s:%d" , + pathname, file, lineno); + + ret =gettimeofday (cotimes,NULL ); +if (ret ==-1 ) +tst_brkm (TBROK |TERRNO , cleanup_fn, +"Failed to gettimeofday() at %s:%d" , + file, lineno); + cotimes[1 ] = cotimes[0 ]; + +set_time (cotimes, times, + sb.st_atime, sb.st_atim.tv_nsec /1000 );
lib/safe_file_ops.c void safe_touch(const char *file, const int lineno, · line 242
Quoted 10 lines
lib/safe_file_ops.c +7
-1+set_time (cotimes +1 , times +1 , + sb.st_mtime, sb.st_mtim.tv_nsec /1000 ); + + ret =utimes (pathname, cotimes); + } +#endif if (ret ==-1 ) tst_brkm(TBROK | TERRNO, cleanup_fn, - "Failed to do utimensat() on file '%s' at %s:%d", + "Failed to update the access/modification times on file '%s' at %s:%d",
And I've also fixed this line to fit into 80 chars.
Pushed, thanks.
Signature · 12 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ Sponsored by Intel(R) XDK Develop, test and display web and hybrid apps with a single code base. Download it for free now! http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list