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, T_SCC_BODY_TEXT_LINE 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 699F61F405 for ; Wed, 31 Jan 2024 20:55:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1706734504; bh=CnZ1Q9ME6aKjamPk9fxfKcStJH7/A5FGhNWUczPzPUM=; h=From:To:Subject:Date:From; b=K7xB0rrLkftLwWrX4uh7lA/EPCiDyht9lZoNqAI1jC6qXr8gFSGcvvCI4QS0/rxr3 dJwhUr8MTJZaYm1vwmgaZZ3FLL5SMBH5s8cIaYj//FWRIrGsg8NmQQdNsj6JMRNx74 YoKW235Wuz/ZgdwtbSlV2DdzCxyhtpe2JfqzvAHs= From: Eric Wong To: spew@80x24.org Subject: [PATCH] pop3d: support fcntl locks on OpenBSD i386 Date: Wed, 31 Jan 2024 20:55:04 +0000 Message-ID: <20240131205504.1293108-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: The packaged Perl on OpenBSD i386 supports 64-bit file offsets but not 64-bit integer support for 'q' and 'Q' with `pack'. Since servers aren't likely to require lock files larger than 2 GB (we'd need an inbox with >2 billion messages), we can workaround the Perl build limitation with explicit padding. AFAIK File::FcntlLock isn't packaged for OpenBSD, but I can test i386 OpenBSD on an extremely slow VM. Big endian support can be done, too, but I have no idea if there's 32-bit BE users around nowadays... --- MANIFEST | 1 + lib/PublicInbox/POP3D.pm | 28 +++++++++++++++++++++------- t/pop3d_lock.t | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 t/pop3d_lock.t diff --git a/MANIFEST b/MANIFEST index 2223cfb4..4c974338 100644 --- a/MANIFEST +++ b/MANIFEST @@ -575,6 +575,7 @@ t/plack-qp.eml t/plack.t t/pop3d-limit.t t/pop3d.t +t/pop3d_lock.t t/precheck.t t/psgi_attach.eml t/psgi_attach.t diff --git a/lib/PublicInbox/POP3D.pm b/lib/PublicInbox/POP3D.pm index 38e982ee..9c868cfb 100644 --- a/lib/PublicInbox/POP3D.pm +++ b/lib/PublicInbox/POP3D.pm @@ -18,18 +18,32 @@ my ($FLOCK_TMPL, @FLOCK_ORDER); if ($^O =~ /\A(?:linux|dragonfly)\z/ || $^O =~ /bsd/) { require Config; my $off_t; + my @LE_pad = ('', ''); my $sz = $Config::Config{lseeksize}; - - if ($sz == 8 && eval('length(pack("q", 1)) == 8')) { $off_t = 'q' } - elsif ($sz == 4) { $off_t = 'l' } - else { warn "sizeof(off_t)=$sz requires File::FcntlLock\n" } - + if ($sz == 8) { + if (eval('length(pack("q", 1)) == 8')) { + $off_t = 'q'; + } elsif ($Config::Config{byteorder} == 1234) { # OpenBSD i386 + $off_t = 'l'; + @LE_pad = ('@8', '@16'); + } else { # I have no 32-bit BE machine to test on... + warn < +# License: AGPL-3.0+ +use v5.12; +use PublicInbox::TestCommon; +require_mods(qw(DBD::SQLite Net::POP3 :fcntl_lock)); +use autodie; +my $tmpdir = tmpdir; +require_ok 'PublicInbox::POP3D'; +my $pop3d = bless {}, 'PublicInbox::POP3D'; +open $pop3d->{txn_fh}, '+>>', "$tmpdir/txn.lock"; +use Fcntl qw(F_SETLK F_UNLCK F_WRLCK); + +ok $pop3d->_setlk(l_type => F_WRLCK, l_start => 9, l_len => 1), + 'locked file (check with ktrace/strace)'; + +done_testing;