public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH V3 1/3] autoconf check for utimensat(2)
       [not found] <529D7CFE.9090104@oracle.com>
@ 2013-12-04 12:16 ` Stanislav Kholmanskikh
  2013-12-04 12:16 ` [LTP] [PATCH V3 2/3] created lapi/utime.h Stanislav Kholmanskikh
  2013-12-04 12:16 ` [LTP] [PATCH V3 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined Stanislav Kholmanskikh
  2 siblings, 0 replies; 4+ messages in thread
From: Stanislav Kholmanskikh @ 2013-12-04 12:16 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


------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [LTP] [PATCH V3 2/3] created lapi/utime.h
       [not found] <529D7CFE.9090104@oracle.com>
  2013-12-04 12:16 ` [LTP] [PATCH V3 1/3] autoconf check for utimensat(2) Stanislav Kholmanskikh
@ 2013-12-04 12:16 ` Stanislav Kholmanskikh
  2013-12-04 12:16 ` [LTP] [PATCH V3 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined Stanislav Kholmanskikh
  2 siblings, 0 replies; 4+ messages in thread
From: Stanislav Kholmanskikh @ 2013-12-04 12:16 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


------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [LTP] [PATCH V3 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined
       [not found] <529D7CFE.9090104@oracle.com>
  2013-12-04 12:16 ` [LTP] [PATCH V3 1/3] autoconf check for utimensat(2) Stanislav Kholmanskikh
  2013-12-04 12:16 ` [LTP] [PATCH V3 2/3] created lapi/utime.h Stanislav Kholmanskikh
@ 2013-12-04 12:16 ` Stanislav Kholmanskikh
  2013-12-06 15:42   ` chrubis
  2 siblings, 1 reply; 4+ messages in thread
From: Stanislav Kholmanskikh @ 2013-12-04 12:16 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, 52 insertions(+), 2 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..f9c316d 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"
 
@@ -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:
+	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;
+	}
+}
+
 void 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);
+		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",
 			pathname, file, lineno);
 }
-
-- 
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH V3 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined
  2013-12-04 12:16 ` [LTP] [PATCH V3 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined Stanislav Kholmanskikh
@ 2013-12-06 15:42   ` chrubis
  0 siblings, 0 replies; 4+ messages in thread
From: chrubis @ 2013-12-06 15:42 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, 52 insertions(+), 2 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..f9c316d 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"
>  
> @@ -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:
> +	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.

>  void 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);
> +		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.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-12-06 15:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <529D7CFE.9090104@oracle.com>
2013-12-04 12:16 ` [LTP] [PATCH V3 1/3] autoconf check for utimensat(2) Stanislav Kholmanskikh
2013-12-04 12:16 ` [LTP] [PATCH V3 2/3] created lapi/utime.h Stanislav Kholmanskikh
2013-12-04 12:16 ` [LTP] [PATCH V3 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined Stanislav Kholmanskikh
2013-12-06 15:42   ` chrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox