static int columns[ARRAY_SIZE(infos) * 2];
static size_t ncolumns;
-static struct libmnt_table *tab; /* /proc/self/mountinfo */
-
struct lock {
struct list_head locks;
int bytes;
pid_t target_pid;
+
+ struct libmnt_table *tab; /* /proc/self/mountinfo */
};
static int lock_tnode_compare(const void *a, const void *b)
/*
* Associate the device's mountpoint for a filename
*/
-static char *get_fallback_filename(dev_t dev)
+static char *get_fallback_filename(struct libmnt_table *tab, dev_t dev)
{
struct libmnt_fs *fs;
char *res = NULL;
- if (!tab) {
- tab = mnt_new_table_from_file(_PATH_PROC_MOUNTINFO);
- if (!tab)
- return NULL;
- }
-
fs = mnt_table_find_devno(tab, dev, MNT_ITER_BACKWARD);
if (!fs)
return NULL;
return l;
}
-static struct lock *refine_lock(struct lock *lock, int no_inaccessible)
+static struct lock *refine_lock(struct lock *lock,
+ int no_inaccessible, struct libmnt_table *tab)
{
/* no permissions -- ignore */
if (!lock->path && no_inaccessible) {
if (!lock->path) {
/* probably no permission to peek into l->pid's path */
- lock->path = get_fallback_filename(lock->dev);
+ lock->path = tab
+ ? get_fallback_filename(tab, lock->dev)
+ : NULL;
lock->size = 0;
}
continue;
l = get_lock(buf + 6, &oinfo, NULL);
if (l)
- l = refine_lock(l, lslocks->no_inaccessible);
+ l = refine_lock(l, lslocks->no_inaccessible,
+ lslocks->tab);
if (l) {
add_to_tree(locks, l);
l->fd = fd;
while (fgets(buf, sizeof(buf), fp)) {
struct lock *l = get_lock(buf, NULL, fallback);
if (l)
- l = refine_lock(l, lslocks->no_inaccessible);
+ l = refine_lock(l, lslocks->no_inaccessible,
+ lslocks->tab);
if (l)
add_to_list(locks, l);
}
static void lslocks_init(struct lslocks *lslocks)
{
- memset(lslocks, 0, sizeof(*lslocks));
+ memset(lslocks, 0, sizeof(*lslocks));
}
static void lslocks_free(struct lslocks *lslocks __attribute__((__unused__)))
* of /proc/$pid/fdinfo/$fd as fallback information.
* get_proc_locks() used the fallback information if /proc/locks
* doesn't provide enough information or provides stale information. */
+ lslocks.tab = mnt_new_table_from_file(_PATH_PROC_MOUNTINFO);
get_pids_locks(&lslocks, &pid_locks);
rc = get_proc_locks(&lslocks, &proc_locks, &pid_locks);
+ mnt_unref_table(lslocks.tab);
if (!rc && !list_empty(&proc_locks))
rc = show_locks(&lslocks, table, &proc_locks, &pid_locks);
rem_locks(&proc_locks);
scols_unref_table(table);
- mnt_unref_table(tab);
lslocks_free(&lslocks);
return rc;
}