[libvirt] [PATCH] Pass a correct pointer type to localtime_r(3).

Eric Blake eblake at redhat.com
Tue Sep 4 15:20:24 UTC 2012


[adding bug-gnulib]

On 09/04/2012 08:49 AM, Jasper Lievisse Adriaanse wrote:
>>From b53dc971cc50b5ac397e4568449d25041477c8d6 Mon Sep 17 00:00:00 2001
> From: Jasper Lievisse Adriaanse <jasper at humppa.nl>
> Date: Tue, 4 Sep 2012 16:47:26 +0200
> Subject: [PATCH] Pass a correct pointer type to localtime_r(3).
> 
> Fixes a warning:
> warning: passing argument 1 of 'localtime_r' from incompatible pointer type
> ---
>  tools/virsh-domain.c |    3 ++-
>  tools/virsh.c        |    3 ++-
>  2 files changed, 4 insertions(+), 2 deletions(-)

NACK from the libvirt point of view.  tv_sec is required by POSIX to be
of type time_t; so this is a bug in the OpenBSD header, and gnulib
should be working around this bug.

> 
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index f0ec742..535779c 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -3711,6 +3711,7 @@ vshGenFileName(vshControl *ctl, virDomainPtr dom, const char *mime)
>      struct tm time_info;
>      const char *ext = NULL;
>      char *ret = NULL;
> +    time_t sec = (time_t) cur_time.tv_sec;
>  
>      if (!dom) {
>          vshError(ctl, "%s", _("Invalid domain supplied"));
> @@ -3724,7 +3725,7 @@ vshGenFileName(vshControl *ctl, virDomainPtr dom, const char *mime)
>      /* add mime type here */
>  
>      gettimeofday(&cur_time, NULL);
> -    localtime_r(&cur_time.tv_sec, &time_info);
> +    localtime_r(&sec, &time_info);
>      strftime(timestr, sizeof(timestr), "%Y-%m-%d-%H:%M:%S", &time_info);
>  

> +++ b/tools/virsh.c
> @@ -2189,6 +2189,7 @@ vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format,
>      const char *lvl = "";
>      struct timeval stTimeval;
>      struct tm *stTm;
> +    time_t sec = stTimeval.tv_sec;
>  
>      if (ctl->log_fd == -1)
>          return;
> @@ -2199,7 +2200,7 @@ vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format,
>       * [YYYY.MM.DD HH:MM:SS SIGNATURE PID] LOG_LEVEL message
>      */
>      gettimeofday(&stTimeval, NULL);
> -    stTm = localtime(&stTimeval.tv_sec);
> +    stTm = localtime(&sec);

Even grosser - why is virsh using localtime() instead of localtime_r()?

-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 617 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120904/30bab683/attachment-0001.sig>


More information about the libvir-list mailing list