[PATCH 3/4] xfs_scrub_all: simplify cleanup of run_killable

Darrick J. Wong
2023-12-31T22:55:28Z

Get rid of the nested lambda functions to simplify the code.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
scrub/xfs_scrub_all.in | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/scrub/xfs_scrub_all.in b/scrub/xfs_scrub_all.in
index ab9b491fb4e..2c20b91fdbe 100644
--- a/scrub/xfs_scrub_all.in
+++ b/scrub/xfs_scrub_all.in
@@ -72,14 +72,14 @@ def remove_killfunc(killfuncs, fn):
except:
pass

-def run_killable(cmd, stdout, killfuncs, kill_fn):
- '''Run a killable program. Returns program retcode or -1 if we can't start it.'''
+def run_killable(cmd, stdout, killfuncs):
+ '''Run a killable program. Returns program retcode or -1 if we can't
+ start it.'''
try:
proc = subprocess.Popen(cmd, stdout = stdout)
- real_kill_fn = lambda: kill_fn(proc)
- killfuncs.add(real_kill_fn)
+ killfuncs.add(proc.terminate)
proc.wait()
- remove_killfunc(killfuncs, real_kill_fn)
+ remove_killfunc(killfuncs, proc.terminate)
return proc.returncode
except:
return -1
@@ -178,8 +178,7 @@ def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs):
cmd = ['@sbindir@/xfs_scrub']
cmd += '@scrub_args@'.split()
cmd += [mnt]
- ret = run_killable(cmd, None, killfuncs, \
- lambda proc: proc.terminate())
+ ret = run_killable(cmd, None, killfuncs)
if ret >= 0:
print("Scrubbing %s done, (err=%d)" % (mnt, ret))
sys.stdout.flush()