From patchwork Sun Jul 30 19:25:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1814685 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=hFAsoJoM; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RDWZk1mzmz1yVt for ; Mon, 31 Jul 2023 05:26:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4360F385842C for ; Sun, 30 Jul 2023 19:26:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4360F385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690745196; bh=x6AL2zme0Gvfi5ghIEP+Xa4XllZFzxBtx9Qm74O9Nd8=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=hFAsoJoMgT3xAaF8QxR2CRO4Y8JW7DF36EYdQEDAzA7eDfyFfi78yAexEoujTJq57 8dzxpdRGhPAw0ON/qTubjZQvle1xznsBL/uCjANR8lVGdehk1eWwBUsujxbu9c4DTC hz3WQz3k+6DADHQiLLEN9lZkv7VUrQ6Lh19jwvJ4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id 22AF33858D39 for ; Sun, 30 Jul 2023 19:26:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 22AF33858D39 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4f95bf5c493so5986731e87.3 for ; Sun, 30 Jul 2023 12:26:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690745173; x=1691349973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x6AL2zme0Gvfi5ghIEP+Xa4XllZFzxBtx9Qm74O9Nd8=; b=bVeavtC45EtHP3eej79xd0Id/0hHNNteNLzZCfIMgUWwjrjUMi4cpWtckiywPnO7BG /dyUTC3I8QzKBIaXX1U/IiMqv8QkiaXkAj+6Ks66PaehUiCpwvIzJfQzTp6op3ELKmOk 38EKw7EPsSqqa7r4DOhWzeEr1Nbw633ISJlh/vHwHuALLIVNIEfzPXmiD5XTp/ILwrdT sGoj5/dPiQjN5f7UhqbOVhMdvRSOgShWPiF5ijeWUtx1UjdfBQ0YfGCHOhgQTjhRBHdY +Q/f4TnwtOYhDVe7gMYqdMG1Oby/JOhNJVmQ1CQTNkDgYcs5e6Qba8roP9do8kmlc72q hoYQ== X-Gm-Message-State: ABy/qLZRSaK0Pxdvfs+5FowxxeHVqXRjmPx43uF5A6OAJCYRpv5jUfOM 1KzR0Y9h8B1gpnM8VD26Z5nRnwlcVKsqvA== X-Google-Smtp-Source: APBJJlHVdL1asPprDLXIfrT4P0IbjjKYBIspcbZ1j5KFQBGO0rZBOod3FV2OBmtQAKnIup53BnZ3lA== X-Received: by 2002:a05:6512:607:b0:4fb:7447:e71a with SMTP id b7-20020a056512060700b004fb7447e71amr3537625lfe.63.1690745173532; Sun, 30 Jul 2023 12:26:13 -0700 (PDT) Received: from localhost.localdomain ([2a02:2168:b344:a600:4435:f106:1598:d2b0]) by smtp.gmail.com with ESMTPSA id y8-20020a197508000000b004fe2f085d5csm532447lfe.299.2023.07.30.12.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jul 2023 12:26:13 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Adhemerval Zanella Subject: [PATCH v4 2/6] support: Add support_fcntl_support_ofd_locks () Date: Sun, 30 Jul 2023 22:25:57 +0300 Message-ID: <20230730192605.2423480-3-bugaevc@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230730192605.2423480-1-bugaevc@gmail.com> References: <20230730192605.2423480-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Reviewed-by: Adhemerval Zanella Signed-off-by: Sergey Bugaev --- support/Makefile | 1 + support/support.h | 3 ++ support/support_fcntl_support_ofd_locks.c | 44 +++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 support/support_fcntl_support_ofd_locks.c diff --git a/support/Makefile b/support/Makefile index 917a858b..ab5d46b8 100644 --- a/support/Makefile +++ b/support/Makefile @@ -58,6 +58,7 @@ libsupport-routines = \ support_descriptors \ support_enter_mount_namespace \ support_enter_network_namespace \ + support_fcntl_support_ofd_locks \ support_format_address_family \ support_format_addrinfo \ support_format_dns_packet \ diff --git a/support/support.h b/support/support.h index b7f76bf0..e20d2ce7 100644 --- a/support/support.h +++ b/support/support.h @@ -178,6 +178,9 @@ static __inline bool support_itimer_support_time64 (void) #endif } +/* Return true if the kernel/file supports open file description locks. */ +extern bool support_fcntl_support_ofd_locks (int fd); + /* Return true if stat supports nanoseconds resolution. PATH is used for tests and its ctime may change. */ extern bool support_stat_nanoseconds (const char *path); diff --git a/support/support_fcntl_support_ofd_locks.c b/support/support_fcntl_support_ofd_locks.c new file mode 100644 index 00000000..fb197a70 --- /dev/null +++ b/support/support_fcntl_support_ofd_locks.c @@ -0,0 +1,44 @@ +/* Return whether the kernel/file supports OFD locks. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +bool +support_fcntl_support_ofd_locks (int fd) +{ +#ifdef F_OFD_GETLK + int res; + struct flock flock; + memset (&flock, 0, sizeof (flock)); + + flock.l_type = F_WRLCK; + flock.l_whence = SEEK_SET; + flock.l_start = 0; + flock.l_len = INT32_MAX; + flock.l_pid = 0; + + res = fcntl (fd, F_OFD_GETLK, &flock); + return res != -1 || errno != EINVAL; +#else + (void) fd; + return false; +#endif +}