qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Daniel P. Berrange" <berrange@redhat.com>, qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v4] qemu-char: add logfile facility to all chardev backends
Date: Thu, 14 Jan 2016 21:05:03 -0700	[thread overview]
Message-ID: <56986FEF.1040307@redhat.com> (raw)
In-Reply-To: <1452516281-27519-1-git-send-email-berrange@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2569 bytes --]

On 01/11/2016 05:44 AM, Daniel P. Berrange wrote:
> Typically a UNIX guest OS will log boot messages to a serial
> port in addition to any graphical console. An admin user
> may also wish to use the serial port for an interactive
> console. A virtualization management system may wish to
> collect system boot messages by logging the serial port,
> but also wish to allow admins interactive access.
> 

> This patch introduces a 'ChardevCommon' struct which
> is setup as a base for all the ChardevBackend types.
> Ideally this would be registered directly as a base
> against ChardevBackend, rather than each type, but
> the QAPI generator doesn't allow that since the
> ChardevBackend is a non-discriminated union. The
> ChardevCommon struct provides the optional 'logfile'
> parameter, as well as 'logappend' which controls
> whether QEMU truncates or appends (default truncate).
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
> 


> -CharDriverState *qemu_chr_alloc(void)
> +static void qemu_chr_free_common(CharDriverState *chr);
> +
> +CharDriverState *qemu_chr_alloc(ChardevCommon *backend, Error **errp)
>  {
>      CharDriverState *chr = g_malloc0(sizeof(CharDriverState));
>      qemu_mutex_init(&chr->chr_write_lock);
> +
> +    if (backend->has_logfile) {
> +        int flags = O_WRONLY | O_CREAT;
> +        if (backend->has_logappend &&
> +            backend->logappend) {
> +            flags |= O_APPEND;
> +        } else {
> +            flags |= O_TRUNC;
> +        }
> +        chr->logfd = qemu_open(backend->logfile, flags, 0666);
> +        if (chr->logfd < 0) {
> +            error_setg_errno(errp, errno,
> +                             "Unable to open logfile %s",
> +                             backend->logfile);
> +            g_free(chr);

Are we leaking anything mutex-related by freeing chr without tearing
down the just-initialized chr_write_lock?


>  
> +static void qemu_chr_parse_common(QemuOpts *opts, ChardevCommon *backend)
> +{
> +    const char *logfile = qemu_opt_get(opts, "logfile");
> +
> +    backend->has_logfile = logfile != NULL;
> +    backend->logfile = logfile ? g_strdup(logfile) : NULL;

Isn't g_strdup(NULL) safe, such that you could write this as:

backend->logfile = g_strdup(logfile);

Otherwise looked okay; with the mutex question answered or fixed, you
can add:
Reviewed-by: Eric Blake <eblake@redhat.com>

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2016-01-15  4:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-11 12:44 [Qemu-devel] [PATCH v4] qemu-char: add logfile facility to all chardev backends Daniel P. Berrange
2016-01-15  4:05 ` Eric Blake [this message]
2016-01-15  9:15   ` Daniel P. Berrange
2016-01-15 15:58     ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56986FEF.1040307@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).