From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] pop3d: support fcntl locks on NetBSD and OpenBSD
Date: Fri, 8 Sep 2023 23:37:39 +0000 [thread overview]
Message-ID: <20230908233739.2291909-1-e@80x24.org> (raw)
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 <signal.h>
+#include <stddef.h>
#include <sys/syscall.h>
#include <sys/ioctl.h>
#ifdef __linux__
#include <linux/fs.h>
#endif
#include <sys/types.h>
+#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
+#include <string.h>
+
+#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();
reply other threads:[~2023-09-08 23:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230908233739.2291909-1-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).