diff mbox series

tools/xenstore/xenstored_control.c: correctly print time_t

Message ID 20230412090104.3794213-1-alex@linutronix.de (mailing list archive)
State Superseded
Headers show
Series tools/xenstore/xenstored_control.c: correctly print time_t | expand

Commit Message

Alexander Kanavin April 12, 2023, 9:01 a.m. UTC
On 32 bit systems with 64 bit time_t (hello, Y2038 problem),
the following error occurs otherwise:

| xenstored_control.c: In function 'lu_reject_reason':
| xenstored_control.c:646:70: error: format '%ld' expects argument of type 'long int', but argument 5 has type 'time_t' {aka 'long long int'} [-Werror=format=]

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
 tools/xenstore/xenstored_control.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jürgen Groß April 17, 2023, 6:35 a.m. UTC | #1
On 12.04.23 11:01, Alexander Kanavin wrote:
> On 32 bit systems with 64 bit time_t (hello, Y2038 problem),
> the following error occurs otherwise:
> 
> | xenstored_control.c: In function 'lu_reject_reason':
> | xenstored_control.c:646:70: error: format '%ld' expects argument of type 'long int', but argument 5 has type 'time_t' {aka 'long long int'} [-Werror=format=]
> 
> Signed-off-by: Alexander Kanavin <alex@linutronix.de>
> ---
>   tools/xenstore/xenstored_control.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_control.c
> index cbd62556c3..8683947d25 100644
> --- a/tools/xenstore/xenstored_control.c
> +++ b/tools/xenstore/xenstored_control.c
> @@ -668,10 +668,10 @@ static const char *lu_reject_reason(const void *ctx)
>   	list_for_each_entry(conn, &connections, list) {
>   		if (conn->ta_start_time &&
>   		    (now - conn->ta_start_time >= lu_status->timeout)) {
> -			ret = talloc_asprintf(ctx, "%s\nDomain %u: %ld s",
> +			ret = talloc_asprintf(ctx, "%s\nDomain %u: %jd s",
>   					      ret ? : "Domains with long running transactions:",
>   					      conn->id,
> -					      now - conn->ta_start_time);
> +					      (intmax_t)now - conn->ta_start_time);
>   		}
>   	}
>   

I'd rather have something like:

diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_control.c
index cbd62556c3..f9452d63b4 100644
--- a/tools/xenstore/xenstored_control.c
+++ b/tools/xenstore/xenstored_control.c
@@ -666,12 +666,12 @@ static const char *lu_reject_reason(const void *ctx)
         time_t now = time(NULL);

         list_for_each_entry(conn, &connections, list) {
-               if (conn->ta_start_time &&
-                   (now - conn->ta_start_time >= lu_status->timeout)) {
+               unsigned long tdiff = now - conn->ta_start_time;
+
+               if (conn->ta_start_time && tdiff >= lu_status->timeout) {
                         ret = talloc_asprintf(ctx, "%s\nDomain %u: %ld s",
                                               ret ? : "Domains with long 
running transactions:",
-                                             conn->id,
-                                             now - conn->ta_start_time);
+                                             conn->id, tdiff);
                 }
         }


Juergen
Alexander Kanavin April 19, 2023, 12:08 p.m. UTC | #2
On 4/17/23 08:35, Juergen Gross wrote:
>
> I'd rather have something like:
>
> diff --git a/tools/xenstore/xenstored_control.c 
> b/tools/xenstore/xenstored_control.c
> index cbd62556c3..f9452d63b4 100644
> --- a/tools/xenstore/xenstored_control.c
> +++ b/tools/xenstore/xenstored_control.c
> @@ -666,12 +666,12 @@ static const char *lu_reject_reason(const void 
> *ctx)
>         time_t now = time(NULL);
>
>         list_for_each_entry(conn, &connections, list) {
> -               if (conn->ta_start_time &&
> -                   (now - conn->ta_start_time >= lu_status->timeout)) {
> +               unsigned long tdiff = now - conn->ta_start_time;
> +
> +               if (conn->ta_start_time && tdiff >= lu_status->timeout) {
>                         ret = talloc_asprintf(ctx, "%s\nDomain %u: %ld 
> s",
>                                               ret ? : "Domains with 
> long running transactions:",
> -                                             conn->id,
> -                                             now - conn->ta_start_time);
> +                                             conn->id, tdiff);
>                 }
>         }


Thanks, I just sent a v2 that does this.
diff mbox series

Patch

diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_control.c
index cbd62556c3..8683947d25 100644
--- a/tools/xenstore/xenstored_control.c
+++ b/tools/xenstore/xenstored_control.c
@@ -668,10 +668,10 @@  static const char *lu_reject_reason(const void *ctx)
 	list_for_each_entry(conn, &connections, list) {
 		if (conn->ta_start_time &&
 		    (now - conn->ta_start_time >= lu_status->timeout)) {
-			ret = talloc_asprintf(ctx, "%s\nDomain %u: %ld s",
+			ret = talloc_asprintf(ctx, "%s\nDomain %u: %jd s",
 					      ret ? : "Domains with long running transactions:",
 					      conn->id,
-					      now - conn->ta_start_time);
+					      (intmax_t)now - conn->ta_start_time);
 		}
 	}