From patchwork Fri May 22 02:34:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 187119 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2102997ilb; Thu, 21 May 2020 19:36:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYKG82Yy5IpVeLMR9waKktGCxSzPdkxOetcgqQupf9hV86JwOjIAsSaza1svEsctRJm7nU X-Received: by 2002:a37:e85:: with SMTP id 127mr12990912qko.178.1590115000748; Thu, 21 May 2020 19:36:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590115000; cv=none; d=google.com; s=arc-20160816; b=W/3EG6n6V4FXkNq94g09jYcNYZ25BP4qwxYeCILK3ie4Cu1HdhGyeqFapNYQNSnEIP Ede8/4+dsRGgphsYMLpqiXqHFJ1dd+P8Ml2fwpcxuWMlBScYwzQ+xJl2INIKtiM36Sxs sChuolaInd/HyvHTRzcJ0cRI1D4xZ3So1FIb2ytNlzF54FSajRKFg6KG3+DDyhHdU1u0 abxwp6JhyNuhrPHyVnNfrn1V0SeqM56Mz8uFuqiIehIvLQPryGPMOPbGv3npwOZSXtl4 mqtksZrZOMUTgQKq9N1Di6Vu4c8jQOpOMiWbhlOL4gI/wax05rLgDjINgzxtp05ghOzr ZOKg== 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=JQCGgvllP6/zU7ZDrHyu78GSFItc7dHunrM7u5X5NHY=; b=kPZ0hUCL4nvU/E4lYKV3zTVdH/lSP05WJbiprBrP5nYuS1Ge0S2Oo/vhXuUqDB8UCB 5cMqxgMNMUjxZ67WKKm0xlkqK15MMVEKl4bq0RBDrbs7FgAe8RpIqgglePO6vizlW5Fm 55n1Cn0paev+HnpkcYUBfS7gze5Hbtfsa4UjecyoD1+SLfWze4xmMxugqdJNtzBvkXkR r0r5dWeGJQC6atYNuw483igXChmmGSvPQIoaZnksfojduHC1JkzlsDwmib5A9Yk6VbDp 851Jo0MA6J3q/6NmzRaPgBhSJvYOSuURfB99jWcKGLjfTZW78+7jEI1ZNj1RKgc+7FGo F98Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yswuQWAA; 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 cu18si4280662qvb.99.2020.05.21.19.36.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 May 2020 19:36:40 -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=yswuQWAA; 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]:50976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbxY8-0006HM-8d for patch@linaro.org; Thu, 21 May 2020 22:36:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbxWJ-00023l-7I for qemu-devel@nongnu.org; Thu, 21 May 2020 22:34:47 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:40288) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jbxWI-00055p-Ai for qemu-devel@nongnu.org; Thu, 21 May 2020 22:34:46 -0400 Received: by mail-pj1-x1043.google.com with SMTP id ci23so4339821pjb.5 for ; Thu, 21 May 2020 19:34:45 -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=JQCGgvllP6/zU7ZDrHyu78GSFItc7dHunrM7u5X5NHY=; b=yswuQWAAOUpgZQ0p7M/vW8p9+vw1X2m4G5mfZdbfIurqVXZVw/ExYxvIWUwzmJN9X+ 34MJ6pLbTHePAfwHF8k1AuxfhY3D40HMcmVQfvCtotGimQPVqSUt80ueC61UHhXCyjPI h7uSddUVRDaYL2fWEthR6jWKNJTuLJ+HmnXJRw2+2l2+zGIued+XsjzpY9aBXRyM27KQ eRNOg+Z00DlV7x6IWIxJ1uF/k5dB1t3QAG0SBnkN0J1wUQO05Iah5Y/F0iucqmnHFsEc XZSs+nyvQFqPI9I+zeP8AIsNEIa8OdqmfrDMUmY7PzZOXCv7zsUi+vIlDVkqRT5OeLR+ PqhA== 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=JQCGgvllP6/zU7ZDrHyu78GSFItc7dHunrM7u5X5NHY=; b=SgaVYDm9LO7Ztg7P5ye7V3DGeiLCm0eCDfz0xcGdVrj3xuhsj6U8B+EtWTnW+2Zbp9 QArJWrz/pVIXPFVHDVOV8JyHkckiG08QvVAV0arq4gDP4K7HgaCaH/y25KF5kNn5U9b+ RSEYB4ICgI1S1w05eRjpneMDrwj85RNR1fIKN+943yelUsGxNlw/aDkCz3Mc8yg/rdkp KbIve9MYF+rKM4hZiGv+dRQ0QOmT8JCQ0RDbv3IkSyORwEb5lflUXvCzebugAGuVepmu 7wzSJ4nwUXj5/tYuLtwVxJ4R+GTEfJr2miqM6ZwKBtxrgTVSdCozi5/V98l1tPm4+6np VV6w== X-Gm-Message-State: AOAM531Xbhcv9Q9+WJP1jzuGz1Ie4UQMkCZgPEupZ9ka7Hdr6Owpxbv7 tzn3NWh2tudHbmCfox0BXywgNjEq/JE= X-Received: by 2002:a17:902:4b:: with SMTP id 69mr11442611pla.99.1590114884611; Thu, 21 May 2020 19:34:44 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 19:34:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 02/25] Unify master_fd and apprentice_fd to comm_fd Date: Thu, 21 May 2020 19:34:17 -0700 Message-Id: <20200522023440.26261-3-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::1043; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1043.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" Any one invocation cannot be both master and apprentice. Let's use only one variable for the file descriptor. Reviewed-by: Alex Bennée Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- risu.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) -- 2.20.1 diff --git a/risu.c b/risu.c index 79b1092..059348f 100644 --- a/risu.c +++ b/risu.c @@ -30,7 +30,7 @@ void *memblock; -int apprentice_fd, master_fd; +static int comm_fd; bool trace; size_t signal_count; @@ -50,7 +50,7 @@ sigjmp_buf jmpbuf; int read_sock(void *ptr, size_t bytes) { - return recv_data_pkt(master_fd, ptr, bytes); + return recv_data_pkt(comm_fd, ptr, bytes); } int write_trace(void *ptr, size_t bytes) @@ -58,9 +58,9 @@ int write_trace(void *ptr, size_t bytes) size_t res; #ifdef HAVE_ZLIB - if (master_fd == STDOUT_FILENO) { + if (comm_fd == STDOUT_FILENO) { #endif - res = write(master_fd, ptr, bytes); + res = write(comm_fd, ptr, bytes); #ifdef HAVE_ZLIB } else { res = gzwrite(gz_trace_file, ptr, bytes); @@ -71,14 +71,14 @@ int write_trace(void *ptr, size_t bytes) void respond_sock(int r) { - send_response_byte(master_fd, r); + send_response_byte(comm_fd, r); } /* Apprentice function */ int write_sock(void *ptr, size_t bytes) { - return send_data_pkt(apprentice_fd, ptr, bytes); + return send_data_pkt(comm_fd, ptr, bytes); } int read_trace(void *ptr, size_t bytes) @@ -86,9 +86,9 @@ int read_trace(void *ptr, size_t bytes) size_t res; #ifdef HAVE_ZLIB - if (apprentice_fd == STDIN_FILENO) { + if (comm_fd == STDIN_FILENO) { #endif - res = read(apprentice_fd, ptr, bytes); + res = read(comm_fd, ptr, bytes); #ifdef HAVE_ZLIB } else { res = gzread(gz_trace_file, ptr, bytes); @@ -218,11 +218,11 @@ int master(void) { if (sigsetjmp(jmpbuf, 1)) { #ifdef HAVE_ZLIB - if (trace && master_fd != STDOUT_FILENO) { + if (trace && comm_fd != STDOUT_FILENO) { gzclose(gz_trace_file); } #endif - close(master_fd); + close(comm_fd); if (trace) { fprintf(stderr, "trace complete after %zd checkpoints\n", signal_count); @@ -244,11 +244,11 @@ int apprentice(void) { if (sigsetjmp(jmpbuf, 1)) { #ifdef HAVE_ZLIB - if (trace && apprentice_fd != STDIN_FILENO) { + if (trace && comm_fd != STDIN_FILENO) { gzclose(gz_trace_file); } #endif - close(apprentice_fd); + close(comm_fd); fprintf(stderr, "finished early after %zd checkpoints\n", signal_count); return report_match_status(true); } @@ -375,31 +375,31 @@ int main(int argc, char **argv) if (ismaster) { if (trace) { if (strcmp(trace_fn, "-") == 0) { - master_fd = STDOUT_FILENO; + comm_fd = STDOUT_FILENO; } else { - master_fd = open(trace_fn, O_WRONLY | O_CREAT, S_IRWXU); + comm_fd = open(trace_fn, O_WRONLY | O_CREAT, S_IRWXU); #ifdef HAVE_ZLIB - gz_trace_file = gzdopen(master_fd, "wb9"); + gz_trace_file = gzdopen(comm_fd, "wb9"); #endif } } else { fprintf(stderr, "master port %d\n", port); - master_fd = master_connect(port); + comm_fd = master_connect(port); } return master(); } else { if (trace) { if (strcmp(trace_fn, "-") == 0) { - apprentice_fd = STDIN_FILENO; + comm_fd = STDIN_FILENO; } else { - apprentice_fd = open(trace_fn, O_RDONLY); + comm_fd = open(trace_fn, O_RDONLY); #ifdef HAVE_ZLIB - gz_trace_file = gzdopen(apprentice_fd, "rb"); + gz_trace_file = gzdopen(comm_fd, "rb"); #endif } } else { fprintf(stderr, "apprentice host %s port %d\n", hostname, port); - apprentice_fd = apprentice_connect(hostname, port); + comm_fd = apprentice_connect(hostname, port); } return apprentice(); }