From owner-freebsd-hackers@freebsd.org Wed Jul 8 16:44:55 2020 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A148536745E for ; Wed, 8 Jul 2020 16:44:55 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4B24sf4710z4Hk3 for ; Wed, 8 Jul 2020 16:44:54 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-wm1-x344.google.com with SMTP id q15so3962755wmj.2 for ; Wed, 08 Jul 2020 09:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=u4BJ22WQdhpcGTCNVCoNj4ZYInrPEOaIQ/WeB3GbfJI=; b=VSbXxn9yVPw/6YQ0t78WVY1jY92CkukdYOp5LLP8ZB3zWxn9qF/7FLYH9zG7Tk/u9r qNZYDXfKAj098s5vYmozBtl0hPnfpNMBDN293ZkAh79FvfGxX4qkqMWq1KNAk52edliI Jvm293Cob/XcoQRFWQeSevYaIGTWf1Ymql0rldPdhhLC3pMMLSQ6w/ecB777aCrK72eU gmMBWbHDnPmZaDm9+wXJyVcL95FZNQAOJE+bg2Q8XggXk4Klucxn0FcHRZ9ifdYgutKx DEKThV86a/bqL7fvEvbqN+3tK9dY0SDE6GxDNZWK2vbwemMV/xSDz+XPfEbjD0I93iyH hDTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=u4BJ22WQdhpcGTCNVCoNj4ZYInrPEOaIQ/WeB3GbfJI=; b=WV/lZE+7tdFFBkweuRydJ32442qE9UYdaT0ZFWR7d0jfXyiluwV+9MuXPALPnBupSK Y1qkMpKMGWO4ZeoCzkvCQgNRTPzykKmfzDeGrNcvfbg15Foukl42o5/14TUMVtZh3QnO m7ckTy6sRb1MqTTCMVTRgYC+nN6yFvsZan5X1D3tXN32LvSpMO8E3zGlXTio+QWpr4wJ Fhi4qxThaAyJ1j0Et4na651cIctNhU+qtaT+c0tbqNTE1ZONu1h0nbBCfSA7hlZ9yhSI 9/J0mnj6U6NcmNQpZZFuO9Hwfkdrjqo3SufKS9OONKehc5lkj5JkaVeB6YJjhNvKlQ93 EfUQ== X-Gm-Message-State: AOAM531faFldkJym7iGdOln7l+jOZ7V9Y57fiSVYSKoug9BrDP9Z5VDl Bmnczw9vEH96ltSciJ3KxNxYTQwkz7OKXR5X7J1u3w== X-Google-Smtp-Source: ABdhPJyrj6M7rznlbBgok8av/2SwH9GIZW4QODjxPGE8Dw1Wg0L8+dW388fx66KbmL8J7y7heOQwkdJccy+RqCyh7Jg= X-Received: by 2002:a1c:e90d:: with SMTP id q13mr10509207wmc.187.1594226693075; Wed, 08 Jul 2020 09:44:53 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:adf:9d84:0:0:0:0:0 with HTTP; Wed, 8 Jul 2020 09:44:52 -0700 (PDT) In-Reply-To: <21b0280d-c290-f27f-98a9-0c2242380718@rawbw.com> References: <21b0280d-c290-f27f-98a9-0c2242380718@rawbw.com> From: Mateusz Guzik Date: Wed, 8 Jul 2020 18:44:52 +0200 Message-ID: Subject: Re: Is it possible to determine the open file path based on the file descriptor? To: Yuri Cc: Freebsd hackers list Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 4B24sf4710z4Hk3 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=VSbXxn9y; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of mjguzik@gmail.com designates 2a00:1450:4864:20::344 as permitted sender) smtp.mailfrom=mjguzik@gmail.com X-Spamd-Result: default: False [-2.10 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.99)[-0.987]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36:c]; FREEMAIL_FROM(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; NEURAL_HAM_LONG(-1.05)[-1.054]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::344:from]; NEURAL_HAM_SHORT(-0.05)[-0.054]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; SUBJECT_ENDS_QUESTION(1.00)[]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVFROM(0.00)[gmail.com]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jul 2020 16:44:55 -0000 On 7/8/20, Yuri wrote: > Hi Hackers, > > > One of the ports (sysutils/watchman) attempts to find the path of the > file based on the file descriptor assuming that this descriptor > represents an open file. > > > Is this possible? > > Yes and no. procstat -f can report that, but not always. The crux is that the namecache is optional -- no name may be present and then we don't have good means to find it. There is a side corner case where you can have *more* than one name and then the kernel has no idea which was used to reach the file for given fd. I think the namecache should start getting new names in all cases and that's perhaps something to change for 13. Even for the working case the interface used by procstat is a bad pick. That said, I can add a fcntl which will translate the fd into a full path if the name can be found, but I don't know how useful it can be with this program given the stipulation above. -- Mateusz Guzik