From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id C157F3858D32 for ; Mon, 29 May 2023 13:18:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C157F3858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-39855d57240so2035810b6e.2 for ; Mon, 29 May 2023 06:18:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685366329; x=1687958329; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=vqCM5eveGqE0/Z3vCHuJ8Xjn+1ODzM/21777Mi8dA8s=; b=OAob2K8sVZyA7AMz5lqYnW6Dil6HwXYPo1zLiqo4AuuyvP1AzH7xco8+4s5QPdijQV eNLUfnKlHVslQhLNRJuR+6Zm+/xEPmtTFeJncAN+t51o8heubnZMN7DbfX+COBhVqb4r ksM3nz+FvuqQhmBL1FcMtznab/0quEhCJaVMhNVycEDsLb7Jbr+Mo6YSrSXPofSz+sIi tuboMmFSIq9HqCphU78XfCt7FBKhtlJ8ACSJ4B/DDdneDGD/iZ//Ctajv3QF/Wh/snGG COGKgrztzkLFgjFZa5os/zeElgPr23LfWKHIUlil3q08SUG813OFhrCJVRgmyUO1sCBT fOHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685366329; x=1687958329; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vqCM5eveGqE0/Z3vCHuJ8Xjn+1ODzM/21777Mi8dA8s=; b=UGJcqJP3sVqInlsm1mrFh5jSbFF1mrN6HvDBHW/JmmSAuS4QKpYhsLpX1tEF2A74MV R8JNiKBp3tAz8g7pAYPHWG/XhM1e+RcdxrJtydv5yv+9PMuGw53exMXEHgJVXOAnpG/n ZvQNrAfQNk/dZ9B4ubnli245Lwol+puUX9BlxGJ1rESQ000TrcEabw4iBzGt5WsSBC9g No3RLuTREkb1iRKIpCokoFCrFyHGjdhF6vd/Qo8IfOGNWEksHrgeHChe1qTU2CJB84t6 M2nA5kIvy9X7cCilH8xLftvJOh1Weoba/e9iP87l93KSrEI9TWnTOB/mlk3jlQnZ9s6R nJCw== X-Gm-Message-State: AC+VfDyouEkUh2MIeIVYzlySPmrj1MDrpF3EH+CTMRuML8M0wQL0tx7g aE6D+rnuqW/M/ZZ7mBmBt7ZBjgjdfr5AF/ATUlXUUA== X-Google-Smtp-Source: ACHHUZ6av52Ivp1jfCMZhMS2klFIsygTf9OMOuaQTNsdBo6MZlBB6VB1+AA3n20ZNehTcbbXG8NrCw== X-Received: by 2002:a05:6808:2a77:b0:397:ec35:f5a6 with SMTP id fu23-20020a0568082a7700b00397ec35f5a6mr4464976oib.57.1685366328930; Mon, 29 May 2023 06:18:48 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c1:4dd5:7120:a40d:fc97:d6db? ([2804:1b3:a7c1:4dd5:7120:a40d:fc97:d6db]) by smtp.gmail.com with ESMTPSA id n203-20020acaefd4000000b00399dff24197sm3600707oih.5.2023.05.29.06.18.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 May 2023 06:18:48 -0700 (PDT) Message-ID: <045eafc6-f523-566c-3f8e-af779eea8572@linaro.org> Date: Mon, 29 May 2023 10:18:44 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.1 Subject: Re: [PATCH v2 1/3] support: Add support_fcntl_support_ofd_locks () Content-Language: en-US To: libc-alpha@sourceware.org, Sergey Bugaev References: <20230528172013.73111-1-bugaevc@gmail.com> <20230528172013.73111-2-bugaevc@gmail.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20230528172013.73111-2-bugaevc@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,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: On 28/05/23 14:20, Sergey Bugaev via Libc-alpha wrote: > Signed-off-by: Sergey Bugaev LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > > support_xxx_support_yyy () seems to be the naming pattern for this > kind of functions? That's the pattern I use to follow. > > 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; I think returning an unexpected error here as supported should be ok here. > +#else > + (void) fd; > + return false; > +#endif > +}