* [PATCH] xap_helper: detect non-socket STDIN
@ 2023-09-14 21:22 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2023-09-14 21:22 UTC (permalink / raw)
To: meta
We don't want to get into a worker respawn loop if somebody
just decides to start the executable from a terminal.
---
lib/PublicInbox/XapHelper.pm | 4 ++++
lib/PublicInbox/xap_helper.h | 6 ++++++
2 files changed, 10 insertions(+)
diff --git a/lib/PublicInbox/XapHelper.pm b/lib/PublicInbox/XapHelper.pm
index 0e79e5e2..e8eeb2dc 100644
--- a/lib/PublicInbox/XapHelper.pm
+++ b/lib/PublicInbox/XapHelper.pm
@@ -10,6 +10,7 @@ $GLP->configure(qw(require_order bundling no_ignore_case no_auto_abbrev));
use PublicInbox::Search qw(xap_terms);
use PublicInbox::CodeSearch;
use PublicInbox::IPC;
+use Socket qw(SOL_SOCKET SO_TYPE SOCK_SEQPACKET AF_UNIX);
use PublicInbox::DS qw(awaitpid);
use POSIX qw(:signal_h);
use Fcntl qw(LOCK_UN LOCK_EX);
@@ -254,6 +255,9 @@ sub xh_alive { $alive || scalar(keys %WORKERS) }
sub start (@) {
my (@argv) = @_;
+ my $c = getsockopt(STDIN, SOL_SOCKET, SO_TYPE) or die "getsockopt: $!";
+ unpack('i', $c) == SOCK_SEQPACKET or die 'stdin is not SOCK_SEQPACKET';
+
local (%SRCH, %WORKERS);
local $alive = 1;
PublicInbox::Search::load_xapian();
diff --git a/lib/PublicInbox/xap_helper.h b/lib/PublicInbox/xap_helper.h
index a2fea266..2322d062 100644
--- a/lib/PublicInbox/xap_helper.h
+++ b/lib/PublicInbox/xap_helper.h
@@ -1108,6 +1108,12 @@ static size_t living_workers(void)
int main(int argc, char *argv[])
{
int c;
+ socklen_t slen = (socklen_t)sizeof(c);
+
+ if (getsockopt(sock_fd, SOL_SOCKET, SO_TYPE, &c, &slen))
+ err(EXIT_FAILURE, "getsockopt");
+ if (c != SOCK_SEQPACKET)
+ errx(EXIT_FAILURE, "stdin is not SOCK_SEQPACKET");
mail_nrp_init();
code_nrp_init();
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-09-14 21:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-14 21:22 [PATCH] xap_helper: detect non-socket STDIN Eric Wong
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).