From patchwork Thu Feb 11 10:41:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 8277641 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 346179F1C0 for ; Thu, 11 Feb 2016 10:43:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 819A02021F for ; Thu, 11 Feb 2016 10:43:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8EBA02011E for ; Thu, 11 Feb 2016 10:43:31 +0000 (UTC) Received: from localhost ([::1]:48529 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aToig-0003dy-VP for patchwork-qemu-devel@patchwork.kernel.org; Thu, 11 Feb 2016 05:43:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59277) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTogm-0000Ip-9k for qemu-devel@nongnu.org; Thu, 11 Feb 2016 05:41:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTogl-0004qs-B3 for qemu-devel@nongnu.org; Thu, 11 Feb 2016 05:41:32 -0500 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:38428) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTogl-0004qm-4p for qemu-devel@nongnu.org; Thu, 11 Feb 2016 05:41:31 -0500 Received: by mail-wm0-x234.google.com with SMTP id p63so62362519wmp.1 for ; Thu, 11 Feb 2016 02:41:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=vYDXKn1tYgWIXM8+I/4kk/GywLJTmqob8pU+nbVm4BI=; b=QB6Z91DrPlHeyQYAHG+Q0Kmc+5zy42yfGGyhTTk7HYgXEc6WTZM1xcC+Xy4pQkqjhb a9UmHSkNlMUeyAFYVXufyYMobOputd6VPgO8IyibqvBqBA2wWJ8vLyP5HFXd4yGJIEJc niuzJKciSpnY3VFtTQgKFkRkFEuba4oelAfSc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=vYDXKn1tYgWIXM8+I/4kk/GywLJTmqob8pU+nbVm4BI=; b=iea9Li5SihHhv0t3amX7PEmCkDjQbhXV2fhbSme4KVmGbM9qNA6m1iQiMgDQPrtdzX CUratIpxsrDkpwaSuBAukkS7jBBiKb/XOSfmSyS3bvNYRyjgFqDLSrcf/LnjJPuuM0sN O8iNdeEIZ7IP/oxXtIFOM3LrJmF2r0bt/yA0GpaxtP9o9zmCAPa6i82e1ydArQ7Vy209 +kSis1A0fDRduXuoQvgstLJlOo09aou/+nVkWnwIEh5EchwUDkX+eisQgDM0/miBcCrC 99n7yFelJ7t7/4FWPUQacUBRIaYaf7ovR0WIu1eGHNM4LV3p9CkX2HSuRA8G66IzPyfI gZ1w== X-Gm-Message-State: AG10YOS5uDQp514o8PBM0MTfwas7zCyegIulmOBWe7l74pyBzCTS7E10Jd7nr1cQRBkm71SF X-Received: by 10.194.9.98 with SMTP id y2mr46026453wja.105.1455187290514; Thu, 11 Feb 2016 02:41:30 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id av3sm6940652wjc.44.2016.02.11.02.41.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Feb 2016 02:41:29 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id ED08B3E020C; Thu, 11 Feb 2016 10:41:22 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 11 Feb 2016 10:41:01 +0000 Message-Id: <1455187265-26631-6-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1455187265-26631-1-git-send-email-alex.bennee@linaro.org> References: <1455187265-26631-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::234 Cc: dgilbert@redhat.com, crosthwaitepeter@gmail.com, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , aurelien@aurel32.net, rth@twiddle.net Subject: [Qemu-devel] [PATCH v6 5/9] qemu-log: support simple pid substitution in logfile X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When debugging stuff that occurs over several forks it would be useful not to keep overwriting the one logfile you've set-up. This allows a simple %d to be included once in the logfile parameter which is substituted with getpid(). Signed-off-by: Alex Bennée Reviewed-by: Leandro Dorileo Reviewed-by: Aurelien Jarno --- v5 - add another r-b --- util/log.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/util/log.c b/util/log.c index c89b226..3988b5d 100644 --- a/util/log.c +++ b/util/log.c @@ -75,11 +75,24 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers) qemu_log_close(); } } - +/* + * Allow the user to include %d in their logfile which will be + * substituted with the current PID. This is useful for debugging many + * nested linux-user tasks but will result in lots of logs. + */ void qemu_set_log_filename(const char *filename) { g_free(logfilename); - logfilename = g_strdup(filename); + if (g_strrstr(filename, "%d")) { + /* if we are going to format this we'd better validate first */ + if (g_regex_match_simple("^[^%]+%d[^%]+$", filename, 0, 0)) { + logfilename = g_strdup_printf(filename, getpid()); + } else { + g_error("Bad logfile format: %s", filename); + } + } else { + logfilename = g_strdup(filename); + } qemu_log_close(); qemu_set_log(qemu_loglevel); }