From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 86BF7A04AB; Wed, 6 Nov 2019 15:59:07 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 38B081C205; Wed, 6 Nov 2019 15:59:07 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 3E3CA1C204 for ; Wed, 6 Nov 2019 15:59:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573052345; 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: in-reply-to:in-reply-to:references:references; bh=tAvNPVr9SvT9LidwyxQQFHdszitKrII+VzJJAhrsIVc=; b=MGfTacQfrBzWgt/RmMNiqmwp1gtSuG9iL1+3+mlFVVR2lsWWHddnpswxNiAV8KbQGRF2tt IqsomOSMDH36jH47KSd23Na8GJ2Nf/AnFJ4Jeo7wOL/FR8eXBxWFw2zg47DytwJ3TQKe9g uNa4vXGv1QYDNbV1OTFIB4JfhCctGjk= Received: from mail-vs1-f71.google.com (mail-vs1-f71.google.com [209.85.217.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-137-XQiowrS2PHymY3QTFVOtqg-1; Wed, 06 Nov 2019 09:59:02 -0500 Received: by mail-vs1-f71.google.com with SMTP id y125so729550vsb.21 for ; Wed, 06 Nov 2019 06:59:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qx9Jafuv+OgkDn/erXJna5WOXZVNKBbPk4CUXmNygo0=; b=Zy2AwzoUTstmVFgCnziod6irCSrfT+GmFbF1ZK6lfQ8PemPDpqbyUmWQ6adLMJ5llM W1Oqpv1LZs4EEWDfmsrDMEXncnJ5is94bECrgucGNZsqbVjjZq+5FXnfYnJLSVxUq4ea /Nc6cvGhGEOOmAZ1Os1YPmDnSbKfmMs7cKJ2vgwf47PVTrWCtQotBByI8Mg5uHSCVkz9 XFtMxgtfEiD8j5XtwljDPDebNTo0FHjzww42is79a5U033S5mo4aKBeiC15jW+BSs9td QGyoV+xGbbxqsWsak3f8oWepeg8bCWU/t0EiBQVfWs/3kt/Q3Mh6QeEdoOeq5x2Q/3qc ST4w== X-Gm-Message-State: APjAAAX1lFz38xG7u8+1q8lEGkOSjFeq98fVEx44zjz107REooJp9w7x FLkFmt+6SJtxG0tYR/EDnLxzCINDTLie4Pa9GBvcxPmfWvrkumrmQ49kmO6CoEgwp4aSnWLmnQj nsnoF2XKJ3NIHCL5caQE= X-Received: by 2002:a67:7d95:: with SMTP id y143mr1513416vsc.39.1573052341681; Wed, 06 Nov 2019 06:59:01 -0800 (PST) X-Google-Smtp-Source: APXvYqysco7zkk79XrDn9ivDUc1h8JNqdS4Itos8QcDgRnao04m1yiky/FjVZB5gSSK4JfPOUOMp0QCrTCdCgH8XKrs= X-Received: by 2002:a67:7d95:: with SMTP id y143mr1513386vsc.39.1573052341123; Wed, 06 Nov 2019 06:59:01 -0800 (PST) MIME-Version: 1.0 References: <20190902075251.2917-1-kkanas@marvell.com> <20190902094939.20482-1-kkanas@marvell.com> In-Reply-To: <20190902094939.20482-1-kkanas@marvell.com> From: David Marchand Date: Wed, 6 Nov 2019 15:58:50 +0100 Message-ID: To: Krzysztof Kanas Cc: dev X-MC-Unique: XQiowrS2PHymY3QTFVOtqg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [dpdk-dev] [PATCH v2] test: fix process dup fd close X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Mon, Sep 2, 2019 at 11:50 AM wrote: > > From: Krzysztof Kanas > > process_dup was intending to close it's own fd's but failed to do so Please, explain how you caught the issue and what the impact was on your sy= stem. > > Fixes: af75078fece3 ("first public release") Cc: stable@dpdk.org > > Signed-off-by: Krzysztof Kanas > --- > v2: > * remove unnecessary commit msg information > > app/test/process.h | 40 +++++++++++++++++++++++++++++++++++----- > 1 file changed, 35 insertions(+), 5 deletions(-) > > diff --git a/app/test/process.h b/app/test/process.h > index 128ce41219a1..2a6428f104e1 100644 > --- a/app/test/process.h > +++ b/app/test/process.h > @@ -11,6 +11,7 @@ > #include /* NULL */ > #include /* strerror */ > #include /* readlink */ > +#include > #include > > #include /* strlcpy */ > @@ -40,8 +41,12 @@ process_dup(const char *const argv[], int numargs, con= st char *env_value) > { > int num; > char *argv_cpy[numargs + 1]; > - int i, fd, status; > + int i, fd, fdir, status; > + struct dirent *dirent =3D NULL; No need to initialise to NULL. > + const char *procdir =3D "/proc/self/fd/"; self is a Linux thing. This won't work on FreeBSD. > char path[32]; > + char *endptr; > + DIR *dir =3D NULL; Idem, no need to initialize. > #ifdef RTE_LIBRTE_PDUMP > pthread_t thread; > #endif > @@ -58,11 +63,36 @@ process_dup(const char *const argv[], int numargs, co= nst char *env_value) > > /* close all open file descriptors, check /proc/self/fd t= o only > * call close on open fds. Exclude fds 0, 1 and 2*/ > - for (fd =3D getdtablesize(); fd > 2; fd-- ) { > - snprintf(path, sizeof(path), "/proc/" exe "/fd/%d= ", fd); > - if (access(path, F_OK) =3D=3D 0) > - close(fd); > + dir =3D opendir(procdir); > + Remove empty line. > + if (dir =3D=3D NULL) { > + rte_panic("Error opening %s: %s\n", procdir, > + strerror(errno)); > + } > + > + fdir =3D dirfd(dir); > + if (fdir < 0) { > + status =3D errno; No need to set status, this (forked) process will panic. > + closedir(dir); > + rte_panic("Error %d obtaining fd for dir %s: %s\n= ", > + fdir, procdir, strerror(status)); > } > + > + while ((dirent =3D readdir(dir)) !=3D NULL) { > + errno =3D 0; > + fd =3D strtol(dirent->d_name, &endptr, 10); > + if (errno !=3D 0 || dirent->d_name =3D=3D endptr)= { If you want to validate that the entire string is valid: if (errno !=3D 0 || endptr[0] !=3D '\0') > + printf("Error converint name fd %d %s:\n"= , > + fd, dirent->d_name); converting > + continue; > + } > + > + if (fd =3D=3D fdir || fd <=3D 2) > + continue; > + > + close(fd); > + } Missing closedir(). > + > printf("Running binary with argv[]:"); > for (i =3D 0; i < num; i++) > printf("'%s' ", argv_cpy[i]); > -- > 2.21.0 > --=20 David Marchand