From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWS8V-0005R3-Di for qemu-devel@nongnu.org; Thu, 18 Feb 2016 12:13:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWS8Q-0002Vr-7V for qemu-devel@nongnu.org; Thu, 18 Feb 2016 12:13:03 -0500 Received: from mx0.arrikto.com ([212.71.252.59]:33551) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWS8Q-0002Vk-19 for qemu-devel@nongnu.org; Thu, 18 Feb 2016 12:12:58 -0500 Date: Thu, 18 Feb 2016 19:12:50 +0200 From: Dimitris Aragiorgis Message-ID: <20160218171250.GA21453@arr> References: <56BCCB44.4060203@redhat.com> <1455795518-19205-1-git-send-email-dimara@arrikto.com> <56C5E1A5.2030001@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="YiEDa0DAkWCtVeE4" Content-Disposition: inline In-Reply-To: <56C5E1A5.2030001@redhat.com> Subject: Re: [Qemu-devel] [PATCH] log: Redirect stderr to logfile if deamonized List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * Paolo Bonzini [2016-02-18 16:22:13 +0100]: >=20 >=20 > On 18/02/2016 12:38, Dimitris Aragiorgis wrote: > > In case of daemonize, use the logfile passed with the -D option in > > order to redirect stderr to it instead of /dev/null. > >=20 > > Also remove some unused code in log.h. > >=20 > > Signed-off-by: Dimitris Aragiorgis > > --- > > include/qemu/log.h | 6 ------ > > os-posix.c | 6 +++++- > > util/log.c | 11 +++++++++-- > > 3 files changed, 14 insertions(+), 9 deletions(-) > >=20 > > diff --git a/include/qemu/log.h b/include/qemu/log.h > > index 30817f7..dda65fd 100644 > > --- a/include/qemu/log.h > > +++ b/include/qemu/log.h > > @@ -94,12 +94,6 @@ static inline void qemu_log_close(void) > > } > > } > > =20 > > -/* Set up a new log file */ > > -static inline void qemu_log_set_file(FILE *f) > > -{ > > - qemu_logfile =3D f; > > -} > > - > > /* define log items */ > > typedef struct QEMULogItem { > > int mask; > > diff --git a/os-posix.c b/os-posix.c > > index cce62ed..92fa3ba 100644 > > --- a/os-posix.c > > +++ b/os-posix.c > > @@ -37,6 +37,7 @@ > > #include "qemu-options.h" > > #include "qemu/rcu.h" > > #include "qemu/error-report.h" > > +#include "qemu/log.h" > > =20 > > #ifdef CONFIG_LINUX > > #include > > @@ -275,7 +276,10 @@ void os_setup_post(void) > > =20 > > dup2(fd, 0); > > dup2(fd, 1); > > - dup2(fd, 2); > > + /* In case -D is given do not redirect stderr to /dev/null */ > > + if (!qemu_logfile) { > > + dup2(fd, 2); > > + } > > =20 > > close(fd); > > =20 > > diff --git a/util/log.c b/util/log.c > > index 2709e98..a7ddc7e 100644 > > --- a/util/log.c > > +++ b/util/log.c > > @@ -56,13 +56,20 @@ void do_qemu_set_log(int log_flags, bool use_own_bu= ffers) > > #ifdef CONFIG_TRACE_LOG > > qemu_loglevel |=3D LOG_TRACE; > > #endif > > - if (qemu_loglevel && !qemu_logfile) { > > + if ((qemu_loglevel || is_daemonized()) && !qemu_logfile) { > > if (logfilename) { > > qemu_logfile =3D fopen(logfilename, log_append ? "a" : "w"= ); > > if (!qemu_logfile) { > > perror(logfilename); > > _exit(1); > > } > > + /* In case we are a daemon redirect stderr to logfile */ > > + if (is_daemonized()) { > > + dup2(fileno(qemu_logfile), STDERR_FILENO); > > + fclose(qemu_logfile); > > + /* This will skip closing logfile in qemu_log_close() = */ > > + qemu_logfile =3D stderr; > > + } > > } else { > > /* Default to stderr if no log file specified */ > > qemu_logfile =3D stderr; > > @@ -82,7 +89,7 @@ void do_qemu_set_log(int log_flags, bool use_own_buff= ers) > > log_append =3D 1; > > } > > } > > - if (!qemu_loglevel && qemu_logfile) { > > + if (!qemu_loglevel && !is_daemonized() && qemu_logfile) { > > qemu_log_close(); > > } >=20 > Why is this necessary? Perhaps qemu_log_close should dup(1,2) if QEMU > is daemonized. The rest looks great. >=20 Without !is_daemonized(), if we use -daemon with -D without -d, qemu_log_close() will eventually set qemu_logfile to NULL. This will make os_setup_post() redirect stderr to /dev/null, which is unwanted. To be honest, I don't understand your suggestion. How would calling dup2(1, 2) help in our case? Isn't fd 1 the standard output? Thanks, dimara > Paolo --YiEDa0DAkWCtVeE4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iQEcBAEBAgAGBQJWxfuSAAoJEHFDHex6CBG9hEYIAKe4sdMsS/PT96jE16a1EvhM zMcSKcWB14v+skIS0QPWWEMp7Wy7ZYhlxfN+LenK/lmVqWX/mVSYBeGxEREZf/gi j6hurolavrosk0uSikUVRP35ghZ03o0FHrvpUDc/DoHj+NV9oprGOm3vVeUhYuLQ gIq//EiAbvfAws4J8fm8bZ+7st4am8356uamYaUEycs7UvJBJZHHq6fyf9Gmvvpw s/+NbXioG1F038uUhuFC2jhFcWR25unJR/Q0sLtkgNviPcCqqpia9oJNZESna6o6 dYeYFMa/A/IO/VXTJdypZpX1e6pkHT9rQ2F757SeGfgI/CVtkHdd1Xs8Brtvaoc= =5Ytw -----END PGP SIGNATURE----- --YiEDa0DAkWCtVeE4--