From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id 2CDDB3858CDA for ; Sun, 28 May 2023 17:20:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2CDDB3858CDA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-4f4f3ac389eso1279223e87.1 for ; Sun, 28 May 2023 10:20:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685294416; x=1687886416; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=4RGFA+w0npmx+Fg5s+zvUvyimrcgN/gn6b+lkYgU2Ik=; b=FIfLFqJgSrMio3UIApKUVRkcrslYu/dCEHvRbHi6wdYoD+RNwWB/7HbV7gdzoj0nLW JbX2iA4tJCkhjip42fRW394/F8FKqjWhLbultmFpylDXRLKSgbhR0XyYkgMNwaSK9LVR 5/afrbXSb3JUkii5QVYB+hTBqOix/9+MykEyhwVjAqPunaCU9T2MoZyobA7tsXR+I/pQ kAsD84pK3Mvl0S9zrZEVDtufw7jwABT0lWPer05HW0Yakz08mYQGj8s+V2+YYNIU/hbX Gb+FMUKrWhvFp0DTKYah/P+jKknETrCpO0H4WcQ9lXNvLM0CGgmfensWHsh2bgvQ7nF1 3rUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685294416; x=1687886416; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4RGFA+w0npmx+Fg5s+zvUvyimrcgN/gn6b+lkYgU2Ik=; b=Fggss7D5AFHIMIrrZ49lB4WnPORlb4hv7svtPzG7jaUI2X/5FmRwBa/8oa/ZYf55qn nUS9G6s1xDy5EsnOJeX1obWCxszqg+ndwcAeb9sKRpjEvJgey7LvTRngE87UXicu5uJd I1R2aonSu2GBEpoHe0ayhXTQQdu9d4S8qUHPd/VyOKoGzt9PKWN/PDS3sEFRaXoCTckL 3CuIMUfyBPG3yZNrSTYjUH3QGfIKLwB8s5+YWhxB1nhZyK8DKYgZeI8JzafTAcR4jmdK aqfBmaUK2e6Hgg0qlZapQL0UKU6yvgTMjIwaPe6PhxL2Gc6JSP3NYO7ShiCMDqndcpp5 49SQ== X-Gm-Message-State: AC+VfDxWY+XV5p7ePohr7RG6HvCjgIfEBt8m0SSRLz1RJHjZyTbLtAcn R+rTWRwByV4md7rrY1KUpA98BPG6/xs= X-Google-Smtp-Source: ACHHUZ6cc7cSKFt4v7WVBVCpbf/9994kZRVJpd5IUc08pwbptNPW7at+crfDnKAzFdFjc2oWZZJ4XA== X-Received: by 2002:ac2:4465:0:b0:4f2:53f6:d4bf with SMTP id y5-20020ac24465000000b004f253f6d4bfmr2715866lfl.48.1685294416195; Sun, 28 May 2023 10:20:16 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:5e3d:a067:bc18:2967]) by smtp.gmail.com with ESMTPSA id v26-20020a19741a000000b004f4d5003e8dsm1662596lfe.7.2023.05.28.10.20.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 May 2023 10:20:15 -0700 (PDT) From: Sergey Bugaev To: libc-alpha@sourceware.org Subject: [PATCH v2 1/3] support: Add support_fcntl_support_ofd_locks () Date: Sun, 28 May 2023 20:20:11 +0300 Message-Id: <20230528172013.73111-2-bugaevc@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528172013.73111-1-bugaevc@gmail.com> References: <20230528172013.73111-1-bugaevc@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.5 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 List-Id: Signed-off-by: Sergey Bugaev --- support_xxx_support_yyy () seems to be the naming pattern for this kind of functions? 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 92f1a246..e9a00b2d 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 +} -- 2.40.1