[libvirt] [PATCH v2] virsh: time_t is not a long on FreeBSD

localtime_r expects time_t. --- v2: add overflow check tools/virsh.c | 14 ++++++++++---- 1 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index de49489..b43c167 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -10442,7 +10442,8 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) char *doc = NULL; virDomainSnapshotPtr snapshot = NULL; char *state = NULL; - long creation; + long long creation_longlong; + time_t creation_time_t; char timestr[100]; struct tm time_info; @@ -10501,10 +10502,15 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) state = virXPathString("string(/domainsnapshot/state)", ctxt); if (state == NULL) continue; - if (virXPathLong("string(/domainsnapshot/creationTime)", ctxt, - &creation) < 0) + if (virXPathLongLong("string(/domainsnapshot/creationTime)", ctxt, + &creation_longlong) < 0) continue; - localtime_r(&creation, &time_info); + creation_time_t = creation_longlong; + if (creation_time_t != creation_longlong) { + vshError(ctl, "%s", _("time_t overflow")); + continue; + } + localtime_r(&creation_time_t, &time_info); strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S %z", &time_info); vshPrint(ctl, " %-20s %-25s %s\n", names[i], timestr, state); -- 1.7.0.4

On 05/25/2011 09:06 AM, Matthias Bolte wrote:
localtime_r expects time_t. --- v2: add overflow check
ACK.
- localtime_r(&creation, &time_info); + creation_time_t = creation_longlong; + if (creation_time_t != creation_longlong) { + vshError(ctl, "%s", _("time_t overflow"));
We shouldn't hit this error until 2038, and by then, hopefully more 32-bit platforms (if any are still running) will have switched to 64-bit time_t. :) But I agree with keeping this error in the code, since silent wraparound is always worse than explicit mention of overflow. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

2011/5/25 Eric Blake <eblake@redhat.com>:
On 05/25/2011 09:06 AM, Matthias Bolte wrote:
localtime_r expects time_t. --- v2: add overflow check
ACK.
- localtime_r(&creation, &time_info); + creation_time_t = creation_longlong; + if (creation_time_t != creation_longlong) { + vshError(ctl, "%s", _("time_t overflow"));
We shouldn't hit this error until 2038, and by then, hopefully more 32-bit platforms (if any are still running) will have switched to 64-bit time_t. :) But I agree with keeping this error in the code, since silent wraparound is always worse than explicit mention of overflow.
I like to be on the safe side :) Thanks, pushed. Matthias

On 05/25/2011 05:53 PM, Eric Blake wrote:
- localtime_r(&creation,&time_info); + creation_time_t = creation_longlong; + if (creation_time_t != creation_longlong) { + vshError(ctl, "%s", _("time_t overflow"));
We shouldn't hit this error until 2038, and by then, hopefully more 32-bit platforms (if any are still running) will have switched to 64-bit time_t.:)
If FreeBSD will still have time_t==int, it will die a painful death in 2038 independent of 32- vs. 64-bit. :) Paolo
participants (3)
-
Eric Blake
-
Matthias Bolte
-
Paolo Bonzini