From nobody Sat May 14 19:45:26 2022 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 863101ADAB18 for ; Sat, 14 May 2022 19:45:36 +0000 (UTC) (envelope-from paulf2718@gmail.com) Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (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 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4L0wwb6TBLz4SBL for ; Sat, 14 May 2022 19:45:35 +0000 (UTC) (envelope-from paulf2718@gmail.com) Received: by mail-wr1-x42c.google.com with SMTP id d5so15587560wrb.6 for ; Sat, 14 May 2022 12:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:to:content-language:from :subject:content-transfer-encoding; bh=sThllVnUSz0WI33ViM3VYB7LHitfZC//XYfl4yzE1t0=; b=gNddXaWA58w+9KXGJzPrUVQc6TuSqpsr6tEkiER07iZ4BfHIPVzzXisqb+uoO6uVxS gEABFqcCVSfOOZN7FXd0pJDhLXCe/vqGQgmYbwaWAejHBj688M2a+RuSI59IrYMe8btU yfqsKWknTxkCUTbdP0RdtkNrOP0eLeSQ/XvzzzerbN7u8FOQwrH4pW3sDhrjM/c1GdOv jeeZDY9LK6qUM7YVQynQYsjYJs2dtb9PHW2WezRuQauQzsMlVmrIlvY+qVGSdPw5pbMo PPkqyveRorrzRzdNUkL+9VpFijAkwNv9PEmZYIackJ2mMw8uJC5TIhurjBpPF9aGnS7+ 4aHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:to :content-language:from:subject:content-transfer-encoding; bh=sThllVnUSz0WI33ViM3VYB7LHitfZC//XYfl4yzE1t0=; b=6dh9I5xerWrrFzMfOtfpp38EuFB/hzPqf4FimFMR4WZ8wpIM+fNZ1tKUG5oYpMICzm 2YnxyVKFc/bnHKoeSOfdu43P7mzTSj3YwpnwOa7D3IHqL9bqaLtBGJuQ3FY2a+kJUGor ffaCMvR5Df5YU/EOrVoDHWqDJaRs8raGDNkqZw4g+bHSb4aBrBl/MI1+15iXCxBGdQuQ sl9QXU+cZmRz/v3kEPNtzcuTBpT7tA3Yj7MG120wILHJqIscKFtcP4GXwnwprPk3AzOh MOcNzzJV2elBQWL+8P4oa8ugIAE+2j/qqYXifXkkmVq7M80/ipXvfLlmKClkZklN9KHG qYTA== X-Gm-Message-State: AOAM530y/JRVYbw6duL553OetXgUFdNDt2RdHdQ7PcOvecwcwBtIJZOY eljsOIkjXLKkDIFBbHr86aIEcVVerfI= X-Google-Smtp-Source: ABdhPJweJRzcNgYcKY//ua4aQ7vKsUoh/kHWjBeoR6QjschD5Q63QjqdQ+aw9xlbB+YSsP0XeasQMg== X-Received: by 2002:adf:f3cb:0:b0:20c:8afd:9572 with SMTP id g11-20020adff3cb000000b0020c8afd9572mr8497425wrp.179.1652557528875; Sat, 14 May 2022 12:45:28 -0700 (PDT) Received: from [192.168.1.28] (lfbn-lyo-1-398-93.w2-7.abo.wanadoo.fr. [2.7.225.93]) by smtp.gmail.com with ESMTPSA id w22-20020a7bc116000000b003945f955b51sm8809680wmi.3.2022.05.14.12.45.28 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 May 2022 12:45:28 -0700 (PDT) Message-ID: <5e7863b6-4c57-16a2-0b54-655defefb347@gmail.com> Date: Sat, 14 May 2022 21:45:26 +0200 List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 To: freebsd-hackers@freebsd.org Content-Language: en-US From: Paul Floyd Subject: fcntl F_KINFO for Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4L0wwb6TBLz4SBL X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20210112 header.b=gNddXaWA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of paulf2718@gmail.com designates 2a00:1450:4864:20::42c as permitted sender) smtp.mailfrom=paulf2718@gmail.com X-Spamd-Result: default: False [-4.00 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36:c]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_NONE(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[gmail.com:+]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RECEIVED_SPAMHAUS_PBL(0.00)[2.7.225.93:received]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; MID_RHS_MATCH_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.999]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20210112]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::42c:from]; MLMMJ_DEST(0.00)[freebsd-hackers]; RCVD_TLS_ALL(0.00)[] X-ThisMailContainsUnwantedMimeParts: N Hi I'm working on updating Valgrind for FreeBSD 13.1. I've been trying to rewrite some of the code (used in tracking file descriptors, --track-fds=yes) to use fcntl and F_KINFO. The old code was IMO ugly, using KERN_PROC_FILEDESC to get info on all open files and then do a linear search for the fd. The new code is a lot shorter, but it doesn't quite work correctly. The Valgrind regression test system redirects stdout and stderr, which it then filters and compares to reference files. fcntl / F_KINFO doesn't seem to work correctly with fd 1 (or at least, that seems to be the problem the most often). Here is a small reproducer #include #include #include #include #include #include #include int main(void) { struct kinfo_file kf; kf.kf_structsize = KINFO_FILE_SIZE; if (0 == fcntl( 1, F_KINFO, &kf )) { printf("fcntl succeeded %s\n", kf.kf_path); } else { printf("fcntl failed\n"); } } Compiled with clang -g -o fcntl fcntl.c Then run it. For the first run $ ./fcntl > foo $ cat foo fcntl succeeded There's an empty string for kf_path there. Now that foo exists $ ./fcntl > foo $ cat foo fcntl succeeded /usr/home/paulf/foo Am I doing something wrong here or is this a bug / misfeature in the implementation of gcntl / K_INFO? A+ Paul