[PATCH v6 08/13] tests/sockopt-timestamp: Use the old time_t struct for old timestamps

Alistair Francis alistair.francis at wdc.com
Fri Mar 20 22:09:34 UTC 2020


The SO_TIMESTAMP_OLD returns a timeval that matches the struct
kernel_old_timeval_t instead of the struct timeval. This is different
on new 32-bit architectures (like RV32) where timeval uses 64-bit time_t
while kernel_old_timeval_t uses 32-bit.

To fix overflow errors let's case the data to a struct
kernel_old_timeval_t instead of the libc stuct timeval.

Signed-off-by: Alistair Francis <alistair.francis at wdc.com>
---
 tests/sockopt-timestamp.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tests/sockopt-timestamp.c b/tests/sockopt-timestamp.c
index fd332ec2..a1b20f05 100644
--- a/tests/sockopt-timestamp.c
+++ b/tests/sockopt-timestamp.c
@@ -23,12 +23,15 @@
 #include "xlat/sock_options.h"
 #undef XLAT_MACROS_ONLY
 
+# include "kernel_timeval.h"
+# include "kernel_timespec.h"
+
 static void
 print_timestamp_old(const struct cmsghdr *c)
 {
 	const void *cmsg_header = c;
 	const void *cmsg_data = CMSG_DATA(c);
-	struct timeval tv;
+	kernel_old_timeval_t tv;
 	const unsigned int expected_len = sizeof(tv);
 	const unsigned int data_len = c->cmsg_len - (cmsg_data - cmsg_header);
 
@@ -47,7 +50,7 @@ print_timestampns_old(const struct cmsghdr *c)
 {
 	const void *cmsg_header = c;
 	const void *cmsg_data = CMSG_DATA(c);
-	struct timespec ts;
+	kernel_old_timespec_t ts;
 	const unsigned int expected_len = sizeof(ts);
 	const unsigned int data_len = c->cmsg_len - (cmsg_data - cmsg_header);
 
-- 
2.25.1



More information about the Strace-devel mailing list