[v2,4/5] y2038: nscd: Modify nscd_helper to use __clock_gettime64

Message ID 20200326080641.10193-5-lukma@denx.de
State Committed
Commit 481d01fa2b07d3c6f9e6ef9ae239bc616b1ac757
Headers
Series y2038: Replace __clock_gettime with __clock_gettime64 |

Commit Message

Lukasz Majewski March 26, 2020, 8:06 a.m. UTC
  The nscd/nscd_helper.c uses __clock_gettime to get current time and on this
basis calculate the relative timeout for poll.
By using __clock_gettime64 on systems with __WORDSIZE == 32 && __TIMESIZE != 64
the timeout is correctly calculated after time_t overflow.
---
 nscd/nscd_helper.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
  

Comments

Adhemerval Zanella Netto April 30, 2020, 8:54 p.m. UTC | #1
On 26/03/2020 05:06, Lukasz Majewski wrote:
> The nscd/nscd_helper.c uses __clock_gettime to get current time and on this
> basis calculate the relative timeout for poll.
> By using __clock_gettime64 on systems with __WORDSIZE == 32 && __TIMESIZE != 64
> the timeout is correctly calculated after time_t overflow.

LGTM, thanks.

> ---
>  nscd/nscd_helper.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
> index d2d7d15f26..a4f3312f90 100644
> --- a/nscd/nscd_helper.c
> +++ b/nscd/nscd_helper.c
> @@ -37,6 +37,7 @@
>  #include <not-cancel.h>
>  #include <kernel-features.h>
>  #include <nss.h>
> +#include <struct___timespec64.h>
>  
>  #include "nscd-client.h"
>  
> @@ -59,10 +60,10 @@ wait_on_socket (int sock, long int usectmo)
>        /* Handle the case where the poll() call is interrupted by a
>  	 signal.  We cannot just use TEMP_FAILURE_RETRY since it might
>  	 lead to infinite loops.  */
> -      struct timespec now;
> -      __clock_gettime (CLOCK_REALTIME, &now);
> -      long int end = (now.tv_sec * 1000 + usectmo
> -                      + (now.tv_nsec + 500000) / 1000000);
> +      struct __timespec64 now;
> +      __clock_gettime64 (CLOCK_REALTIME, &now);
> +      int64_t end = (now.tv_sec * 1000 + usectmo
> +                     + (now.tv_nsec + 500000) / 1000000);
>        long int timeout = usectmo;
>        while (1)
>  	{

Ok. Maybe we could use ppoll instead here to simplify the timeout
calculation?

> @@ -71,7 +72,7 @@ wait_on_socket (int sock, long int usectmo)
>  	    break;
>  
>  	  /* Recompute the timeout time.  */
> -          __clock_gettime (CLOCK_REALTIME, &now);
> +          __clock_gettime64 (CLOCK_REALTIME, &now);
>  	  timeout = end - ((now.tv_sec * 1000
>                              + (now.tv_nsec + 500000) / 1000000));
>  	}

Ok.

