From patchwork Sat Jun 17 05:36:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 13283446 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E7B4EEB64D9 for ; Sat, 17 Jun 2023 05:37:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qAOcV-0003OC-Py; Sat, 17 Jun 2023 01:37:07 -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 1qAOcU-0003Nh-2M for qemu-devel@nongnu.org; Sat, 17 Jun 2023 01:37:06 -0400 Received: from bg4.exmail.qq.com ([43.155.67.158]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qAOcS-0006Xe-8U for qemu-devel@nongnu.org; Sat, 17 Jun 2023 01:37:05 -0400 X-QQ-mid: bizesmtp73t1686980193tu7g7u6w Received: from ubuntu.. ( [111.196.130.174]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 17 Jun 2023 13:36:32 +0800 (CST) X-QQ-SSF: 01200000000000E0G000000A0000000 X-QQ-FEAT: rZJGTgY0+YOT3oQmERRSL+DXWsKs2Jcv63KNGwgGy65bHQCMbDNI5X4MYzei9 p5eWKVFGrxJBR+BhLzCExe7hqX7hGdVrJ1OoCx6NQxsUoY4m56F1O9bUZmKKMMSzU5tUaTE 7yKL+/MAYSaZ3s7E57uglnL0+H8AcY34D0kaDjlEqo+B0envreyzLRtCanqRbtjZo+wB2R+ NXJX3RYs+j/Wqk9QhhemKshbU0uPO997tAGHSznNC/uvHujBNiBriQaZyDaSNpPk0W65msX nIQKOZaqoa2AszbrNZYuvoJKpomVCfcOTIJ0uPjyGPWWijobI6ZdIfiHh3MmvQ2NMPFutHh SVchiRmR7fXk55Vu6V5bwXJOLXPqVLHQS2zupR9DwTJMBkIx0U= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 8674422273484162088 From: Bin Meng To: qemu-devel@nongnu.org Cc: Zhangjin Wu , Claudio Imbrenda , Markus Armbruster , "Michael S. Tsirkin" Subject: [PATCH v3 3/6] util/async-teardown: Fall back to close fds one by one Date: Sat, 17 Jun 2023 13:36:18 +0800 Message-Id: <20230617053621.50359-4-bmeng@tinylab.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230617053621.50359-1-bmeng@tinylab.org> References: <20230617053621.50359-1-bmeng@tinylab.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz7a-0 Received-SPF: pass client-ip=43.155.67.158; envelope-from=bmeng@tinylab.org; helo=bg4.exmail.qq.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_SBL=0.141, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org When opening /proc/self/fd fails, current codes just return directly, but we can fall back to close fds one by one. Signed-off-by: Bin Meng --- (no changes since v2) Changes in v2: - new patch: "util/async-teardown: Fall back to close fds one by one" util/async-teardown.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util/async-teardown.c b/util/async-teardown.c index 3ab19c8740..7e0177a8da 100644 --- a/util/async-teardown.c +++ b/util/async-teardown.c @@ -48,7 +48,11 @@ static void close_all_open_fd(void) dir = opendir("/proc/self/fd"); if (!dir) { - /* If /proc is not mounted, there is nothing that can be done. */ + /* If /proc is not mounted, close fds one by one. */ + int open_max = sysconf(_SC_OPEN_MAX), i; + for (i = 0; i < open_max; i++) { + close(i); + } return; } /* Avoid closing the directory. */