Skip to contentSkip to conversation

migration: Remove time_t cast for OpenBSD

PATCH In review Brad Smith 5 participants 10 messages Feb 22, 2021 – Apr 1, 2021

lore
Share & tools
lore

Brad Smith

author
#0 lore raw

PATCH 1/1 migration: Remove time_t cast for OpenBSD

OpenBSD has supported 64-bit time_t across all archs since 5.5 released in 2014.

Remove a time_t cast that is no longer necessary.

migration/savevm.c +1 -2
index 52e2d72e4b..9557f85ba9 100644
@@ -2849,8 +2849,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate,
     if (name) {
         pstrcpy(sn->name, sizeof(sn->name), name);
     } else {
-        /* cast below needed for OpenBSD where tv_sec is still 'long' */
-        localtime_r((const time_t *)&tv.tv_sec, &tm);
+        localtime_r(&tv.tv_sec, &tm);
         strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", &tm);
     }
 
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Brad Smith

OpenBSD has supported 64-bit time_t across all archs since 5.5 released in 2014.

Remove a time_t cast that is no longer necessary.

migration/savevm.c +0 -0
index 52e2d72e4b..9557f85ba9 100644

migration/savevm.c bool save_snapshot(const char *name, bool overwrite, const char *vmstate, · line 2854

Quoted 8 lines
migration/savevm.c +1 -2
@@ -2849,8 +2849,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate,
      if (name) {
          pstrcpy(sn->name, sizeof(sn->name), name);
      } else {
-        /* cast below needed for OpenBSD where tv_sec is still 'long' */
-        localtime_r((const time_t *)&tv.tv_sec, &tm);
+        localtime_r(&tv.tv_sec, &tm);
          strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", &tm);
      }

Please make sure to CC: the maintainers (see MAINTAINERS file). Done now.

#2 lore raw

Le 08/03/2021 à 12:46, Thomas Huth a écrit :

Quoted 8 lines · Brad Smith
Quoted 7 lines

OpenBSD has supported 64-bit time_t across all archs since 5.5 released in 2014.

Remove a time_t cast that is no longer necessary.

Quoted 14 lines

migration/savevm.c bool save_snapshot(const char *name, bool overwrite, const char *vmstate, · line 2854

Quoted 13 lines
migration/savevm.c +1 -2
index 52e2d72e4b..9557f85ba9 100644
@@ -2849,8 +2849,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate,
       if (name) {
           pstrcpy(sn->name, sizeof(sn->name), name);
       } else {
-        /* cast below needed for OpenBSD where tv_sec is still 'long' */
-        localtime_r((const time_t *)&tv.tv_sec, &tm);
+        localtime_r(&tv.tv_sec, &tm);
           strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", &tm);
       }

but the qemu_timeval from "include/sysemu/os-win32.h" still uses a long: is this file compiled for win32?

Thanks,
Laurent

#3 lore raw
Quoted 24 lines · * Laurent Vivier ([email protected]) wrote:

Le 08/03/2021 à 12:46, Thomas Huth a écrit :

Quoted 8 lines · Brad Smith
Quoted 7 lines

OpenBSD has supported 64-bit time_t across all archs since 5.5 released in 2014.

Remove a time_t cast that is no longer necessary.

Quoted 14 lines

migration/savevm.c bool save_snapshot(const char *name, bool overwrite, const char *vmstate, · line 2854

Quoted 13 lines
migration/savevm.c +1 -2
index 52e2d72e4b..9557f85ba9 100644
@@ -2849,8 +2849,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate,
       if (name) {
           pstrcpy(sn->name, sizeof(sn->name), name);
       } else {
-        /* cast below needed for OpenBSD where tv_sec is still 'long' */
-        localtime_r((const time_t *)&tv.tv_sec, &tm);
+        localtime_r(&tv.tv_sec, &tm);
           strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", &tm);
       }
Quoted 2 lines

but the qemu_timeval from "include/sysemu/os-win32.h" still uses a long: is this file compiled for win32?

Yep this fails for me when built with x86_64-w64-mingw32- (it's fine with i686-w64-mingw32- )

Dave

Quoted 3 lines

Thanks,
Laurent

Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#4 lore raw
Quoted 25 lines · Dr. David Alan Gilbert
Quoted 24 lines · * Laurent Vivier ([email protected]) wrote:

Le 08/03/2021 à 12:46, Thomas Huth a écrit :

Quoted 22 lines · Brad Smith
Quoted 20 lines

OpenBSD has supported 64-bit time_t across all archs since 5.5 released in 2014.

Remove a time_t cast that is no longer necessary.

migration/savevm.c +1 -2
index 52e2d72e4b..9557f85ba9 100644
@@ -2849,8 +2849,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate,
       if (name) {
           pstrcpy(sn->name, sizeof(sn->name), name);
       } else {
-        /* cast below needed for OpenBSD where tv_sec is still 'long' */
-        localtime_r((const time_t *)&tv.tv_sec, &tm);
+        localtime_r(&tv.tv_sec, &tm);
           strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", &tm);
       }
Quoted 5 lines
Quoted 2 lines

but the qemu_timeval from "include/sysemu/os-win32.h" still uses a long: is this file compiled for win32?

Yep this fails for me when built with x86_64-w64-mingw32- (it's fine with i686-w64-mingw32- )

We could just switch the code to use GDateTime from GLib and thus avoid portability issues. I think this should be equivalent:

     g_autoptr(GDateTime) now = g_date_time_new_now_local();
     g_autofree char *nowstr = g_date_time_format(now, "vm-%Y%m%d%H%M%s");
     strncpy(sn->name, sizeof(sn->name), nowstr);

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
author
#5 lore raw
Quoted 26 lines · Daniel P. Berrangé
Quoted 25 lines · Dr. David Alan Gilbert
Quoted 24 lines · * Laurent Vivier ([email protected]) wrote:

Le 08/03/2021 à 12:46, Thomas Huth a écrit :

Quoted 8 lines · Brad Smith
Quoted 7 lines

OpenBSD has supported 64-bit time_t across all archs since 5.5 released in 2014.

Remove a time_t cast that is no longer necessary.

Quoted 13 lines

migration/savevm.c bool save_snapshot(const char *name, bool overwrite, const char *vmstate, · line 2854

Quoted 13 lines
migration/savevm.c +1 -2
index 52e2d72e4b..9557f85ba9 100644
@@ -2849,8 +2849,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate,
       if (name) {
           pstrcpy(sn->name, sizeof(sn->name), name);
       } else {
-        /* cast below needed for OpenBSD where tv_sec is still 'long' */
-        localtime_r((const time_t *)&tv.tv_sec, &tm);
+        localtime_r(&tv.tv_sec, &tm);
           strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", &tm);
       }

but the qemu_timeval from "include/sysemu/os-win32.h" still uses a long: is this file compiled for win32?

Quoted 8 lines
Quoted 2 lines

Yep this fails for me when built with x86_64-w64-mingw32- (it's fine with i686-w64-mingw32- )

We could just switch the code to use GDateTime from GLib and thus avoid portability issues. I think this should be equivalent:

      g_autoptr(GDateTime) now = g_date_time_new_now_local();
      g_autofree char *nowstr = g_date_time_format(now, "vm-%Y%m%d%H%M%s");
      strncpy(sn->name, sizeof(sn->name), nowstr);

Which way do you guys want to go? Something like above, remove the comment or some variation on the comment but not mentioning OpenBSD since it is no longer relevant?

author
#6 lore raw
Quoted 34 lines · Brad Smith
Quoted 33 lines · Daniel P. Berrangé
Quoted 27 lines · Dr. David Alan Gilbert
Quoted 18 lines · * Laurent Vivier ([email protected]) wrote:

Le 08/03/2021 à 12:46, Thomas Huth a écrit :

Quoted 17 lines · Brad Smith
Quoted 16 lines

OpenBSD has supported 64-bit time_t across all archs since 5.5 released in 2014.

Remove a time_t cast that is no longer necessary.

migration/savevm.c +0 -0
index 52e2d72e4b..9557f85ba9 100644
@@ -2849,8 +2849,7 @@ bool save_snapshot(const char *name, bool 
 overwrite, const char *vmstate,
       if (name) {
           pstrcpy(sn->name, sizeof(sn->name), name);
       } else {
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
migration/savevm.c +0 -1
-        /* cast below needed for OpenBSD where tv_sec is 

still 'long' */
-        localtime_r((const time_t *)&tv.tv_sec, &tm);
+        localtime_r(&tv.tv_sec, &tm);
          strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", &tm); }

but the qemu_timeval from "include/sysemu/os-win32.h" still uses a long: is this file compiled for win32?

Quoted 2 lines

Yep this fails for me when built with x86_64-w64-mingw32- (it's fine with i686-w64-mingw32- )

We could just switch the code to use GDateTime from GLib and thus avoid portability issues. I think this should be equivalent:

Quoted 7 lines
Quoted 3 lines

      g_autoptr(GDateTime) now = g_date_time_new_now_local(); g_autofree char *nowstr = g_date_time_format(now, "vm-%Y%m%d%H%M%s"); strncpy(sn->name, sizeof(sn->name), nowstr);

Which way do you guys want to go? Something like above, remove the comment or some variation on the comment but not mentioning OpenBSD since it is no longer relevant?

Anyone?

#7 lore raw
Quoted 43 lines · Brad Smith
Quoted 42 lines · Brad Smith
Quoted 40 lines · Daniel P. Berrangé
Quoted 30 lines · Dr. David Alan Gilbert
Quoted 21 lines · * Laurent Vivier ([email protected]) wrote:

Le 08/03/2021 à 12:46, Thomas Huth a écrit :

Quoted 20 lines · Brad Smith
Quoted 19 lines

OpenBSD has supported 64-bit time_t across all archs since 5.5 released in 2014.

Remove a time_t cast that is no longer necessary.

migration/savevm.c +0 -1
index 52e2d72e4b..9557f85ba9 100644
@@ -2849,8 +2849,7 @@ bool save_snapshot(const char
 *name, bool overwrite, const char *vmstate,
       if (name) {
           pstrcpy(sn->name, sizeof(sn->name), name);
       } else {
-        /* cast below needed for OpenBSD where

tv_sec is still 'long' */

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

-        localtime_r((const time_t *)&tv.tv_sec, &tm); +        localtime_r(&tv.tv_sec, &tm); strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", &tm);
      }

but the qemu_timeval from "include/sysemu/os-win32.h" still uses a long: is this file compiled for
win32?

Quoted 2 lines

Yep this fails for me when built with x86_64-w64-mingw32- (it's fine with i686-w64-mingw32- )

We could just switch the code to use GDateTime from GLib and thus avoid portability issues. I think this should be equivalent:

      g_autoptr(GDateTime) now = g_date_time_new_now_local(); g_autofree char *nowstr = g_date_time_format(now, "vm-%Y%m%d%H%M%s");
      strncpy(sn->name, sizeof(sn->name), nowstr);

Quoted 7 lines
Quoted 5 lines

Which way do you guys want to go? Something like above, remove the comment
or some variation on the comment but not mentioning OpenBSD since it is no
longer relevant?

Anyone?

Personally I always favour using GLib APIs if there's an applicable one, since it eliminates portability problems - or rather offloads them to the GLib maintainers, who have already solved them generally.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
author
#8 lore raw
Quoted 48 lines · Daniel P. Berrangé
Quoted 47 lines · Brad Smith
Quoted 46 lines · Brad Smith
Quoted 33 lines · Daniel P. Berrangé
Quoted 30 lines · Dr. David Alan Gilbert
Quoted 21 lines · * Laurent Vivier ([email protected]) wrote:

Le 08/03/2021 à 12:46, Thomas Huth a écrit :

Quoted 20 lines · Brad Smith
Quoted 19 lines

OpenBSD has supported 64-bit time_t across all archs since 5.5 released in 2014.

Remove a time_t cast that is no longer necessary.

migration/savevm.c +0 -1
index 52e2d72e4b..9557f85ba9 100644
@@ -2849,8 +2849,7 @@ bool save_snapshot(const char
 *name, bool overwrite, const char *vmstate,
       if (name) {
           pstrcpy(sn->name, sizeof(sn->name), name);
       } else {
-        /* cast below needed for OpenBSD where

tv_sec is still 'long' */

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

-        localtime_r((const time_t *)&tv.tv_sec, &tm); +        localtime_r(&tv.tv_sec, &tm); strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", &tm);
      }

but the qemu_timeval from "include/sysemu/os-win32.h" still uses a long: is this file compiled for
win32?

Quoted 2 lines

Yep this fails for me when built with x86_64-w64-mingw32- (it's fine with i686-w64-mingw32- )

Quoted 7 lines

We could just switch the code to use GDateTime from GLib and thus avoid portability issues. I think this should be equivalent:

      g_autoptr(GDateTime) now = g_date_time_new_now_local(); g_autofree char *nowstr = g_date_time_format(now, "vm-%Y%m%d%H%M%s");
      strncpy(sn->name, sizeof(sn->name), nowstr);

Which way do you guys want to go? Something like above, remove the comment
or some variation on the comment but not mentioning OpenBSD since it is no
longer relevant?

Quoted 4 lines
Quoted 1 line

Anyone?

Personally I always favour using GLib APIs if there's an applicable one, since it eliminates portability problems - or rather offloads them to the GLib maintainers, who have already solved them generally.

Can you please submit a proper diff and I'll drop this?

author
#9 lore raw
In reply to Thomas Huth
Quoted 26 lines · Thomas Huth
Quoted 17 lines · Brad Smith

OpenBSD has supported 64-bit time_t across all archs since 5.5 released in 2014.

Remove a time_t cast that is no longer necessary.

migration/savevm.c +0 -1
index 52e2d72e4b..9557f85ba9 100644
@@ -2849,8 +2849,7 @@ bool save_snapshot(const char *name, bool 
 overwrite, const char *vmstate,
       if (name) {
           pstrcpy(sn->name, sizeof(sn->name), name);
       } else {
-        /* cast below needed for OpenBSD where tv_sec is 
Quoted 5 lines

still 'long' */
-        localtime_r((const time_t *)&tv.tv_sec, &tm);
+        localtime_r(&tv.tv_sec, &tm);
          strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", &tm); }

Please make sure to CC: the maintainers (see MAINTAINERS file). Done now.

Quoted 1 line

My bad. That was an oversight on my part. I was quick to send it to the list without thinking about something like that.