> @@ -193,7 +194,7 @@ open_socket (request_type type, const char *key, size_t keylen)
>    memcpy (reqdata->key, key, keylen);
>  
>    bool first_try = true;
> -  struct timespec tvend = { 0, 0 };
> +  struct __timespec64 tvend = { 0, 0 };
>    while (1)
>      {

Ok.

>  #ifndef MSG_NOSIGNAL
> @@ -212,8 +213,8 @@ open_socket (request_type type, const char *key, size_t keylen)
>  
>        /* The daemon is busy wait for it.  */
>        int to;
> -      struct timespec now;
> -      __clock_gettime (CLOCK_REALTIME, &now);
> +      struct __timespec64 now;
> +      __clock_gettime64 (CLOCK_REALTIME, &now);
>        if (first_try)
>  	{
>  	  tvend.tv_nsec = now.tv_nsec;
> 

Ok.
  
Lukasz Majewski May 1, 2020, 11:30 a.m. UTC | #2
Hi Adhemerval,

> On 26/03/2020 05:06, Lukasz Majewski wrote:
> > The nscd/nscd_helper.c uses __clock_gettime to get current time and
> > on this basis calculate the relative timeout for poll.
> > By using __clock_gettime64 on systems with __WORDSIZE == 32 &&
> > __TIMESIZE != 64 the timeout is correctly calculated after time_t
> > overflow.  
> 
> LGTM, thanks.
> 
> > ---
> >  nscd/nscd_helper.c | 17 +++++++++--------
> >  1 file changed, 9 insertions(+), 8 deletions(-)
> > 
> > diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
> > index d2d7d15f26..a4f3312f90 100644
> > --- a/nscd/nscd_helper.c
> > +++ b/nscd/nscd_helper.c
> > @@ -37,6 +37,7 @@
> >  #include <not-cancel.h>
> >  #include <kernel-features.h>
> >  #include <nss.h>
> > +#include <struct___timespec64.h>
> >  
> >  #include "nscd-client.h"
> >  
> > @@ -59,10 +60,10 @@ wait_on_socket (int sock, long int usectmo)
> >        /* Handle the case where the poll() call is interrupted by a
> >  	 signal.  We cannot just use TEMP_FAILURE_RETRY since it
> > might lead to infinite loops.  */
> > -      struct timespec now;
> > -      __clock_gettime (CLOCK_REALTIME, &now);
> > -      long int end = (now.tv_sec * 1000 + usectmo
> > -                      + (now.tv_nsec + 500000) / 1000000);
> > +      struct __timespec64 now;
> > +      __clock_gettime64 (CLOCK_REALTIME, &now);
> > +      int64_t end = (now.tv_sec * 1000 + usectmo
> > +                     + (now.tv_nsec + 500000) / 1000000);
> >        long int timeout = usectmo;
> >        while (1)
> >  	{  
> 
> Ok. Maybe we could use ppoll instead here to simplify the timeout
> calculation?
> 

I wanted to change as little as possible (to not introduce any extra
bugs) to only replace __clock_gettime with __clock_gettime64. 

> > @@ -71,7 +72,7 @@ wait_on_socket (int sock, long int usectmo)
> >  	    break;
> >  
> >  	  /* Recompute the timeout time.  */
> > -          __clock_gettime (CLOCK_REALTIME, &now);
> > +          __clock_gettime64 (CLOCK_REALTIME, &now);
> >  	  timeout = end - ((now.tv_sec * 1000
> >                              + (now.tv_nsec + 500000) / 1000000));
> >  	}  
> 
> Ok.
> 
> > @@ -193,7 +194,7 @@ open_socket (request_type type, const char
> > *key, size_t keylen) memcpy (reqdata->key, key, keylen);
> >  
> >    bool first_try = true;
> > -  struct timespec tvend = { 0, 0 };
> > +  struct __timespec64 tvend = { 0, 0 };
> >    while (1)
> >      {  
> 
> Ok.
> 
> >  #ifndef MSG_NOSIGNAL
> > @@ -212,8 +213,8 @@ open_socket (request_type type, const char
> > *key, size_t keylen) 
> >        /* The daemon is busy wait for it.  */
> >        int to;
> > -      struct timespec now;
> > -      __clock_gettime (CLOCK_REALTIME, &now);
> > +      struct __timespec64 now;
> > +      __clock_gettime64 (CLOCK_REALTIME, &now);
> >        if (first_try)
> >  	{
> >  	  tvend.tv_nsec = now.tv_nsec;
> >   
> 
> Ok.




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
  
Adhemerval Zanella Netto May 4, 2020, 12:27 p.m. UTC | #3
On 01/05/2020 08:30, Lukasz Majewski wrote:
> Hi Adhemerval,
> 
>> On 26/03/2020 05:06, Lukasz Majewski wrote:
>>> The nscd/nscd_helper.c uses __clock_gettime to get current time and
>>> on this basis calculate the relative timeout for poll.
>>> By using __clock_gettime64 on systems with __WORDSIZE == 32 &&
>>> __TIMESIZE != 64 the timeout is correctly calculated after time_t
>>> overflow.  
>>
>> LGTM, thanks.
>>
>>> ---
>>>  nscd/nscd_helper.c | 17 +++++++++--------
>>>  1 file changed, 9 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
>>> index d2d7d15f26..a4f3312f90 100644
>>> --- a/nscd/nscd_helper.c
>>> +++ b/nscd/nscd_helper.c
>>> @@ -37,6 +37,7 @@
>>>  #include <not-cancel.h>
>>>  #include <kernel-features.h>
>>>  #include <nss.h>
>>> +#include <struct___timespec64.h>
>>>  
>>>  #include "nscd-client.h"
>>>  
>>> @@ -59,10 +60,10 @@ wait_on_socket (int sock, long int usectmo)
>>>        /* Handle the case where the poll() call is interrupted by a
>>>  	 signal.  We cannot just use TEMP_FAILURE_RETRY since it
>>> might lead to infinite loops.  */
>>> -      struct timespec now;
>>> -      __clock_gettime (CLOCK_REALTIME, &now);
>>> -      long int end = (now.tv_sec * 1000 + usectmo
>>> -                      + (now.tv_nsec + 500000) / 1000000);
>>> +      struct __timespec64 now;
>>> +      __clock_gettime64 (CLOCK_REALTIME, &now);
>>> +      int64_t end = (now.tv_sec * 1000 + usectmo
>>> +                     + (now.tv_nsec + 500000) / 1000000);
>>>        long int timeout = usectmo;
>>>        while (1)
>>>  	{  
>>
>> Ok. Maybe we could use ppoll instead here to simplify the timeout
>> calculation?
>>
> 
> I wanted to change as little as possible (to not introduce any extra
> bugs) to only replace __clock_gettime with __clock_gettime64. 

I don't have a strong opinion here, it is just that it might simplifies
a bit the timeout handling.

> 
>>> @@ -71,7 +72,7 @@ wait_on_socket (int sock, long int usectmo)
>>>  	    break;
>>>  
>>>  	  /* Recompute the timeout time.  */
>>> -          __clock_gettime (CLOCK_REALTIME, &now);
>>> +          __clock_gettime64 (CLOCK_REALTIME, &now);
>>>  	  timeout = end - ((now.tv_sec * 1000
>>>                              + (now.tv_nsec + 500000) / 1000000));
>>>  	}  
>>
>> Ok.
>>
>>> @@ -193,7 +194,7 @@ open_socket (request_type type, const char
>>> *key, size_t keylen) memcpy (reqdata->key, key, keylen);
>>>  
>>>    bool first_try = true;
>>> -  struct timespec tvend = { 0, 0 };
>>> +  struct __timespec64 tvend = { 0, 0 };
>>>    while (1)
>>>      {  
>>
>> Ok.
>>
>>>  #ifndef MSG_NOSIGNAL
>>> @@ -212,8 +213,8 @@ open_socket (request_type type, const char
>>> *key, size_t keylen) 
>>>        /* The daemon is busy wait for it.  */
>>>        int to;
>>> -      struct timespec now;
>>> -      __clock_gettime (CLOCK_REALTIME, &now);
>>> +      struct __timespec64 now;
>>> +      __clock_gettime64 (CLOCK_REALTIME, &now);
>>>        if (first_try)
>>>  	{
>>>  	  tvend.tv_nsec = now.tv_nsec;
>>>   
>>
>> Ok.
> 
> 
> 
> 
> Best regards,
> 
> Lukasz Majewski
> 
> --
> 
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
>
  
Lukasz Majewski May 4, 2020, 3:26 p.m. UTC | #4
Hi Adhemerval,

> On 01/05/2020 08:30, Lukasz Majewski wrote:
> > Hi Adhemerval,
> >   
> >> On 26/03/2020 05:06, Lukasz Majewski wrote:  
> >>> The nscd/nscd_helper.c uses __clock_gettime to get current time
> >>> and on this basis calculate the relative timeout for poll.
> >>> By using __clock_gettime64 on systems with __WORDSIZE == 32 &&
> >>> __TIMESIZE != 64 the timeout is correctly calculated after time_t
> >>> overflow.    
> >>
> >> LGTM, thanks.
> >>  
> >>> ---
> >>>  nscd/nscd_helper.c | 17 +++++++++--------
> >>>  1 file changed, 9 insertions(+), 8 deletions(-)
> >>>
> >>> diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
> >>> index d2d7d15f26..a4f3312f90 100644
> >>> --- a/nscd/nscd_helper.c
> >>> +++ b/nscd/nscd_helper.c
> >>> @@ -37,6 +37,7 @@
> >>>  #include <not-cancel.h>
> >>>  #include <kernel-features.h>
> >>>  #include <nss.h>
> >>> +#include <struct___timespec64.h>
> >>>  
> >>>  #include "nscd-client.h"
> >>>  
> >>> @@ -59,10 +60,10 @@ wait_on_socket (int sock, long int usectmo)
> >>>        /* Handle the case where the poll() call is interrupted by
> >>> a signal.  We cannot just use TEMP_FAILURE_RETRY since it
> >>> might lead to infinite loops.  */
> >>> -      struct timespec now;
> >>> -      __clock_gettime (CLOCK_REALTIME, &now);
> >>> -      long int end = (now.tv_sec * 1000 + usectmo
> >>> -                      + (now.tv_nsec + 500000) / 1000000);
> >>> +      struct __timespec64 now;
> >>> +      __clock_gettime64 (CLOCK_REALTIME, &now);
> >>> +      int64_t end = (now.tv_sec * 1000 + usectmo
> >>> +                     + (now.tv_nsec + 500000) / 1000000);
> >>>        long int timeout = usectmo;
> >>>        while (1)
> >>>  	{    
> >>
> >> Ok. Maybe we could use ppoll instead here to simplify the timeout
> >> calculation?
> >>  
> > 
> > I wanted to change as little as possible (to not introduce any extra
> > bugs) to only replace __clock_gettime with __clock_gettime64.   
> 
> I don't have a strong opinion here, it is just that it might
> simplifies a bit the timeout handling.

If you don't mind I would prefer to change as little as possible and
stick to the approach (changes) proposed in this patch.

Do you agree with such approach?

> 
> >   
> >>> @@ -71,7 +72,7 @@ wait_on_socket (int sock, long int usectmo)
> >>>  	    break;
> >>>  
> >>>  	  /* Recompute the timeout time.  */
> >>> -          __clock_gettime (CLOCK_REALTIME, &now);
> >>> +          __clock_gettime64 (CLOCK_REALTIME, &now);
> >>>  	  timeout = end - ((now.tv_sec * 1000
> >>>                              + (now.tv_nsec + 500000) / 1000000));
> >>>  	}    
> >>
> >> Ok.
> >>  
> >>> @@ -193,7 +194,7 @@ open_socket (request_type type, const char
> >>> *key, size_t keylen) memcpy (reqdata->key, key, keylen);
> >>>  
> >>>    bool first_try = true;
> >>> -  struct timespec tvend = { 0, 0 };
> >>> +  struct __timespec64 tvend = { 0, 0 };
> >>>    while (1)
> >>>      {    
> >>
> >> Ok.
> >>  
> >>>  #ifndef MSG_NOSIGNAL
> >>> @@ -212,8 +213,8 @@ open_socket (request_type type, const char
> >>> *key, size_t keylen) 
> >>>        /* The daemon is busy wait for it.  */
> >>>        int to;
> >>> -      struct timespec now;
> >>> -      __clock_gettime (CLOCK_REALTIME, &now);
> >>> +      struct __timespec64 now;
> >>> +      __clock_gettime64 (CLOCK_REALTIME, &now);
> >>>        if (first_try)
> >>>  	{
> >>>  	  tvend.tv_nsec = now.tv_nsec;
> >>>     
> >>
> >> Ok.  
> > 
> > 
> > 
> > 
> > Best regards,
> > 
> > Lukasz Majewski
> > 
> > --
> > 
> > DENX Software Engineering GmbH,      Managing Director: Wolfgang
> > Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell,
> > Germany Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
> > lukma@denx.de 
> 




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
  
Adhemerval Zanella Netto May 4, 2020, 4:36 p.m. UTC | #5
On 04/05/2020 12:26, Lukasz Majewski wrote:
> Hi Adhemerval,
> 
>> On 01/05/2020 08:30, Lukasz Majewski wrote:
>>> Hi Adhemerval,
>>>   
>>>> On 26/03/2020 05:06, Lukasz Majewski wrote:  
>>>>> The nscd/nscd_helper.c uses __clock_gettime to get current time
>>>>> and on this basis calculate the relative timeout for poll.
>>>>> By using __clock_gettime64 on systems with __WORDSIZE == 32 &&
>>>>> __TIMESIZE != 64 the timeout is correctly calculated after time_t
>>>>> overflow.    
>>>>
>>>> LGTM, thanks.
>>>>  
>>>>> ---
>>>>>  nscd/nscd_helper.c | 17 +++++++++--------
>>>>>  1 file changed, 9 insertions(+), 8 deletions(-)
>>>>>
>>>>> diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
>>>>> index d2d7d15f26..a4f3312f90 100644
>>>>> --- a/nscd/nscd_helper.c
>>>>> +++ b/nscd/nscd_helper.c
>>>>> @@ -37,6 +37,7 @@
>>>>>  #include <not-cancel.h>
>>>>>  #include <kernel-features.h>
>>>>>  #include <nss.h>
>>>>> +#include <struct___timespec64.h>
>>>>>  
>>>>>  #include "nscd-client.h"
>>>>>  
>>>>> @@ -59,10 +60,10 @@ wait_on_socket (int sock, long int usectmo)
>>>>>        /* Handle the case where the poll() call is interrupted by
>>>>> a signal.  We cannot just use TEMP_FAILURE_RETRY since it
>>>>> might lead to infinite loops.  */
>>>>> -      struct timespec now;
>>>>> -      __clock_gettime (CLOCK_REALTIME, &now);
>>>>> -      long int end = (now.tv_sec * 1000 + usectmo
>>>>> -                      + (now.tv_nsec + 500000) / 1000000);
>>>>> +      struct __timespec64 now;
>>>>> +      __clock_gettime64 (CLOCK_REALTIME, &now);
>>>>> +      int64_t end = (now.tv_sec * 1000 + usectmo
>>>>> +                     + (now.tv_nsec + 500000) / 1000000);
>>>>>        long int timeout = usectmo;
>>>>>        while (1)
>>>>>  	{    
>>>>
>>>> Ok. Maybe we could use ppoll instead here to simplify the timeout
>>>> calculation?
>>>>  
>>>
>>> I wanted to change as little as possible (to not introduce any extra
>>> bugs) to only replace __clock_gettime with __clock_gettime64.   
>>
>> I don't have a strong opinion here, it is just that it might
>> simplifies a bit the timeout handling.
> 
> If you don't mind I would prefer to change as little as possible and
> stick to the approach (changes) proposed in this patch.
> 
> Do you agree with such approach?

Ack.
  

Patch

diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
index d2d7d15f26..a4f3312f90 100644
--- a/nscd/nscd_helper.c
+++ b/nscd/nscd_helper.c
@@ -37,6 +37,7 @@ 
 #include <not-cancel.h>
 #include <kernel-features.h>
 #include <nss.h>
+#include <struct___timespec64.h>
 
 #include "nscd-client.h"
 
@@ -59,10 +60,10 @@  wait_on_socket (int sock, long int usectmo)
       /* Handle the case where the poll() call is interrupted by a
 	 signal.  We cannot just use TEMP_FAILURE_RETRY since it might
 	 lead to infinite loops.  */
-      struct timespec now;
-      __clock_gettime (CLOCK_REALTIME, &now);
-      long int end = (now.tv_sec * 1000 + usectmo
-                      + (now.tv_nsec + 500000) / 1000000);
+      struct __timespec64 now;
+      __clock_gettime64 (CLOCK_REALTIME, &now);
+      int64_t end = (now.tv_sec * 1000 + usectmo
+                     + (now.tv_nsec + 500000) / 1000000);
       long int timeout = usectmo;
       while (1)
 	{
@@ -71,7 +72,7 @@  wait_on_socket (int sock, long int usectmo)
 	    break;
 
 	  /* Recompute the timeout time.  */
-          __clock_gettime (CLOCK_REALTIME, &now);
+          __clock_gettime64 (CLOCK_REALTIME, &now);
 	  timeout = end - ((now.tv_sec * 1000
                             + (now.tv_nsec + 500000) / 1000000));
 	}
@@ -193,7 +194,7 @@  open_socket (request_type type, const char *key, size_t keylen)
   memcpy (reqdata->key, key, keylen);
 
   bool first_try = true;
-  struct timespec tvend = { 0, 0 };
+  struct __timespec64 tvend = { 0, 0 };
   while (1)
     {
 #ifndef MSG_NOSIGNAL
@@ -212,8 +213,8 @@  open_socket (request_type type, const char *key, size_t keylen)
 
       /* The daemon is busy wait for it.  */
       int to;
-      struct timespec now;
-      __clock_gettime (CLOCK_REALTIME, &now);
+      struct __timespec64 now;
+      __clock_gettime64 (CLOCK_REALTIME, &now);
       if (first_try)
 	{
 	  tvend.tv_nsec = now.tv_nsec;