* [LTP] safe_touch and utimensat
@ 2013-11-13 14:30 Stanislav Kholmanskikh
2013-11-13 14:30 ` [LTP] [RFC PATCH 1/2] autoconf check for utimensat(2) Stanislav Kholmanskikh
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: Stanislav Kholmanskikh @ 2013-11-13 14:30 UTC (permalink / raw)
To: ltp-list; +Cc: vasily.isaenko
Hi!
Some distributions (RHEL5, for instance) don't have defined utimensat()
system call. So I introduced an autoconf check for this, otherwise safe_file_ops.c can
not be compiled on these distributions.
Actually, I'm not satisfied with
utimes(pathname, NULL)
because it throws away the time-changing logic from safe_touch().
How do you think it is safe to explicitly define UTIME_* constants in LTP
sources (safe_file_ops.h):
#ifndef UTIME_NOW
#define UTIME_NOW ((1l << 30) - 1l)
#endif
#ifndef UTIME_OMIT
#define UTIME_OMIT ((1l << 30) - 2l)
#endif
?
------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 12+ messages in thread* [LTP] [RFC PATCH 1/2] autoconf check for utimensat(2) 2013-11-13 14:30 [LTP] safe_touch and utimensat Stanislav Kholmanskikh @ 2013-11-13 14:30 ` Stanislav Kholmanskikh 2013-11-14 15:08 ` chrubis 2013-11-21 18:22 ` Mike Frysinger 2013-11-13 14:30 ` [LTP] [RFC PATCH 2/2] safe_touch: use utimes(2) if utimensat(2) is not defined Stanislav Kholmanskikh ` (2 subsequent siblings) 3 siblings, 2 replies; 12+ messages in thread From: Stanislav Kholmanskikh @ 2013-11-13 14:30 UTC (permalink / raw) To: ltp-list; +Cc: vasily.isaenko Unfortunately, not all distributions have utimensat(2) defined (old glibc), so we need a way to check it in our code. Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com> --- configure.ac | 1 + m4/ltp-utimensat.m4 | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 0 deletions(-) create mode 100644 m4/ltp-utimensat.m4 diff --git a/configure.ac b/configure.ac index 940f4f7..4e955e3 100644 --- a/configure.ac +++ b/configure.ac @@ -161,6 +161,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 diff --git a/m4/ltp-utimensat.m4 b/m4/ltp-utimensat.m4 new file mode 100644 index 0000000..e98b3af --- /dev/null +++ b/m4/ltp-utimensat.m4 @@ -0,0 +1,44 @@ +dnl +dnl Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. +dnl +dnl This program is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU General Public License as +dnl published by the Free Software Foundation; either version 2 of +dnl the License, or (at your option) any later version. +dnl +dnl This program is distributed in the hope that it would be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +dnl GNU General Public License for more details. +dnl +dnl You should have received a copy of the GNU General Public License +dnl along with this program; if not, write the Free Software Foundation, +dnl Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +dnl + +dnl +dnl LTP_CHECK_SYSCALL_UTIMENSAT +dnl ---------------------------- +dnl +AC_DEFUN([LTP_CHECK_SYSCALL_UTIMENSAT],[ + AC_MSG_CHECKING([for utimensat]) + AC_LINK_IFELSE([AC_LANG_SOURCE([ +#include <stdlib.h> +#include <sys/stat.h> +#include <fcntl.h> + +int main(void) { + long tv_nsec; + tv_nsec = UTIME_NOW; + tv_nsec = UTIME_OMIT; + + return utimensat(AT_FDCWD, (const char *) "/dev/null", NULL, 0); +}])],[has_utimensat="yes"]) + +if test "x$has_utimensat" == "xyes"; then + AC_DEFINE(HAVE_UTIMENSAT, 1, [Define to 1 if you have utimensat(2)]) + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi +]) -- 1.7.1 ------------------------------------------------------------------------------ DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access Free app hosting. Or install the open source package on any LAMP server. Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native! http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [LTP] [RFC PATCH 1/2] autoconf check for utimensat(2) 2013-11-13 14:30 ` [LTP] [RFC PATCH 1/2] autoconf check for utimensat(2) Stanislav Kholmanskikh @ 2013-11-14 15:08 ` chrubis 2013-11-21 18:22 ` Mike Frysinger 1 sibling, 0 replies; 12+ messages in thread From: chrubis @ 2013-11-14 15:08 UTC (permalink / raw) To: Stanislav Kholmanskikh; +Cc: vasily.isaenko, ltp-list Hi! > +AC_DEFUN([LTP_CHECK_SYSCALL_UTIMENSAT],[ > + AC_MSG_CHECKING([for utimensat]) > + AC_LINK_IFELSE([AC_LANG_SOURCE([ > +#include <stdlib.h> > +#include <sys/stat.h> > +#include <fcntl.h> > + > +int main(void) { > + long tv_nsec; > + tv_nsec = UTIME_NOW; > + tv_nsec = UTIME_OMIT; > + > + return utimensat(AT_FDCWD, (const char *) "/dev/null", NULL, 0); > +}])],[has_utimensat="yes"]) Why the cast to const char* and why cannot be the second parameter NULL too (it's just linked not executed)? > + > +if test "x$has_utimensat" == "xyes"; then > + AC_DEFINE(HAVE_UTIMENSAT, 1, [Define to 1 if you have utimensat(2)]) > + AC_MSG_RESULT(yes) > +else > + AC_MSG_RESULT(no) > +fi > +]) -- Cyril Hrubis chrubis@suse.cz ------------------------------------------------------------------------------ DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access Free app hosting. Or install the open source package on any LAMP server. Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native! http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [LTP] [RFC PATCH 1/2] autoconf check for utimensat(2) 2013-11-13 14:30 ` [LTP] [RFC PATCH 1/2] autoconf check for utimensat(2) Stanislav Kholmanskikh 2013-11-14 15:08 ` chrubis @ 2013-11-21 18:22 ` Mike Frysinger 1 sibling, 0 replies; 12+ messages in thread From: Mike Frysinger @ 2013-11-21 18:22 UTC (permalink / raw) To: ltp-list; +Cc: vasily.isaenko [-- Attachment #1.1: Type: Text/Plain, Size: 130 bytes --] On Wednesday 13 November 2013 09:30:21 Stanislav Kholmanskikh wrote: > +if test "x$has_utimensat" == "xyes"; then just 1 = -mike [-- Attachment #1.2: This is a digitally signed message part. --] [-- Type: application/pgp-signature, Size: 836 bytes --] [-- Attachment #2: Type: text/plain, Size: 427 bytes --] ------------------------------------------------------------------------------ Shape the Mobile Experience: Free Subscription Software experts and developers: Be at the forefront of tech innovation. Intel(R) Software Adrenaline delivers strategic insight and game-changing conversations that shape the rapidly evolving mobile landscape. Sign up now. http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk [-- Attachment #3: Type: text/plain, Size: 155 bytes --] _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply [flat|nested] 12+ messages in thread
* [LTP] [RFC PATCH 2/2] safe_touch: use utimes(2) if utimensat(2) is not defined 2013-11-13 14:30 [LTP] safe_touch and utimensat Stanislav Kholmanskikh 2013-11-13 14:30 ` [LTP] [RFC PATCH 1/2] autoconf check for utimensat(2) Stanislav Kholmanskikh @ 2013-11-13 14:30 ` Stanislav Kholmanskikh 2013-11-14 15:06 ` [LTP] safe_touch and utimensat chrubis 2013-11-26 16:06 ` chrubis 3 siblings, 0 replies; 12+ messages in thread From: Stanislav Kholmanskikh @ 2013-11-13 14:30 UTC (permalink / raw) To: ltp-list; +Cc: vasily.isaenko If utimensat(2) is not defined on the platform we switch to using utimes(2). Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com> --- lib/safe_file_ops.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/lib/safe_file_ops.c b/lib/safe_file_ops.c index 8cfd264..3876c27 100644 --- a/lib/safe_file_ops.c +++ b/lib/safe_file_ops.c @@ -21,10 +21,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "config.h" #include <stdarg.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> +#include <sys/syscall.h> #include <fcntl.h> #include "safe_file_ops.h" @@ -186,10 +188,20 @@ void safe_touch(const char *file, const int lineno, pathname, file, lineno); } + +#if HAVE_UTIMENSAT ret = utimensat(AT_FDCWD, pathname, times, 0); +#else + /* we can't reliably check if times[i].tv_nsec is + * either UTIME_NOW or UTIME_OMIT (because they + * are not defined if utimensat() is not defined), + * therefore update the access/modification times + * to the current time */ + ret = utimes(pathname, NULL); +#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", pathname, file, lineno); } -- 1.7.1 ------------------------------------------------------------------------------ DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access Free app hosting. Or install the open source package on any LAMP server. Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native! http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [LTP] safe_touch and utimensat 2013-11-13 14:30 [LTP] safe_touch and utimensat Stanislav Kholmanskikh 2013-11-13 14:30 ` [LTP] [RFC PATCH 1/2] autoconf check for utimensat(2) Stanislav Kholmanskikh 2013-11-13 14:30 ` [LTP] [RFC PATCH 2/2] safe_touch: use utimes(2) if utimensat(2) is not defined Stanislav Kholmanskikh @ 2013-11-14 15:06 ` chrubis 2013-11-26 16:06 ` chrubis 3 siblings, 0 replies; 12+ messages in thread From: chrubis @ 2013-11-14 15:06 UTC (permalink / raw) To: Stanislav Kholmanskikh; +Cc: vasily.isaenko, ltp-list Hi! > Some distributions (RHEL5, for instance) don't have defined utimensat() > system call. So I introduced an autoconf check for this, otherwise safe_file_ops.c can > not be compiled on these distributions. > > Actually, I'm not satisfied with > utimes(pathname, NULL) > because it throws away the time-changing logic from safe_touch(). > > How do you think it is safe to explicitly define UTIME_* constants in LTP > sources (safe_file_ops.h): > > #ifndef UTIME_NOW > #define UTIME_NOW ((1l << 30) - 1l) > #endif > > #ifndef UTIME_OMIT > #define UTIME_OMIT ((1l << 30) - 2l) > #endif That shouldn't be a problem. These constants are part of ABI they will not change in future. Actually LTP has several places where such defines are used in order not to overcomplicate the autoconf checks. But I would like to start sticking these into a specific directory under include/. For example to put these two into include/lapi/utime.h and include it from the safe_file_ops.h. -- Cyril Hrubis chrubis@suse.cz ------------------------------------------------------------------------------ DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access Free app hosting. Or install the open source package on any LAMP server. Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native! http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [LTP] safe_touch and utimensat 2013-11-13 14:30 [LTP] safe_touch and utimensat Stanislav Kholmanskikh ` (2 preceding siblings ...) 2013-11-14 15:06 ` [LTP] safe_touch and utimensat chrubis @ 2013-11-26 16:06 ` chrubis [not found] ` <5296FAB8.8050702@oracle.com> 3 siblings, 1 reply; 12+ messages in thread From: chrubis @ 2013-11-26 16:06 UTC (permalink / raw) To: Stanislav Kholmanskikh; +Cc: vasily.isaenko, ltp-list Hi! > Some distributions (RHEL5, for instance) don't have defined utimensat() > system call. So I introduced an autoconf check for this, otherwise safe_file_ops.c can > not be compiled on these distributions. > > Actually, I'm not satisfied with > utimes(pathname, NULL) > because it throws away the time-changing logic from safe_touch(). > > How do you think it is safe to explicitly define UTIME_* constants in LTP > sources (safe_file_ops.h): > > #ifndef UTIME_NOW > #define UTIME_NOW ((1l << 30) - 1l) > #endif > > #ifndef UTIME_OMIT > #define UTIME_OMIT ((1l << 30) - 2l) > #endif Any progress on this? Do you need a help? The latest git build on older distros is broken and should be fixed ASAP... -- Cyril Hrubis chrubis@suse.cz ------------------------------------------------------------------------------ Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <5296FAB8.8050702@oracle.com>]
* Re: [LTP] safe_touch and utimensat [not found] ` <5296FAB8.8050702@oracle.com> @ 2013-11-28 11:36 ` chrubis 2013-11-29 7:58 ` [LTP] [PATCH V2 1/3] autoconf check for utimensat(2) Stanislav Kholmanskikh ` (2 more replies) 0 siblings, 3 replies; 12+ messages in thread From: chrubis @ 2013-11-28 11:36 UTC (permalink / raw) To: Stanislav Kholmanskikh; +Cc: vasily.isaenko, ltp-list Hi! > Actually, I need. > > I use clock_gettime() to get the current time and use it when UTIME_NOW > is passed. Like this: > #if HAVE_UTIMENSAT > ret = utimensat(AT_FDCWD, pathname, times, 0); > #else > if (times == NULL) { > ret = utimes(pathname, NULL); > } else { > /* stat and etc */ > > ret = clock_gettime(CLOCK_REALTIME, &tp); > if (ret == -1) > tst_brkm(TBROK | TERRNO, cleanup_fn, > "Failed to clock_realtime() at %s:%d", > file, lineno); > > /* handle UTIME_NOW and etc */ > } > #endif > > > The compilation of safe_file_ops.c performs ok. libltp.a is formed. But > compilations of other pieces of code using safe_touch fails with: > make[1]: Entering directory `/home/stas/ltp/lib/tests' > gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W > -D_FORTIFY_SOURCE=2 -I../../include -I../../include -L../../lib > tst_process_state.c -lltp -o tst_process_state > ../../lib/libltp.a(safe_file_ops.o): In function `safe_touch': > /home/stas/ltp/lib/safe_file_ops.c:213: undefined reference to > `clock_gettime' > collect2: ld returned 1 exit status > > I know, that clock_gettime() requires '-lrt'. > > But I'm not sure about the right place inside LTP sources to put it in.... What about using gettimeofday() instead? -- Cyril Hrubis chrubis@suse.cz ------------------------------------------------------------------------------ Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply [flat|nested] 12+ messages in thread
* [LTP] [PATCH V2 1/3] autoconf check for utimensat(2) 2013-11-28 11:36 ` chrubis @ 2013-11-29 7:58 ` Stanislav Kholmanskikh 2013-11-29 7:58 ` [LTP] [PATCH V2 2/3] created lapi/utime.h Stanislav Kholmanskikh 2013-11-29 7:58 ` [LTP] [PATCH V2 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined Stanislav Kholmanskikh 2 siblings, 0 replies; 12+ messages in thread From: Stanislav Kholmanskikh @ 2013-11-29 7:58 UTC (permalink / raw) To: ltp-list; +Cc: vasily.isaenko Unfortunately, not all distributions have utimensat(2) defined (old glibc), so we need a way to check it in our code. Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com> --- configure.ac | 1 + m4/ltp-utimensat.m4 | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 0 deletions(-) create mode 100644 m4/ltp-utimensat.m4 diff --git a/configure.ac b/configure.ac index 4846afd..4af7662 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/m4/ltp-utimensat.m4 b/m4/ltp-utimensat.m4 new file mode 100644 index 0000000..1f9a055 --- /dev/null +++ b/m4/ltp-utimensat.m4 @@ -0,0 +1,44 @@ +dnl +dnl Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. +dnl +dnl This program is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU General Public License as +dnl published by the Free Software Foundation; either version 2 of +dnl the License, or (at your option) any later version. +dnl +dnl This program is distributed in the hope that it would be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +dnl GNU General Public License for more details. +dnl +dnl You should have received a copy of the GNU General Public License +dnl along with this program; if not, write the Free Software Foundation, +dnl Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +dnl + +dnl +dnl LTP_CHECK_SYSCALL_UTIMENSAT +dnl ---------------------------- +dnl +AC_DEFUN([LTP_CHECK_SYSCALL_UTIMENSAT],[ + AC_MSG_CHECKING([for utimensat]) + AC_LINK_IFELSE([AC_LANG_SOURCE([ +#include <stdlib.h> +#include <sys/stat.h> +#include <fcntl.h> + +int main(void) { + long tv_nsec; + tv_nsec = UTIME_NOW; + tv_nsec = UTIME_OMIT; + + return utimensat(AT_FDCWD, NULL, NULL, 0); +}])],[has_utimensat="yes"]) + +if test "x$has_utimensat" = "xyes"; then + AC_DEFINE(HAVE_UTIMENSAT, 1, [Define to 1 if you have utimensat(2)]) + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi +]) -- 1.7.1 ------------------------------------------------------------------------------ Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [LTP] [PATCH V2 2/3] created lapi/utime.h 2013-11-28 11:36 ` chrubis 2013-11-29 7:58 ` [LTP] [PATCH V2 1/3] autoconf check for utimensat(2) Stanislav Kholmanskikh @ 2013-11-29 7:58 ` Stanislav Kholmanskikh 2013-11-29 7:58 ` [LTP] [PATCH V2 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined Stanislav Kholmanskikh 2 siblings, 0 replies; 12+ messages in thread From: Stanislav Kholmanskikh @ 2013-11-29 7:58 UTC (permalink / raw) To: ltp-list; +Cc: vasily.isaenko And put there some definitions which are needed, even if the libc doesn't provide them. Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com> --- include/lapi/utime.h | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-) create mode 100644 include/lapi/utime.h diff --git a/include/lapi/utime.h b/include/lapi/utime.h new file mode 100644 index 0000000..4209d4c --- /dev/null +++ b/include/lapi/utime.h @@ -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__ */ -- 1.7.1 ------------------------------------------------------------------------------ Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [LTP] [PATCH V2 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined 2013-11-28 11:36 ` chrubis 2013-11-29 7:58 ` [LTP] [PATCH V2 1/3] autoconf check for utimensat(2) Stanislav Kholmanskikh 2013-11-29 7:58 ` [LTP] [PATCH V2 2/3] created lapi/utime.h Stanislav Kholmanskikh @ 2013-11-29 7:58 ` Stanislav Kholmanskikh 2013-12-02 18:27 ` chrubis 2 siblings, 1 reply; 12+ messages in thread From: Stanislav Kholmanskikh @ 2013-11-29 7:58 UTC (permalink / raw) To: ltp-list; +Cc: vasily.isaenko If utimensat(2) is not defined on the platform we switch to using utimes(2). Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com> --- include/safe_file_ops.h | 1 + lib/safe_file_ops.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletions(-) diff --git a/include/safe_file_ops.h b/include/safe_file_ops.h index 77ad594..1815984 100644 --- a/include/safe_file_ops.h +++ b/include/safe_file_ops.h @@ -36,6 +36,7 @@ #include <sys/stat.h> +#include "lapi/utime.h" #include "test.h" /* diff --git a/lib/safe_file_ops.c b/lib/safe_file_ops.c index 8cfd264..dee8558 100644 --- a/lib/safe_file_ops.c +++ b/lib/safe_file_ops.c @@ -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" @@ -186,10 +190,57 @@ 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 { + int i; + 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[0]), NULL); + if (ret == -1) + tst_brkm(TBROK | TERRNO, cleanup_fn, + "Failed to gettimeofday() at %s:%d", + file, lineno); + cotimes[1] = cotimes[0]; + + for (i = 0; i < 2; i++) { + if (times[i].tv_nsec == UTIME_NOW) { + /* do nothing, because cotimes[i] + * already has the current time + */ + } else if (times[i].tv_nsec == UTIME_OMIT) { + if (i == 0) { + cotimes[i].tv_sec = sb.st_atime; + cotimes[i].tv_usec = sb.st_atim.tv_nsec; + cotimes[i].tv_usec /= 1000; + } else { + cotimes[i].tv_sec = sb.st_mtime; + cotimes[i].tv_usec = sb.st_mtim.tv_nsec; + cotimes[i].tv_usec /= 1000; + } + } else { + cotimes[i].tv_sec = times[i].tv_sec; + cotimes[i].tv_usec = times[i].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", pathname, file, lineno); } -- 1.7.1 ------------------------------------------------------------------------------ Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [LTP] [PATCH V2 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined 2013-11-29 7:58 ` [LTP] [PATCH V2 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined Stanislav Kholmanskikh @ 2013-12-02 18:27 ` chrubis 0 siblings, 0 replies; 12+ messages in thread From: chrubis @ 2013-12-02 18:27 UTC (permalink / raw) To: Stanislav Kholmanskikh; +Cc: vasily.isaenko, ltp-list Hi! > If utimensat(2) is not defined on the platform we switch > to using utimes(2). > > Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com> > --- > include/safe_file_ops.h | 1 + > lib/safe_file_ops.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++- > 2 files changed, 53 insertions(+), 1 deletions(-) > > diff --git a/include/safe_file_ops.h b/include/safe_file_ops.h > index 77ad594..1815984 100644 > --- a/include/safe_file_ops.h > +++ b/include/safe_file_ops.h > @@ -36,6 +36,7 @@ > > #include <sys/stat.h> > > +#include "lapi/utime.h" > #include "test.h" > > /* > diff --git a/lib/safe_file_ops.c b/lib/safe_file_ops.c > index 8cfd264..dee8558 100644 > --- a/lib/safe_file_ops.c > +++ b/lib/safe_file_ops.c > @@ -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" > > @@ -186,10 +190,57 @@ 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 { > + int i; > + 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[0]), NULL); ^ this is the same as cotimes as it translates to &(*(cotimes+0)) > + if (ret == -1) > + tst_brkm(TBROK | TERRNO, cleanup_fn, > + "Failed to gettimeofday() at %s:%d", > + file, lineno); > + cotimes[1] = cotimes[0]; > + > + for (i = 0; i < 2; i++) { > + if (times[i].tv_nsec == UTIME_NOW) { > + /* do nothing, because cotimes[i] > + * already has the current time > + */ > + } else if (times[i].tv_nsec == UTIME_OMIT) { > + if (i == 0) { > + cotimes[i].tv_sec = sb.st_atime; > + cotimes[i].tv_usec = sb.st_atim.tv_nsec; > + cotimes[i].tv_usec /= 1000; > + } else { > + cotimes[i].tv_sec = sb.st_mtime; > + cotimes[i].tv_usec = sb.st_mtim.tv_nsec; > + cotimes[i].tv_usec /= 1000; > + } > + } else { > + cotimes[i].tv_sec = times[i].tv_sec; > + cotimes[i].tv_usec = times[i].tv_nsec / 1000; > + } This part would be easier to read as a swith() statement: switch (times[i].tv_nsec) { case UTIME_NOW: break; case UTIME_OMIT: ... break; } Moreover I would move it into a function such as: void set_time(struct timeval *res, struct timespec *src, long cur_tv_sec, long cur_tv_usec) { switch (src[i].tv_nsec) { ... } And call it as: set_time(cotimes, times, sb.st_atime, sb.st_atim.tv_nsec/1000); set_time(cotimes+1, times+1, sb.st_mtime, sb.st_mtim.tv_nsec/1000); Instead of the for loop, what do you think? > + } > + > + 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", > pathname, file, lineno); > } > The rest of the patchset looks fine to me. -- Cyril Hrubis chrubis@suse.cz ------------------------------------------------------------------------------ Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2013-12-02 18:28 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-13 14:30 [LTP] safe_touch and utimensat Stanislav Kholmanskikh
2013-11-13 14:30 ` [LTP] [RFC PATCH 1/2] autoconf check for utimensat(2) Stanislav Kholmanskikh
2013-11-14 15:08 ` chrubis
2013-11-21 18:22 ` Mike Frysinger
2013-11-13 14:30 ` [LTP] [RFC PATCH 2/2] safe_touch: use utimes(2) if utimensat(2) is not defined Stanislav Kholmanskikh
2013-11-14 15:06 ` [LTP] safe_touch and utimensat chrubis
2013-11-26 16:06 ` chrubis
[not found] ` <5296FAB8.8050702@oracle.com>
2013-11-28 11:36 ` chrubis
2013-11-29 7:58 ` [LTP] [PATCH V2 1/3] autoconf check for utimensat(2) Stanislav Kholmanskikh
2013-11-29 7:58 ` [LTP] [PATCH V2 2/3] created lapi/utime.h Stanislav Kholmanskikh
2013-11-29 7:58 ` [LTP] [PATCH V2 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined Stanislav Kholmanskikh
2013-12-02 18:27 ` chrubis
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox