From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with UTF8SMTPS id 1EAA53889822 for ; Fri, 13 Aug 2021 07:05:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1EAA53889822 Received: by mail-wm1-x336.google.com with SMTP id i10-20020a05600c354ab029025a0f317abfso8940886wmq.3 for ; Fri, 13 Aug 2021 00:05:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version; bh=NL7hWLL9jHpJdJw/IvP/EcXd1fQU96T98qx783tUPz8=; b=SnZCkhSWWHME0DsBSGkQxKsv1Vy1wg8g4oZfvbvNDXKtqAnjJy7f2w4iqAsJcqQcaa Q7rPMleD8VWAsH0nHHcprwkNrAG4f9dyCCp09kVXrPwj3j4HCjKe4Wygc4nkx2GPtvqx tJ1tD2ds/wZIj0cyxcc668RtyJFh7NU6ELEU4UaiIM5LtuwEdKxCWGGFollam3hibogP 1tdpN4mS+5n3x/iOI1uumV5QLAXdjBCy41EhGcJrzLhKp06in+WQvediGckHzUW7gY2o RU+ECSGyfpCJetjl9IFveipw2o+vpbHKo3JhS1THsDJl34ZNs0XPXPDefqaT1Du9ki8U Fe2Q== X-Gm-Message-State: AOAM532UMfH04wBiTuA0+qwD38yyzqpTN9iGGSZ2kmAzVNJdM9rovh+1 I0Yn3z1Gm7lQNG8DF5sgHRk= X-Google-Smtp-Source: ABdhPJx+jI8HUBblfqXmLCA7PCmIxhSE8hS4Au/5lsTnPH8Qkfxl8JsqC7ggliAs7jqRMdxEZ4kurg== X-Received: by 2002:a05:600c:4fd1:: with SMTP id o17mr1168427wmq.131.1628838327228; Fri, 13 Aug 2021 00:05:27 -0700 (PDT) Received: from zn3 (host81-129-83-184.range81-129.btcentralplus.com. [81.129.83.184]) by smtp.gmail.com with ESMTPSA id g9sm504908wmk.34.2021.08.13.00.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Aug 2021 00:05:26 -0700 (PDT) Date: Fri, 13 Aug 2021 08:05:08 +0100 From: Sergei Trofimovich To: Ian Lance Taylor Cc: gcc-patches@gcc.gnu.org, Ian Lance Taylor , Sergei Trofimovich Subject: Re: [PATCH] libbacktrace: fix fd leak tests on systems with extra descriptors Message-ID: <20210813080508.09afde43@zn3> In-Reply-To: References: <20210812223336.3398471-1-slyich@gmail.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.29; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="Sig_/XQVf9lHJ1NCGBg/WoVRtBGd"; protocol="application/pgp-signature"; micalg=pgp-sha512 X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2021 07:05:29 -0000 --Sig_/XQVf9lHJ1NCGBg/WoVRtBGd Content-Type: multipart/mixed; boundary="MP_/yKPf6_m96BFVUciHOoGnz__" --MP_/yKPf6_m96BFVUciHOoGnz__ Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Thu, 12 Aug 2021 16:16:04 -0700 Ian Lance Taylor wrote: > On Thu, Aug 12, 2021 at 3:34 PM Sergei Trofimovich via Gcc-patches > wrote: > > > > From: Sergei Trofimovich > > > > I noticed test failures when ran gcc test suite from under mc shell. > > mc opens fd=3D9 and exposes it to child processes. As a result a few > > tests failes: > > FAIL: b2test_buildid > > FAIL: btest_gnudebuglink > > FAIL: btest > > FAIL: btest_lto > > FAIL: btest_alloc > > FAIL: ctestg > > FAIL: ctesta > > FAIL: ctestg_alloc > > FAIL: ctesta_alloc > > FAIL: dwarf5 > > FAIL: dwarf5_alloc > > > > Instead of trying to close file descripts in range test polls for > > first available file descriptor by creating it via dup(1). > > > > libbacktrace/ > > > > * btest.c (check_open_files): Use last free file descriptor as a > > signal for flie descriptor leak. =20 >=20 > This isn't a useful replacement, as this will pass as long as > libbacktrace closes the first file descriptor that it opens. It won't > check whether libbacktrace left any other file descriptors open. >=20 > Perhaps at program startup we could fstat descriptors up to 10 and > record whether they are valid, and then skip those files in > check_open_files. Oh, great point! Completely missed it. Changed the patch to poll for present file descriptors with fcntl(fd, F_GETFD) to compare before/after. --=20 Sergei --MP_/yKPf6_m96BFVUciHOoGnz__ Content-Type: text/x-patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=v2-0001-libbacktrace-fix-fd-leak-tests-on-systems-with-ex.patch =46rom dba67cc728d6be521f59a4c0d3abe7879de2db4c Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Thu, 12 Aug 2021 23:27:00 +0100 Subject: [PATCH v2] libbacktrace: fix fd leak tests on systems with extra descriptors I noticed test failures when ran gcc test suite from under mc shell. mc opens fd=3D9 and exposes it to child processes. As a result a few tests failes: FAIL: b2test_buildid FAIL: btest_gnudebuglink FAIL: btest FAIL: btest_lto FAIL: btest_alloc FAIL: ctestg FAIL: ctesta FAIL: ctestg_alloc FAIL: ctesta_alloc FAIL: dwarf5 FAIL: dwarf5_alloc Instead of trying to close file descripts in range test polls for their presence with with fcntl(fd, F_GETFD) before and after test. libbacktrace/ * btest.c (check_open_files): Use fcntl to poll for file descriptor presence. --- libbacktrace/btest.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libbacktrace/btest.c b/libbacktrace/btest.c index 9f9c03babf3..c08c1540fa6 100644 --- a/libbacktrace/btest.c +++ b/libbacktrace/btest.c @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. */ libbacktrace library. */ =20 #include +#include #include #include #include @@ -458,6 +459,18 @@ test5 (void) return failures; } =20 +#define MAX_FDS 10 +static int fd_states[MAX_FDS]; + +static void +store_open_files (void) +{ + int i; + + for (i =3D 0; i < MAX_FDS; i++) + fd_states[i] =3D fcntl (i, F_GETFD); +} + /* Check that are no files left open. */ =20 static void @@ -465,9 +478,9 @@ check_open_files (void) { int i; =20 - for (i =3D 3; i < 10; i++) + for (i =3D 0; i < MAX_FDS; i++) { - if (close (i) =3D=3D 0) + if (fcntl (i, F_GETFD) !=3D fd_states[i]) { fprintf (stderr, "ERROR: descriptor %d still open after tests complete\n", @@ -484,6 +497,7 @@ main (int argc ATTRIBUTE_UNUSED, char **argv) { state =3D backtrace_create_state (argv[0], BACKTRACE_SUPPORTS_THREADS, error_callback_create, NULL); + store_open_files (); =20 #if BACKTRACE_SUPPORTED test1 (); --=20 2.32.0 --MP_/yKPf6_m96BFVUciHOoGnz__-- --Sig_/XQVf9lHJ1NCGBg/WoVRtBGd Content-Type: application/pgp-signature Content-Description: Цифровая подпись OpenPGP -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQKTBAEBCgB9FiEE+g11JqJ4cL44QkmN7V5F4G8qwpMFAmEWGaRfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldEZB MEQ3NTI2QTI3ODcwQkUzODQyNDk4REVENUU0NUUwNkYyQUMyOTMACgkQ7V5F4G8q wpNi2A/9E5aFf5xIExSz76HXad64Gw+o/W0xQE2Kr2vaCLylPpsvbHB9hdc3vzSa 573/7u3WSDHfWOofplgiVMNGMSJWP0ef24EFlMu8QZp8F1fxSjWeNVhsJXBqbdBn pqkyJaUzfkFkqngFt3neVbWjUeTUjgiG+YWdtuIR580mMQA99NjLHrTSdDB7d70G 0lrK7JtDbzXOwZ7EGA1IHlM7yGeJ0Ve24WXMEMvtKr2JkzdXY8P17PLYN9SZmCDQ spuupG65igI2N65DwBVxhOcG89iVsbKsgNeZXUCUnIShG0v8PuxT97/9Qx1F0KZD /iKBLfLaemW9iIjtl7JONWWKJXDHRmmjTm8A93PHI689NJ5K1mDVQyUpM+4jiEp6 Oq9rFnOaPkXr291f27IwxpkEnqh2sh3h4tPICjwGaz6dblHZCblhSWtuYWNytGUA tsJDNHpKgldwtSEjZ9YiwmOpHaBvJQ7uyOicNJqvMluRD3LHm7JEsp2W5CQVVKDb OnsLF3yvr/DVRdE1R6HR0od/44Q2JYVEg+o3IbuQW4ze3Kfe3XjJUm2gllnpt/+v EGZBsUJxAyoDg/rhkd0WISLiSzhuzNXHWKupL5At7Sn6E+mkhGc/oOWnax1Jv6Bd uQEAzLz1RLp8lLo/zoLr8HgNYJK248YvLPM2IwZncDM2iU2gk1U= =TIri -----END PGP SIGNATURE----- --Sig_/XQVf9lHJ1NCGBg/WoVRtBGd--