From 53ce6e704d6c4e32182bfd035d5ab8e6b2b744ac Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Mon, 13 Nov 2023 00:30:32 +0900 Subject: [PATCH] lslocks: (refactor) lift up the code destroying the lock list for future extension Signed-off-by: Masatake YAMATO --- misc-utils/lslocks.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/misc-utils/lslocks.c b/misc-utils/lslocks.c index 38cc9d9d1a..d60cb013e2 100644 --- a/misc-utils/lslocks.c +++ b/misc-utils/lslocks.c @@ -468,11 +468,22 @@ static void add_scols_line(struct libscols_table *table, struct lock *l, struct } } +static void rem_locks(struct list_head *locks) +{ + struct list_head *p, *pnext; + + /* destroy the list */ + list_for_each_safe(p, pnext, locks) { + struct lock *l = list_entry(p, struct lock, locks); + rem_lock(l); + } +} + static int show_locks(struct list_head *locks, pid_t target_pid) { int rc = 0; size_t i; - struct list_head *p, *pnext; + struct list_head *p; struct libscols_table *table; table = scols_new_table(); @@ -530,12 +541,6 @@ static int show_locks(struct list_head *locks, pid_t target_pid) add_scols_line(table, l, locks); } - /* destroy the list */ - list_for_each_safe(p, pnext, locks) { - struct lock *l = list_entry(p, struct lock, locks); - rem_lock(l); - } - scols_print_table(table); scols_unref_table(table); return rc; @@ -684,6 +689,8 @@ int main(int argc, char *argv[]) if (!rc && !list_empty(&proc_locks)) rc = show_locks(&proc_locks, target_pid); + rem_locks(&proc_locks); + mnt_unref_table(tab); return rc; } -- 2.47.3