From patchwork Wed Sep 18 07:31:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1986710 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BSiy3c4h; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X7r1P1pS6z1y1g for ; Wed, 18 Sep 2024 17:31:20 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 56EC63C2E4D for ; Wed, 18 Sep 2024 09:31:17 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 2BCED3C0EBB for ; Wed, 18 Sep 2024 09:31:14 +0200 (CEST) Authentication-Results: in-3.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=liwang@redhat.com; receiver=lists.linux.it) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 4AAB51B60EEB for ; Wed, 18 Sep 2024 09:31:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726644671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EtD488ZmOH11CIAm/+YVWwW+mcFvNuB8muDVhYlYMbQ=; b=BSiy3c4hDIozMXrONyGMjD0IhB0KFLtILBs9LX3+DY1mSBqyh79T8jP3AAqwv1SqoCSlmt 52GgLfDtmSqsVJU0GoAnwni9GBSL769W+0Ag/0nqbkVnMAIqly4l57QJ7Laf0Lj90KyGaa 2W8V/ALFMTvX90WSP9pGSKk4kZSp0hs= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-vTHuRmAhMCCi4_VUjvBDmw-1; Wed, 18 Sep 2024 03:31:10 -0400 X-MC-Unique: vTHuRmAhMCCi4_VUjvBDmw-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F2A411955D53 for ; Wed, 18 Sep 2024 07:31:08 +0000 (UTC) Received: from dell-per7425-02.rhts.eng.pek2.redhat.com (dell-per7425-02.rhts.eng.pek2.redhat.com [10.73.116.18]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9F70219560A3; Wed, 18 Sep 2024 07:31:06 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Wed, 18 Sep 2024 15:31:00 +0800 Message-ID: <20240918073101.13814-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-3.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-3.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH] lib: handle ENOENT errors when processes exit during PID scanning X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Charles Mirabile , Paul Bunyan Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" There is a race window between readdir() and fopen() in line 125~131 of lib function get_used_pids. A process could terminate after its directory entry is read but before its status file is opened. When fopen() is called, the status file may no longer exist, resulting in an error like: tag=msgstress01__with_dmesg_entry stime=1723563200 ... tst_test.c:1617: TINFO: Timeout per run is 0h 03m 30s tst_pid.c:128: TBROK: Failed to open FILE '/proc/73429/status' for reading: ENOENT (2) To resolve this, the file_lines_scanf() function is modified to handle ENOENT errors gracefully when strict mode is not enabled. If fopen() fails due to ENOENT, the function now returns 1 to skip the missing file instead of treating it as a critical error. Reported-by: Paul Bunyan Analysed-by: Charles Mirabile Signed-off-by: Li Wang --- lib/.tst_pid.c.swo | Bin 0 -> 16384 bytes lib/safe_file_ops.c | 3 +++ 2 files changed, 3 insertions(+) create mode 100644 lib/.tst_pid.c.swo diff --git a/lib/.tst_pid.c.swo b/lib/.tst_pid.c.swo new file mode 100644 index 0000000000000000000000000000000000000000..956a03da5090a5af543e0dca7eab124d2a2f1d67 GIT binary patch literal 16384 zcmeHNYiuJ|75=);CU)$^1%%2&z*#Tp+NtA5+7&I?tnlWsYc(&~PPf}qtcmA3zS{AO zHTOEZVf&&*lvknU4??9#AS8Yu1Omxo=*UeC4fg0z#|F3 zNdO;B0ObU5G6AF#z;pumdmQ+49C$Vk{4@?c9S0tc10oKXap1N%@UKbWTa&=~N#MjJ zkemdjCxPc;9$r$iR4ERJ0crXSOW5D}jz`J9>-=e_FQQ-Gc z;CE5rhf(00QQ&h?;Nd9nP!y;|f#oPrhyrs_AR7hV69wKC1#V)#3E&44z%vuT(-Xj> z6F_?cuqJ@pCxG|_@b7Wp^>N_Eap242z-PyS$HswAjRWiBz=?6-uSbEe90k636u9Ro zFntt=9|b0l0tFCGD2I0AhC2=L?)cyUk)nn7;} zu~4CX>3-@I*bOo_XEoli#^BgTwwY0iYudI}om&=v3Dcw5D&v=xG1rvwJUVpTaQ;r?>W+>^lZZthTZMdn|6l0 zu}lVd05MnSu4_}g$xrgh-g42yR}cYNNi_a38kcCdvfcR zY)hS9I$PP?-m2E`D%PuO<)xMS>Uu3pU1?^owbGlCI6o?JM7^#wY0>jdpjTI#>HY=< z%6r;e!=V8a`?P1woA>Mkh{gD4NUl)rbgjIxx|yZas?)Vi^87LE?nP;}R;g{S1^ZRsGpw%2QXxy_jT(m&Gd)1UQi8+$t*NruHZEUB z9Z!eV^4dzhx>VX&O&`QZmbS{vtU;Y4J4>kYI0F=-46^xRi{n$<(gUoJVy3{gmbcR@WIGI=vW_GjDe@US`rF^(&t* zzE|=*8efZgv#q_L^{n(N3C|9d5N~wICHEE!1uiaJFM?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A|7P0(nf7JsbK9RPK%d*{VGp$cLe5u0ba_@d{bZ&8|lh(5^Fp5qO&3bn?{W;(E zpfAZD>T!GQgX46XyV*D2OjpmG>YKtXYnDC4IDFy4YxM3;4z32g9_@fq>*bBU{(c|7 z*BayPJFNXb+GHELWq5-!1{-ce{H(gC>2Sk*)Zih7hwu4@Z{>#UzXFyTbW-`~@4M>I zM(ROo_Cv1U+g)1QtgZ}QSMn5Rj@Mt0^*QL4MW4OrA5JL$CdRwQSu1a>RIhQFGjLUz UrBuzo*8DK}mpY#Cz~34C2N*U}KL7v# literal 0 HcmV?d00001 diff --git a/lib/safe_file_ops.c b/lib/safe_file_ops.c index 63ae2dbbe..4cf0d6e0f 100644 --- a/lib/safe_file_ops.c +++ b/lib/safe_file_ops.c @@ -182,6 +182,9 @@ int file_lines_scanf(const char *file, const int lineno, fp = fopen(path, "r"); if (fp == NULL) { + if (strict == 0 && errno == ENOENT) + return 1; + tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn, "Failed to open FILE '%s' for reading", path); return 1;