[PATCH v4 7/8] tests/sockopt-timestamp: Use the old time_t struct for old timestamps

Dmitry V. Levin ldv at altlinux.org
Tue Mar 10 01:55:30 UTC 2020


On Mon, Mar 09, 2020 at 05:43:03PM -0700, Alistair Francis wrote:
> 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..18301e1a 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_timespec_t ts;

This doesn't look correct, the type has to be struct __kernel_old_timespec
or equivalent.


-- 
ldv


More information about the Strace-devel mailing list