]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commit
xfs_scrub_all: fix termination signal handling
authorDarrick J. Wong <djwong@kernel.org>
Fri, 12 Jan 2024 02:07:07 +0000 (18:07 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 12 Jan 2024 02:08:47 +0000 (18:08 -0800)
commit1c95c17c8857223d05e8c4516af42c6d41ae579a
tree093d875659829af9e5eb80629941d2d20bc5756b
parent0c22427fe07e22e25991742f7948945a039272fc
xfs_scrub_all: fix termination signal handling

Currently, xfs_scrub_all does not handle termination signals well.
SIGTERM and SIGINT are left to their default handlers, which are
immediate termination of the process group in the case of SIGTERM and
raising KeyboardInterrupt in the case of SIGINT.

Terminating the process group is fine when the xfs_scrub processes are
direct children, but this completely doesn't work if we're farming the
work out to systemd services since we don't terminate the child service.
Instead, they keep going.

Raising KeyboardInterrupt doesn't work because once the main thread
calls sys.exit at the bottom of main(), it blocks in the python runtime
waiting for child threads to terminate.  There's no longer any context
to handle an exception, so the signal is ignored and no child processes
are killed.

In other words, if you try to kill a running xfs_scrub_all, chances are
good it won't kill the child xfs_scrub processes.  This is undesirable
and egregious since we actually have the ability to track and kill all
the subprocesses that we create.

Solve the subproblem of getting stuck in the python runtime by calling
it repeatedly until we no longer have subprocesses.  This means that the
main thread loops until all threads have exited.

Solve the subproblem of the signals doing the wrong thing by setting up
our own signal handler that can wake up the main thread and initiate
subprocess shutdown, no matter whether the subprocesses are systemd
services or directly fork/exec'd.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
scrub/xfs_scrub_all.in