pid_t target_pid;
+ struct list_head proc_locks;
void *pid_locks;
struct libmnt_table *tab; /* /proc/self/mountinfo */
};
return;
}
-static int get_proc_locks(struct lslocks *lslocks, struct list_head *locks)
+static int get_proc_locks(struct lslocks *lslocks)
{
FILE *fp;
char buf[PATH_MAX];
l = refine_lock(l, lslocks->no_inaccessible,
lslocks->tab);
if (l)
- add_to_list(locks, l);
+ add_to_list(&lslocks->proc_locks, l);
}
fclose(fp);
}
static void add_scols_line(struct lslocks *lslocks,
- struct libscols_table *table, struct lock *l, struct list_head *locks)
+ struct libscols_table *table, struct lock *l)
{
struct libscols_line *line;
/*
case COL_BLOCKER:
{
pid_t bl = l->blocked && l->id ?
- get_blocker(l->id, locks) : 0;
+ get_blocker(l->id, &lslocks->proc_locks) : 0;
if (bl)
xasprintf(&str, "%d", (int) bl);
break;
return table;
}
-static int show_locks(struct lslocks *lslocks,
- struct libscols_table *table, struct list_head *locks)
+static int show_locks(struct lslocks *lslocks, struct libscols_table *table)
{
struct list_head *p;
/* prepare data for output */
- list_for_each(p, locks) {
+ list_for_each(p, &lslocks->proc_locks) {
struct lock *l = list_entry(p, struct lock, locks);
if (lslocks->target_pid && lslocks->target_pid != l->pid)
continue;
- add_scols_line(lslocks, table, l, locks);
+ add_scols_line(lslocks, table, l);
}
scols_print_table(table);
static void lslocks_init(struct lslocks *lslocks)
{
memset(lslocks, 0, sizeof(*lslocks));
+
+ INIT_LIST_HEAD(&lslocks->proc_locks);
}
static void lslocks_free(struct lslocks *lslocks)
{
+ rem_locks(&lslocks->proc_locks);
tdestroy(lslocks->pid_locks, rem_tnode);
}
{
struct lslocks lslocks;
int c, rc = 0, collist = 0;
- struct list_head proc_locks;
struct libscols_table *table;
char *outarg = NULL;
enum {
if (collist)
list_columns(&lslocks); /* print end exit */
- INIT_LIST_HEAD(&proc_locks);
-
if (!ncolumns) {
/* default columns */
columns[ncolumns++] = COL_SRC;
* doesn't provide enough information or provides stale information. */
lslocks.tab = mnt_new_table_from_file(_PATH_PROC_MOUNTINFO);
get_pids_locks(&lslocks);
- rc = get_proc_locks(&lslocks, &proc_locks);
+ rc = get_proc_locks(&lslocks);
mnt_unref_table(lslocks.tab);
- if (!rc && !list_empty(&proc_locks))
- rc = show_locks(&lslocks, table, &proc_locks);
+ if (!rc && !list_empty(&lslocks.proc_locks))
+ rc = show_locks(&lslocks, table);
- rem_locks(&proc_locks);
scols_unref_table(table);
lslocks_free(&lslocks);