From: Masatake YAMATO Date: Sun, 12 Nov 2023 15:30:32 +0000 (+0900) Subject: lslocks: (refactor) lift up the code destroying the lock list for future extension X-Git-Tag: v2.40-rc1~163^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=53ce6e704d6c4e32182bfd035d5ab8e6b2b744ac;p=thirdparty%2Futil-linux.git lslocks: (refactor) lift up the code destroying the lock list for future extension Signed-off-by: Masatake YAMATO --- 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; }