user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 7/7] spawn: do not block ABRT/BUS/ILL/SEGV signals
  2023-09-11  9:41  6% [PATCH 0/7] system-related updates and cleanups Eric Wong
@ 2023-09-11  9:41  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2023-09-11  9:41 UTC (permalink / raw)
  To: meta

SIGABRT, SIGBUS, SIGILL, and SIGSEGV may all happen if we
introduce bugs in the section where signals are blocked.

We can delay handling of SIGFPE, SIGXCPU and SIGXFSZ since
there's no floating point operations; while SIGXCPU and
SIGXFSZ are safe to delay, especially in the absence of
threads in our current code paths.
---
 lib/PublicInbox/Spawn.pm   | 11 ++++++++---
 lib/PublicInbox/SpawnPP.pm |  4 ++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm
index 17d87f57..ed698afc 100644
--- a/lib/PublicInbox/Spawn.pm
+++ b/lib/PublicInbox/Spawn.pm
@@ -92,18 +92,23 @@ int pi_fork_exec(SV *redirref, SV *file, SV *cmdref, SV *envref, SV *rlimref,
 	sigset_t set, old;
 	int ret, perrnum;
 	volatile int cerrnum = 0; /* shared due to vfork */
-	int chld_is_member;
+	int chld_is_member; /* needed due to shared memory w/ vfork */
 	I32 max_fd = av_len(redir);
 
 	AV2C_COPY(argv, cmd);
 	AV2C_COPY(envp, env);
 
 	if (sigfillset(&set)) return -1;
+	if (sigdelset(&set, SIGABRT)) return -1;
+	if (sigdelset(&set, SIGBUS)) return -1;
+	if (sigdelset(&set, SIGFPE)) return -1;
+	if (sigdelset(&set, SIGILL)) return -1;
+	if (sigdelset(&set, SIGSEGV)) return -1;
+	/* no XCPU/XFSZ here */
 	if (sigprocmask(SIG_SETMASK, &set, &old)) return -1;
 	chld_is_member = sigismember(&old, SIGCHLD);
 	if (chld_is_member < 0) return -1;
-	if (chld_is_member > 0)
-		sigdelset(&old, SIGCHLD);
+	if (chld_is_member > 0 && sigdelset(&old, SIGCHLD)) return -1;
 
 	pid = vfork();
 	if (pid == 0) {
diff --git a/lib/PublicInbox/SpawnPP.pm b/lib/PublicInbox/SpawnPP.pm
index d6c863f8..e7174d6f 100644
--- a/lib/PublicInbox/SpawnPP.pm
+++ b/lib/PublicInbox/SpawnPP.pm
@@ -15,6 +15,10 @@ sub pi_fork_exec ($$$$$$$) {
 	my $old = POSIX::SigSet->new();
 	my $set = POSIX::SigSet->new();
 	$set->fillset or die "sigfillset: $!";
+	for (POSIX::SIGABRT, POSIX::SIGBUS, POSIX::SIGFPE,
+			POSIX::SIGILL, POSIX::SIGSEGV) {
+		$set->delset($_) or die "delset($_): $!";
+	}
 	sigprocmask(SIG_SETMASK, $set, $old) or die "SIG_SETMASK(set): $!";
 	my $syserr;
 	pipe(my ($r, $w)) or die "pipe: $!";

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/7] system-related updates and cleanups
@ 2023-09-11  9:41  6% Eric Wong
  2023-09-11  9:41  7% ` [PATCH 7/7] spawn: do not block ABRT/BUS/ILL/SEGV signals Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2023-09-11  9:41 UTC (permalink / raw)
  To: meta

2/7 is a very welcome cleanup... I'm liking the `awaitpid' API
quite a bit :>  I noticed the bug fixed by 1/7 while working
on 2/7.

3/7 is a welcome cleanup, though 4/7 is debatable...
IMHO epoll is total overkill for processes which will never
see many FDs and can't benefit from EPOLLEXCLUSIVE.

5/7 helps me sleep better at night since I'm uncomfortable
with using undocumented APIs

And a couple of further signal blocking cleanups.

Eric Wong (7):
  tests: map CLOFORK->FD_CLOEXEC temporarily for `tail -f'
  daemon: depend on DS event_loop in master process, too
  ds: use object-oriented API for epoll
  favor poll(2) for most daemons
  dspoll: switch to the documented IO::Poll API
  ds: use constants for @UNBLOCKABLE list
  spawn: do not block ABRT/BUS/ILL/SEGV signals

 MANIFEST                      |   1 +
 lib/PublicInbox/DS.pm         |  60 ++++----
 lib/PublicInbox/DSKQXS.pm     |  58 ++++----
 lib/PublicInbox/DSPoll.pm     |  64 ++++-----
 lib/PublicInbox/Daemon.pm     | 254 ++++++++++++++++------------------
 lib/PublicInbox/Epoll.pm      |  23 +++
 lib/PublicInbox/Sigfd.pm      |  12 +-
 lib/PublicInbox/Spawn.pm      |  11 +-
 lib/PublicInbox/SpawnPP.pm    |   4 +
 lib/PublicInbox/Syscall.pm    |  12 +-
 lib/PublicInbox/TestCommon.pm |  43 +++++-
 t/ds-kqxs.t                   |   4 +-
 t/ds-poll.t                   |  29 ++--
 t/epoll.t                     |  23 ++-
 t/httpd-unix.t                |  21 ++-
 t/lei-daemon.t                |   1 +
 t/sigfd.t                     |   4 +-
 t/watch_maildir.t             |   1 +
 t/xap_helper.t                |   7 +-
 19 files changed, 323 insertions(+), 309 deletions(-)
 create mode 100644 lib/PublicInbox/Epoll.pm


^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-09-11  9:41  6% [PATCH 0/7] system-related updates and cleanups Eric Wong
2023-09-11  9:41  7% ` [PATCH 7/7] spawn: do not block ABRT/BUS/ILL/SEGV signals Eric Wong

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).