From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53507) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJvdO-00036i-VM for qemu-devel@nongnu.org; Thu, 14 Jan 2016 23:05:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJvdJ-0003Xo-Vh for qemu-devel@nongnu.org; Thu, 14 Jan 2016 23:05:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45525) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJvdJ-0003Xi-NZ for qemu-devel@nongnu.org; Thu, 14 Jan 2016 23:05:05 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 478357AE82 for ; Fri, 15 Jan 2016 04:05:05 +0000 (UTC) References: <1452516281-27519-1-git-send-email-berrange@redhat.com> From: Eric Blake Message-ID: <56986FEF.1040307@redhat.com> Date: Thu, 14 Jan 2016 21:05:03 -0700 MIME-Version: 1.0 In-Reply-To: <1452516281-27519-1-git-send-email-berrange@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ruADjeELexf7sMT5sWimgmmuXvwWbTqAa" Subject: Re: [Qemu-devel] [PATCH v4] qemu-char: add logfile facility to all chardev backends List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Paolo Bonzini , Markus Armbruster This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --ruADjeELexf7sMT5sWimgmmuXvwWbTqAa Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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. >=20 > 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). >=20 > Signed-off-by: Daniel P. Berrange > --- >=20 > -CharDriverState *qemu_chr_alloc(void) > +static void qemu_chr_free_common(CharDriverState *chr); > + > +CharDriverState *qemu_chr_alloc(ChardevCommon *backend, Error **errp) > { > CharDriverState *chr =3D g_malloc0(sizeof(CharDriverState)); > qemu_mutex_init(&chr->chr_write_lock); > + > + if (backend->has_logfile) { > + int flags =3D O_WRONLY | O_CREAT; > + if (backend->has_logappend && > + backend->logappend) { > + flags |=3D O_APPEND; > + } else { > + flags |=3D O_TRUNC; > + } > + chr->logfd =3D 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? > =20 > +static void qemu_chr_parse_common(QemuOpts *opts, ChardevCommon *backe= nd) > +{ > + const char *logfile =3D qemu_opt_get(opts, "logfile"); > + > + backend->has_logfile =3D logfile !=3D NULL; > + backend->logfile =3D logfile ? g_strdup(logfile) : NULL; Isn't g_strdup(NULL) safe, such that you could write this as: backend->logfile =3D g_strdup(logfile); Otherwise looked okay; with the mutex question answered or fixed, you can add: Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --ruADjeELexf7sMT5sWimgmmuXvwWbTqAa Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWmG/vAAoJEKeha0olJ0NqU2wIAJMCyYITpRftmw3QZNDtNlbm QxOGbfsl2cvok0O/vICzKJA4fjCmlJs2KZyM4XtRlc18lUl+FpyI/TSISx6WCTs6 sRcIyQeTmeYndsIR/HRhQrxQb0K6fZ6VQgc0w1NJy4v658VheGMGrIkQoSK9RKNR zKvWyuUhbsNRRoHjXcOSjkTeAi0fb4yre4FhWXpTqeQ+DE7yMCRaeQypbFSayT3T ncgxGJiDEvuM48QEZu5bP5HIRoiP1EzcdK+zhRiswtt5feLGEr1Gno2QCiZw21xw bsvyFbBfMW6ZTt8M23BrD9QcWbJtuJ9dCzGnmFhwsFsVc8qlw3Fs8DNuCk4tXgk= =CM3U -----END PGP SIGNATURE----- --ruADjeELexf7sMT5sWimgmmuXvwWbTqAa--