From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A6BF11F55F for ; Fri, 8 Sep 2023 23:37:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1694216259; bh=L+jiRS6A06JYpe6lXQEsCqdOEsWKEj1ICTDqxPxSnaM=; h=From:To:Subject:Date:From; b=myysxByYm4qnslWad3P3YpV0TmkflBBkWmAnrfJgiQBHSNMEHaYONeXSHwP736h/A keay42ZuBEH8fN6A6WwRKyQqAqgWbQL3blSkJfiyptnGg/8QyFJYL84GxtOCbxWoC8 NHnL03Ymq5yJwHyaveH6YmdQ8Jw/4H+RkTmW7qbo= From: Eric Wong To: spew@80x24.org Subject: [PATCH] pop3d: support fcntl locks on NetBSD and OpenBSD Date: Fri, 8 Sep 2023 23:37:39 +0000 Message-ID: <20230908233739.2291909-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: MboxLock already supported it since it locked the whole file, but POP3D requires more fine-grained locking at file offsets. I wonder if "struct flock" is old enough for it to be the same across all the BSDs... --- devel/sysdefs-list | 23 +++++++++++++++++++++++ lib/PublicInbox/POP3D.pm | 3 ++- t/pop3d.t | 3 ++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/devel/sysdefs-list b/devel/sysdefs-list index 9764cc29..0356cbc1 100755 --- a/devel/sysdefs-list +++ b/devel/sysdefs-list @@ -33,14 +33,29 @@ __DATA__ # define _GNU_SOURCE #endif #include +#include #include #include #ifdef __linux__ #include #endif #include +#include #include #include +#include + +#define STRUCT_BEGIN(t) do { t x; printf("\n"#t" => %zu bytes\n", sizeof(x)) +#define STRUCT_END } while (0) + +// prints the struct field name, @offset, and signed/unsigned bit size +#define PR_NUM(f) do { \ + memset(&x.f, 0xff, sizeof(x.f)); \ + printf("\t.%s @%zu %s%zu""\n", #f, \ + offsetof(typeof(x),f), \ + x.f > 0 ? "u" : "s", \ + sizeof(x.f) * 8); \ +} while (0) #define D(x) printf("$" #x " = %ld;\n", (long)x) @@ -70,5 +85,13 @@ int main(void) D(SIGWINCH); MAYBE _SC_NPROCESSORS_ONLN + STRUCT_BEGIN(struct flock); + PR_NUM(l_start); + PR_NUM(l_len); + PR_NUM(l_pid); + PR_NUM(l_type); + PR_NUM(l_whence); + STRUCT_END; + return 0; } diff --git a/lib/PublicInbox/POP3D.pm b/lib/PublicInbox/POP3D.pm index 3fc85efc..580a26d3 100644 --- a/lib/PublicInbox/POP3D.pm +++ b/lib/PublicInbox/POP3D.pm @@ -14,6 +14,7 @@ use PublicInbox::Syscall; use File::Temp 0.19 (); # 0.19 for ->newdir use Fcntl qw(F_SETLK F_UNLCK F_WRLCK SEEK_SET); my @FLOCK; +# are all BSDs the same "struct flock"? tested Free+Net+Open... if ($^O eq 'linux' || $^O =~ /bsd/) { require Config; my $off_t; @@ -27,7 +28,7 @@ if ($^O eq 'linux' || $^O =~ /bsd/) { if ($^O eq 'linux') { @FLOCK = ("ss\@8$off_t$off_t\@32", qw(l_type l_whence l_start l_len)); - } elsif ($^O =~ /bsd/) { + } elsif ($^O =~ /bsd/) { # @32 may be enough @FLOCK = ("${off_t}${off_t}lss\@256", qw(l_start l_len l_pid l_type l_whence)); } diff --git a/t/pop3d.t b/t/pop3d.t index dc52b0cf..95875105 100644 --- a/t/pop3d.t +++ b/t/pop3d.t @@ -14,7 +14,8 @@ unless (-r $key && -r $cert) { # Net::POP3 is part of the standard library, but distros may split it off... require_mods(qw(DBD::SQLite Net::POP3 IO::Socket::SSL)); require_git('2.6'); # for v2 -require_mods(qw(File::FcntlLock)) if $^O !~ /\A(?:linux|freebsd)\z/; +$^O =~ /\A(?:linux|(?:free|net|open)bsd)\z/ or + require_mods(qw(File::FcntlLock)); use_ok 'IO::Socket::SSL'; use_ok 'PublicInbox::TLS'; my ($tmpdir, $for_destroy) = tmpdir();