From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] xap_helper: detect non-socket STDIN
Date: Thu, 14 Sep 2023 21:22:40 +0000 [thread overview]
Message-ID: <20230914212240.19307-1-e@80x24.org> (raw)
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();
reply other threads:[~2023-09-14 21:22 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
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230914212240.19307-1-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).