diff options
author | Karel Zak | 2013-02-14 16:29:51 +0100 |
---|---|---|
committer | Karel Zak | 2013-02-14 16:29:51 +0100 |
commit | 55c0d16bab8cc84b72bf11cb2fdd8aa6205ac608 (patch) | |
tree | 716da88bdd49bce9b07501f29504235b9b72a022 /misc-utils/lslocks.c | |
parent | lslocks: use libmount to parse mountinfo (diff) | |
download | kernel-qcow2-util-linux-55c0d16bab8cc84b72bf11cb2fdd8aa6205ac608.tar.gz kernel-qcow2-util-linux-55c0d16bab8cc84b72bf11cb2fdd8aa6205ac608.tar.xz kernel-qcow2-util-linux-55c0d16bab8cc84b72bf11cb2fdd8aa6205ac608.zip |
lslocks: detect blocked locks, fix /proc/locks parser
$ flock foo -c "sleep 100" & flock foo -c "sleep 100"
old version:
$ lslocks
lslocks: failed to parse pid: 'WRITE'
new version:
COMMAND PID TYPE SIZE MODE M START END PATH
[...]
flock 1318 FLOCK 0B WRITE* 0 0 0 /home/projects/
flock 1319 FLOCK 0B WRITE 0 0 0 /home/projects/
The asterisk (e.g. WRITE*) is used for blocked processes.
Reported-by: Mantas Mikulenas <grawity@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/lslocks.c')
-rw-r--r-- | misc-utils/lslocks.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/misc-utils/lslocks.c b/misc-utils/lslocks.c index e837b014e..fb40dcb73 100644 --- a/misc-utils/lslocks.c +++ b/misc-utils/lslocks.c @@ -93,7 +93,8 @@ struct lock { char *mode; off_t start; off_t end; - int mandatory; + unsigned int mandatory :1, + blocked :1; char *size; }; @@ -250,11 +251,15 @@ static int get_local_locks(struct list_head *locks) case 0: /* ignore */ break; case 1: /* posix, flock, etc */ - l->type = xstrdup(tok); + if (strcmp(tok, "->") == 0) { /* optional field */ + l->blocked = 1; + i--; + } else + l->type = xstrdup(tok); break; case 2: /* is this a mandatory lock? other values are advisory or noinode */ - l->mandatory = *tok == 'M' ? TRUE : FALSE; + l->mandatory = *tok == 'M' ? 1 : 0; break; case 3: /* lock mode */ l->mode = xstrdup(tok); @@ -406,10 +411,10 @@ static void add_tt_line(struct tt *tt, struct lock *l) xasprintf(&str, "%s", l->size); break; case COL_MODE: - xasprintf(&str, "%s", l->mode); + xasprintf(&str, "%s%s", l->mode, l->blocked ? "*" : ""); break; case COL_M: - xasprintf(&str, "%d", l->mandatory); + xasprintf(&str, "%d", l->mandatory ? 1 : 0); break; case COL_START: xasprintf(&str, "%jd", l->start); |