From patchwork Fri May 22 02:34:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 187117 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2102818ilb; Thu, 21 May 2020 19:36:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxp+hSRPzi4MMATt2yCPxAMLt+FigQgK7To46WC/MdnEEQlaKDjK1JVAn3bNCAyiL7EAL/F X-Received: by 2002:a05:620a:201d:: with SMTP id c29mr11842133qka.263.1590114979513; Thu, 21 May 2020 19:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590114979; cv=none; d=google.com; s=arc-20160816; b=E2my50fvD0wccz8iDF+PV+8DrZJl6/6xsBeHXrYZmOx9/bmhVT3MBgOvW2J5e3k/O6 uwvHlIyoQdQx7uslRCa6y90zelNT9FqwBog+RtiHFpAEg4c8MRcPqo/ln7yd/tD9BE8f swmXUk8vhJuSTr0U+ej3Zzt3K1X2za/s26duoU75mCb07ADdMlZp8sSeyfLmWvoYNXfW Er74BYQYIj5adac74GTEKppXBSf/h+0jM5lc88nko04DZd0yL6dS4aV7uvWyDX3GNEDz 9at0hQZX2cuvJZruK4Xe+PwCu3crOcztBUiNDA97QCr11Ig+N3toCCdsoli2/k3MO/kq 0+IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=qsogh1iVORSWncpn9Q6d07KHmeqCKiBimOSa205EF/o=; b=CHqa8B4oDM33heUcCs9gsSMud1IEQ0WIcZWn8dOW6S2swBQFapVGGOYgxPWvLb+MqK EwB5jIRtxal3nGeVKrVLg+UQXogMu2Vhwu6hd0U/d8xBc0epCXUmV9qyIwvHqQGjMiUO 15GR4vZW8YmXHSRbuCmFjryD6yg4LSG35d5KAVgET8pHlWaJZF5KO8B0C8yGVganmFTh aUTiu6aPaTMqQxomQ52lLhsSKgcomvHbuJAk/SKWoq0mXZyax1lgrW34VmyaeiQnWHcS ZvALjwSmXJqoiWHYGoaPy/K3R9EcVMcLDWAm+mu975q+sA+962o8JsH7gJJIDKe/6fYG juTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Yo7rGMXb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w22si4489398qkf.349.2020.05.21.19.36.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 May 2020 19:36:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Yo7rGMXb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbxXn-0006Mh-2k for patch@linaro.org; Thu, 21 May 2020 22:36:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbxWK-00025F-Bi for qemu-devel@nongnu.org; Thu, 21 May 2020 22:34:48 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:41737) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jbxWJ-00055z-I9 for qemu-devel@nongnu.org; Thu, 21 May 2020 22:34:48 -0400 Received: by mail-pg1-x52d.google.com with SMTP id r10so4276232pgv.8 for ; Thu, 21 May 2020 19:34:47 -0700 (PDT) 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-transfer-encoding; bh=qsogh1iVORSWncpn9Q6d07KHmeqCKiBimOSa205EF/o=; b=Yo7rGMXbypolOulo6jZnvutW+SAmxwEFHKRUQz1ULYq1OfBzpJkl6iw6WxsFlO/iCq K8aC7Tu+Ok6g2WlFkDZDGRgYNGJI1dV3rj+UMA1zjeRImM76sOwsO0ukAZv7LJ9FhJlU KS7ok2OdGGZldx6hs4H+YRjMWFu3e6uDbvINnnurPXyA/UtGfqVqLnvTZFMpHHwVd3w3 wqRmBIucoVLbYFm3hJ33WYcHsYdnPwefcyBEUKum5a1pHLRtQiN0r7QhjHyJyj2PM3kH TEFD4Xf7cAR0qIifdU0KoQEBoisgtrfwKiltpTqxRYylvyG9nzA0RlAl0nq+z1efS8XE l+Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qsogh1iVORSWncpn9Q6d07KHmeqCKiBimOSa205EF/o=; b=rKHn1qXnF/Np9sHhifGPll4UaOSOD7CXV6FkFWWmx/SUClZKcYeNq+T275/RTszK/i RtR08ynwnyUQgoMxtCnUuC3FzyzUmOtO/jUYIIut6u2eYdXZd4n0PUxPYj1J/6MPw4l+ 9VFxbWcpxXyv1RVejqK950CUO1z3csIfdjGpcCFKIxiVxOfsQr1Edea0auaGMVSat+q2 CzGp8p6yncpSZs3ludiomjvyfdzUIlbBe9tlErOvAJM0wzuYtl4WjUGU8NgQWH+qyee8 czZM75LmsmWkVE6hqHqUWRut0arjCG3tyjl6h8VS5LAihBN4bDcAMCuHTqaLZw0mAyQb KxkA== X-Gm-Message-State: AOAM5337QFTaNHK7BxVXVAQ2da4HktB6r+YEcqZFBSdyJMiv60MiHExk DuqTuVillDh2Ffkz6h7JxfoXPXJlx5Y= X-Received: by 2002:a63:d70b:: with SMTP id d11mr11840970pgg.372.1590114885833; Thu, 21 May 2020 19:34:45 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id gt10sm5443755pjb.30.2020.05.21.19.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 19:34:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 03/25] Hoist trace file and socket opening Date: Thu, 21 May 2020 19:34:18 -0700 Message-Id: <20200522023440.26261-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200522023440.26261-1-richard.henderson@linaro.org> References: <20200522023440.26261-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52d; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52d.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We will want to share this code with --dump. Reviewed-by: Alex Bennée Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v3: Hoist socket connecting as well as trace file opening. --- risu.c | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) -- 2.20.1 diff --git a/risu.c b/risu.c index 059348f..2f6a677 100644 --- a/risu.c +++ b/risu.c @@ -363,6 +363,29 @@ int main(int argc, char **argv) } } + if (trace) { + if (strcmp(trace_fn, "-") == 0) { + comm_fd = ismaster ? STDOUT_FILENO : STDIN_FILENO; + } else { + if (ismaster) { + comm_fd = open(trace_fn, O_WRONLY | O_CREAT, S_IRWXU); + } else { + comm_fd = open(trace_fn, O_RDONLY); + } +#ifdef HAVE_ZLIB + gz_trace_file = gzdopen(comm_fd, ismaster ? "wb9" : "rb"); +#endif + } + } else { + if (ismaster) { + fprintf(stderr, "master port %d\n", port); + comm_fd = master_connect(port); + } else { + fprintf(stderr, "apprentice host %s port %d\n", hostname, port); + comm_fd = apprentice_connect(hostname, port); + } + } + imgfile = argv[optind]; if (!imgfile) { fprintf(stderr, "Error: must specify image file name\n\n"); @@ -373,34 +396,8 @@ int main(int argc, char **argv) load_image(imgfile); if (ismaster) { - if (trace) { - if (strcmp(trace_fn, "-") == 0) { - comm_fd = STDOUT_FILENO; - } else { - comm_fd = open(trace_fn, O_WRONLY | O_CREAT, S_IRWXU); -#ifdef HAVE_ZLIB - gz_trace_file = gzdopen(comm_fd, "wb9"); -#endif - } - } else { - fprintf(stderr, "master port %d\n", port); - comm_fd = master_connect(port); - } return master(); } else { - if (trace) { - if (strcmp(trace_fn, "-") == 0) { - comm_fd = STDIN_FILENO; - } else { - comm_fd = open(trace_fn, O_RDONLY); -#ifdef HAVE_ZLIB - gz_trace_file = gzdopen(comm_fd, "rb"); -#endif - } - } else { - fprintf(stderr, "apprentice host %s port %d\n", hostname, port); - comm_fd = apprentice_connect(hostname, port); - } return apprentice(); } }