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

Alistair Francis alistair23 at gmail.com
Tue Mar 10 18:13:25 UTC 2020


On Mon, Mar 9, 2020 at 6:55 PM Dmitry V. Levin <ldv at altlinux.org> wrote:
>
> 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.

I just updated my kernel source, so now I do have struct __kernel_old_timespec.

This struct is the same though:

struct __kernel_old_timespec {
    __kernel_old_time_t    tv_sec;        /* seconds */
    long            tv_nsec;    /* nanoseconds */
};

Where:

typedef __kernel_long_t    __kernel_old_time_t;

Alistair

>
>
> --
> ldv


More information about the Strace-devel mailing list