[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: [libvirt] [PATCH] time_t is not a long on FreeBSD, need to add casts
- From: Matthias Bolte <matthias bolte googlemail com>
- To: Eric Blake <eblake redhat com>
- Cc: libvir-list redhat com
- Subject: Re: [libvirt] [PATCH] time_t is not a long on FreeBSD, need to add casts
- Date: Sat, 14 May 2011 10:32:49 +0200
2011/5/13 Eric Blake <eblake redhat com>:
> On 05/12/2011 11:53 PM, Matthias Bolte wrote:
>> ---
>> src/conf/domain_conf.c | 6 +++---
>> 1 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
>> index d3efec6..875f90e 100644
>> --- a/src/conf/domain_conf.c
>> +++ b/src/conf/domain_conf.c
>> @@ -9115,7 +9115,7 @@ virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr,
>>
>> def->name = virXPathString("string(./name)", ctxt);
>> if (def->name == NULL)
>> - ignore_value(virAsprintf(&def->name, "%ld", tv.tv_sec));
>> + ignore_value(virAsprintf(&def->name, "%ld", (long)tv.tv_sec));
>
> Ouch. Cygwin is thinking of making time_t a 64-bit entity, but since
> cygwin is 32-bit, that's larger than long.
>
> We need to use %lld and (long long) instead (or %jd and intmax_t).
>
Okay here are the two affected patches with long long instead of long.
Matthias
From 1d72db6b2e25168c80de6fcd420ca182fb273a6f Mon Sep 17 00:00:00 2001
From: Matthias Bolte <matthias bolte googlemail com>
Date: Fri, 13 May 2011 07:07:13 +0200
Subject: [PATCH] time_t is not a long on FreeBSD, need to add casts
Cast to long long to be on the safe side when time_t is a 64bit type.
---
src/conf/domain_conf.c | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a0eb43e..946297a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9070,7 +9070,7 @@ virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr,
def->name = virXPathString("string(./name)", ctxt);
if (def->name == NULL)
- ignore_value(virAsprintf(&def->name, "%ld", tv.tv_sec));
+ ignore_value(virAsprintf(&def->name, "%lld", (long long)tv.tv_sec));
if (def->name == NULL) {
virReportOOMError();
@@ -9080,13 +9080,16 @@ virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr,
def->description = virXPathString("string(./description)", ctxt);
if (!newSnapshot) {
- if (virXPathLong("string(./creationTime)", ctxt,
- &def->creationTime) < 0) {
+ long long creationTime;
+
+ if (virXPathLongLong("string(./creationTime)", ctxt,
+ &creationTime) < 0) {
virDomainReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing creationTime from existing snapshot"));
goto cleanup;
}
+ def->creationTime = creationTime;
def->parent = virXPathString("string(./parent/name)", ctxt);
state = virXPathString("string(./state)", ctxt);
@@ -9146,8 +9149,8 @@ char *virDomainSnapshotDefFormat(char *domain_uuid,
virBufferAsprintf(&buf, " <name>%s</name>\n", def->parent);
virBufferAddLit(&buf, " </parent>\n");
}
- virBufferAsprintf(&buf, " <creationTime>%ld</creationTime>\n",
- def->creationTime);
+ virBufferAsprintf(&buf, " <creationTime>%lld</creationTime>\n",
+ (long long)def->creationTime);
virBufferAddLit(&buf, " <domain>\n");
virBufferAsprintf(&buf, " <uuid>%s</uuid>\n", domain_uuid);
virBufferAddLit(&buf, " </domain>\n");
--
1.7.0.4
From 17cccebb1e35ae56f61802b796598dc16d8a4d02 Mon Sep 17 00:00:00 2001
From: Matthias Bolte <matthias bolte googlemail com>
Date: Fri, 13 May 2011 08:31:03 +0200
Subject: [PATCH] virsh: time_t is not a long on FreeBSD
localtime_r expects time_t.
---
tools/virsh.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index 3baa015..62ffc8e 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -10406,7 +10406,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;
@@ -10465,10 +10466,11 @@ 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;
+ 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
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]