Received: from eggs.gnu.org ([2001:4830:134:3::10]:57627) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZMYh-000237-HR for qemu-devel@nongnu.org; Mon, 15 Aug 2016 14:24:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bZMYc-0003xz-Du for qemu-devel@nongnu.org; Mon, 15 Aug 2016 14:24:22 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:48870 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZMYc-0003xv-9A for qemu-devel@nongnu.org; Mon, 15 Aug 2016 14:24:18 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u7FINhk9116760 for ; Mon, 15 Aug 2016 14:24:17 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 24th4f68mq-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 15 Aug 2016 14:24:17 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 15 Aug 2016 19:24:15 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 9B2201B0804B for ; Mon, 15 Aug 2016 19:25:48 +0100 (BST) Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u7FIOCD118153474 for ; Mon, 15 Aug 2016 18:24:12 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u7FIOCQF004505 for ; Mon, 15 Aug 2016 12:24:12 -0600 From: Sascha Silbe In-Reply-To: References: <1468599862-18973-1-git-send-email-silbe@linux.vnet.ibm.com> Date: Mon, 15 Aug 2016 20:24:12 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-Id: <87bn0tnb5f.fsf@oc4731375738.ibm.com> Subject: Re: [Qemu-devel] [PATCH] test-logging: don't hard-code paths in /tmp List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Paolo Bonzini , Alex =?utf-8?Q?Benn=C3=A9e?= , QEMU Developers , Markus Armbruster Dear Peter, Peter Maydell writes: > On 15 July 2016 at 17:24, Sascha Silbe wrote: [...] >> Instead of hard-coding the paths, create a temporary directory using >> g_dir_make_tmp() and clean it up afterwards. >> >> Fixes: f6880b7f ("qemu-log: support simple pid substitution for logs") >> Signed-off-by: Sascha Silbe > > Thanks for this patch -- I just noticed that the test was leaving > temporary files not cleaned up, which brought me to this patch > by searching the mail archives... I have totally forgotten about it. Would probably have remembered the next time "make check" failed on a shared machine. ;) [tests/test-logging.c:test_parse_path()] >> + gchar *plain_path =3D g_build_filename(tmp_path, "qemu.log", NULL); >> + gchar *pid_infix_path =3D g_build_filename(tmp_path, "qemu-%d.log",= NULL); >> + gchar *pid_suffix_path =3D g_build_filename(tmp_path, "qemu.log.%d"= , NULL); >> + gchar *double_pid_path =3D g_build_filename(tmp_path, "qemu-%d%d.lo= g", NULL); [...] > This could usefully be refactored to have a helper function that does > the g_build_filename/qemu_set_log_filename/g_free. I wasn't sure about it but it actually ended up being a bit nicer than what I had before. >> +static void rmtree(gchar const *root) [...] > I don't really like spawning rm here for this. We know we > don't have any subdirectories here so we can just > gdir =3D g_dir_open(root, 0, NULL); > for (;;) { > const char *f =3D g_dir_read_name(gdir); > if (!f) { > break; > } > g_remove(f); > } > g_dir_close(gdir); > g_rmdir(root); > > (add error handling to taste). I don't really like the rm spawning solution either. But the above plus error handling was a bit much for a single test for my taste. Is there some place I could stick something like the above so it could at least be reused by other tests in the future? (Even though I very much hate the idea of implementing yet another rmtree()). [...] >> int main(int argc, char **argv) >> { >> + gchar *tmp_path =3D g_dir_make_tmp("qemu-test-logging.XXXXXX", NULL= ); > > Unfortunately g_dir_make_tmp() only came in in glib 2.30, and we have > to be able to build with glib 2.22. Bummer. The old interfaces were really awkward. Is there somewhere I could put a compatibility wrapper, implementing g_dir_make_tmp() using the old interfaces? Thanks for the review! Sascha --=20 Softwareentwicklung Sascha Silbe, Niederhofenstra=C3=9Fe 5/1, 71229 Leonberg https://se-silbe.de/ USt-IdNr. DE281696641