]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lslocks: (refactor) lift up the code destroying the lock list for future extension
authorMasatake YAMATO <yamato@redhat.com>
Sun, 12 Nov 2023 15:30:32 +0000 (00:30 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Sun, 12 Nov 2023 18:04:21 +0000 (03:04 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lslocks.c

index 38cc9d9d1acfdb6cc079a36382b14ddaa5ef3dda..d60cb013e2c7871401619a4f7f3a8eee7a7b5512 100644 (file)
@@ -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;
 }