From patchwork Mon Aug 5 00:31:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 816729 Delivered-To: patch@linaro.org Received: by 2002:adf:e00d:0:b0:367:895a:4699 with SMTP id s13csp1133627wrh; Sun, 4 Aug 2024 17:32:40 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWc8VAiDNQZ3tgsCVpS4i7J7e/OVm7QUSTFWHQMQ5k4vSkqhUgEXxvcreWkL4MPMP19SSZ+8UZdqMHEXPf/Tthi X-Google-Smtp-Source: AGHT+IEzlWO7DXwCqNv+LAoqkPihihh/5Cj5njSOzECp+DMqdCyURqQuWOEDaP11Z2E0y6K/lxuW X-Received: by 2002:a05:6902:13cc:b0:e03:a3ac:fb75 with SMTP id 3f1490d57ef6-e0bde2622dcmr12084189276.23.1722817960602; Sun, 04 Aug 2024 17:32:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722817960; cv=none; d=google.com; s=arc-20160816; b=TI6Sr4sIgibz18qGHc6D+82EyA9m/wHnBDRo8lixffeHxxxv4XC0FwzUQNNY6OaW7H Mx9FraoqYIYfeTWIFWwf9uE3/BhPwrZPiNYoejF5hT1vE/WUFGel+kn4PINyRotQasrH mU+1Mb+cTi27588g9Zj+lILJ4HrQ3D8zIvh5E84iEeuFAIWhIDR/WBJ+jqqEV4vq6rE/ CGAMeRl0LrEZLGIsBWJceNnNV3ov5C2DuWDcaxYQb+t84Z3+wKj9SrEGj9tjtW0HfSzF xu7TzJsl1gHsiHdUZTd5B1OuNxHrVegtDFG8c44Pm4ajeOnq/TsFZxdZypxDsu3UxE6K t28w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=zCe4GkwH/iAnpmcpXgqjGYu6VSZ8QZlYv/hHC8b9IYI=; fh=j2Ck7JJDkuIhuIM6fXlcQpeLsiCqZ/awsmByeQRTUsY=; b=Of8WaoyLst4jqY4GVCYNtQDifaqLll7Clrq/RBenBFxHQjg+ZIr3Nh5mhKufmEjYFX yLtqeB2enKd7s5wJjWf/vDeaBW+xhHFdTe8BWbsNwAujfhJaBRtmcRZ8Uf01XZCJvAyC nIDpcC5XicEydxi4y1PXG5m8A+Xof0kuQ1MhgfB36DyBkHBT3fbkj7dcd5zzIqODAML8 pMR8hyh1be9qp3qcX5XuswmTY6R5NQZERMpPi5QRTBD9x38D6I3Xy6uv/ZJfrNccda3n VaMbYRMIzn1sEeGGT60YU48kPg4/UYaDUlSFHTnMwkP+GiQEuSt/j+zrIXvVaDXoZNl9 mM0g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rdkeGhj1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4518a6bd0b1si81321461cf.24.2024.08.04.17.32.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 04 Aug 2024 17:32: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=pass header.i=@linaro.org header.s=google header.b=rdkeGhj1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1saldn-00006d-MW; Sun, 04 Aug 2024 20:31:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1saldl-0008PV-8c for qemu-devel@nongnu.org; Sun, 04 Aug 2024 20:31:57 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1saldj-0002KC-LK for qemu-devel@nongnu.org; Sun, 04 Aug 2024 20:31:57 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-70eaf5874ddso7494603b3a.3 for ; Sun, 04 Aug 2024 17:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1722817914; x=1723422714; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zCe4GkwH/iAnpmcpXgqjGYu6VSZ8QZlYv/hHC8b9IYI=; b=rdkeGhj16oa8Y5B8j6NgH7jUWTJkb1fHjsRMQFoVhbrYuMCJcGGe+4+/FTsk/ipgWb 5PZ8kCs/7w6tBt7phOj8g9buewNhOE9+/J89nSEFteJBqcpl7uwI55ANK+yTcjvODb/8 WjvOvg91F5a9Y/nvMYd21I3IvVeO6R3NSN7SZ2X7deG/D71GdDUsgnqn6+uR3dCBhwMi mLsQWtHpb7dsbiKTLFNoIEu3dCSD8U9wAZ4Wh5s57lHPW+DovOZBE8QmVWHGOpTjOOkk 32NtHvbFkKv8QPSh7wIIICFYtMmQs+7rJb9poU3pgXk1Q8pGmHnQ1mvoEYAiH8AOx5Mz 5kMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722817914; x=1723422714; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zCe4GkwH/iAnpmcpXgqjGYu6VSZ8QZlYv/hHC8b9IYI=; b=r+gSc7Qdm3BkhDQ/A0awXJPRGXtuXlLe8EyYzeUam22kOfp2gYsPisUzl1ZtFoL6AC maYPXoyCmxKDSCez2pR5yytyLG3O09kEqy/I3XJGtOAmORpT9fb1Gjajm6jLkzBVbuNG +bJWrGnMAi/SSbcmn54wOwDa+0hqpqcf+Cur8Snr+6Z992HmR72knKYoYboMlvnQMyDk jJKIXSMcxAk1bxgYYPRDHWEuZyko/tPd/cfXR5mQidLYArr2KqnikRL4Ae1eLBYifCC7 jQr+34c+HJyfTIwVLaQPta/bs9Lqj0isr0XZOd/YbXsHrlevxnzP1MVQWUWsTIGX1EXH IseQ== X-Gm-Message-State: AOJu0YziB3XwGQibUombyQ6LMUIuI1F3F02gaZmZakdce6JqTYCCtc3m nnAIQxce50jWwOMzUgAd1m0arN3C9rhU7sekHtwc7/nBmmsqGJGC18E1A0YDGICFIBdGW0FmO0U UYHaLAg== X-Received: by 2002:a05:6a20:8416:b0:1c4:b927:1ffb with SMTP id adf61e73a8af0-1c69953db33mr9534159637.17.1722817914049; Sun, 04 Aug 2024 17:31:54 -0700 (PDT) Received: from stoup.. ([203.56.128.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed16cb3sm4576038b3a.179.2024.08.04.17.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Aug 2024 17:31:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PULL 6/6] net/tap: Use qemu_close_all_open_fd() Date: Mon, 5 Aug 2024 10:31:29 +1000 Message-ID: <20240805003130.1421051-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805003130.1421051-1-richard.henderson@linaro.org> References: <20240805003130.1421051-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.google.com 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_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Clément Léger Instead of using a slow implementation to close all open fd after forking, use qemu_close_all_open_fd(). Signed-off-by: Clément Léger Reviewed-by: Richard Henderson Message-ID: <20240802145423.3232974-6-cleger@rivosinc.com> Signed-off-by: Richard Henderson --- net/tap.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/net/tap.c b/net/tap.c index 7b2d5d5703..3f90022c0b 100644 --- a/net/tap.c +++ b/net/tap.c @@ -387,13 +387,20 @@ static TAPState *net_tap_fd_init(NetClientState *peer, static void close_all_fds_after_fork(int excluded_fd) { - int open_max = sysconf(_SC_OPEN_MAX), i; + const int skip_fd[] = {STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO, + excluded_fd}; + unsigned int nskip = ARRAY_SIZE(skip_fd); - for (i = 3; i < open_max; i++) { - if (i != excluded_fd) { - close(i); - } + /* + * skip_fd must be an ordered array of distinct fds, exclude + * excluded_fd if already included in the [STDIN_FILENO - STDERR_FILENO] + * range + */ + if (excluded_fd <= STDERR_FILENO) { + nskip--; } + + qemu_close_all_open_fd(skip_fd, nskip); } static void launch_script(const char *setup_script, const char *ifname,