[libvirt] [PATCH 5/6] Add an an internal API for emergency dump of debug buffer

Eric Blake eblake at redhat.com
Fri Mar 4 15:53:55 UTC 2011


On 03/04/2011 03:30 AM, Daniel Veillard wrote:
> virLogEmergencyDumpAll() allows to dump the content of the
> debug buffer from within a signal handler. It saves to all
> log file or stderr if none is found
> * src/util/logging.h src/util/logging.c: add the new API
>   and cleanup the old virLogDump code
> * src/libvirt_private.syms: exports it as a private symbol

> 
> +void
> +virLogEmergencyDumpAll(int signum) {
> +    int ret = 0, len;
> +    char buf[100];
> +
> +    if (virLogLen == 0)
> +        return;
>  
> -    if ((virLogLen == 0) || (f == NULL))
> -        return 0;
>      virLogLock();

Is virLogLock async-signal-safe?

> +    snprintf(buf, sizeof(buf) - 1,
> +             "Caught signal %d, dumping internal log buffer:\n", signum);

snprintf is _not_ safe; it can call malloc.  We probably ought to use a
manual decimal-to-string conversion loop instead.

> +    buf[sizeof(buf) - 1] = 0;
> +    virLogDumpAllFD(buf, strlen(buf));
> +    snprintf(buf, sizeof(buf) - 1, "\n\n    ====== start of log =====\n\n");

Why snprintf here, rather than strcpy?

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

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


More information about the libvir-list mailing list