Skip to contentSkip to conversation

autoconf check for utimensat(2)

PATCH In review Stanislav Kholmanskikh 2 participants 4 messages Dec 4, 2013 – Dec 6, 2013 1 message not in the archive Library code

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v3 1/3 autoconf check for utimensat(2)

Unfortunately, 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
index 4846afd..4af7662 100644
@@ -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
#2 lore raw

PATCH v3 2/3 created lapi/utime.h

In reply to a message not in the archive

And 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
new file mode 100644
index 0000000..4209d4c
@@ -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
#3 lore raw

PATCH v3 3/3 safe_touch: use utimes(2) if utimensat(2) is not defined

In reply to a message not in the archive

If 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
index 77ad594..1815984 100644
@@ -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
#4 lore raw

Re: [LTP] [PATCH V3 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined

Hi!

Quoted 50 lines

If 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
index 77ad594..1815984 100644
@@ -36,6 +36,7 @@
 
 #include <sys/stat.h>
 
+#include "lapi/utime.h"
 #include "test.h"
 
 /*
lib/safe_file_ops.c +9 -0
index 8cfd264..f9c316d 100644
@@ -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 -0
 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);

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