.SH OPTIONS
.TP
+.BR \-i , " \-\-noinaccessible"
+Ignore lock files which are inaccessible for the current user.
+.TP
.BR \-J , " \-\-json"
Use JSON output format.
.TP
.IP "END"
Ending offset of the lock.
.IP "PATH"
-Full path of the lock. If none is found, or there are no permissions to read the path,
-it will fall back to the device's mountpoint. The path might be truncated; use
+Full path of the lock. If none is found, or there are no permissions to read
+the path, it will fall back to the device's mountpoint and "..." is appended to
+the path. The path might be truncated; use
\fB\-\-notruncate\fR to get the full path.
.IP "BLOCKER"
The PID of the process which blocks the lock.
/* basic output flags */
static int no_headings;
+static int no_inaccessible;
static int raw;
static int json;
int id;
};
+static void rem_lock(struct lock *lock)
+{
+ if (!lock)
+ return;
+
+ free(lock->path);
+ free(lock->size);
+ free(lock->mode);
+ free(lock->cmdname);
+ free(lock->type);
+ list_del(&lock->locks);
+ free(lock);
+}
+
static void disable_columns_truncate(void)
{
size_t i;
static char *get_fallback_filename(dev_t dev)
{
struct libmnt_fs *fs;
+ char *res = NULL;
if (!tab) {
tab = mnt_new_table_from_file(_PATH_PROC_MOUNTINFO);
if (!fs)
return NULL;
- return xstrdup(mnt_fs_get_target(fs));
+ xasprintf(&res, "%s...", mnt_fs_get_target(fs));
+ return res;
}
/*
int i;
ino_t inode = 0;
FILE *fp;
- char buf[PATH_MAX], *szstr = NULL, *tok = NULL;
+ char buf[PATH_MAX], *tok = NULL;
size_t sz;
struct lock *l;
dev_t dev = 0;
default:
break;
}
+ }
- l->path = get_filename_sz(inode, l->pid, &sz);
- if (!l->path)
- /* probably no permission to peek into l->pid's path */
- l->path = get_fallback_filename(dev);
+ l->path = get_filename_sz(inode, l->pid, &sz);
- /* avoid leaking */
- szstr = size_to_human_string(SIZE_SUFFIX_1LETTER, sz);
- l->size = xstrdup(szstr);
- free(szstr);
+ /* no permissions -- ignore */
+ if (!l->path && no_inaccessible) {
+ rem_lock(l);
+ continue;
}
+ if (!l->path) {
+ /* probably no permission to peek into l->pid's path */
+ l->path = get_fallback_filename(dev);
+ l->size = xstrdup("");
+ } else
+ /* avoid leaking */
+ l->size = size_to_human_string(SIZE_SUFFIX_1LETTER, sz);
+
list_add(&l->locks, locks);
}
return &infos[ get_column_id(num) ];
}
-static void rem_lock(struct lock *lock)
-{
- if (!lock)
- return;
-
- free(lock->path);
- free(lock->size);
- free(lock->mode);
- free(lock->cmdname);
- free(lock->type);
- list_del(&lock->locks);
- free(lock);
-}
-
static pid_t get_blocker(int id, struct list_head *locks)
{
struct list_head *p;
fputs(USAGE_OPTIONS, out);
fputs(_(" -J, --json use JSON output format\n"), out);
+ fputs(_(" -i, --noinaccessible ignore locks without read permissions\n"), out);
fputs(_(" -n, --noheadings don't print headings\n"), out);
fputs(_(" -o, --output <list> define which output columns to use\n"), out);
fputs(_(" -p, --pid <pid> display only locks held by this process\n"), out);
{ "version", no_argument, NULL, 'V' },
{ "noheadings", no_argument, NULL, 'n' },
{ "raw", no_argument, NULL, 'r' },
+ { "noinaccessible", no_argument, NULL, 'i' },
{ NULL, 0, NULL, 0 }
};
atexit(close_stdout);
while ((c = getopt_long(argc, argv,
- "Jp:o:nruhV", long_opts, NULL)) != -1) {
+ "iJp:o:nruhV", long_opts, NULL)) != -1) {
err_exclusive_options(c, long_opts, excl, excl_st);
switch(c) {
+ case 'i':
+ no_inaccessible = 1;
+ break;
case 'J':
json = 1;
break;