* [PATCH] lslocks: add personality column
@ 2012-03-02 13:00 Davidlohr Bueso
2012-03-02 13:09 ` Peter Breitenlohner
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Davidlohr Bueso @ 2012-03-02 13:00 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
From: Davidlohr Bueso <dave@gnu.org>
By knowing the lock's personality (flock or posix), the user can have more information
about the lock and how it was created.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
misc-utils/lslocks.8 | 5 +++++
misc-utils/lslocks.c | 30 ++++++++++++++++++++----------
2 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/misc-utils/lslocks.8 b/misc-utils/lslocks.8
index 3257d79..86aac47 100644
--- a/misc-utils/lslocks.8
+++ b/misc-utils/lslocks.8
@@ -37,6 +37,9 @@ The command name of the process holding the lock.
.IP "PID"
Process ID which holds the lock.
+.IP "PERSONALITY"
+Type of lock, can be FLOCK (created with flock(2)) or POSIX (created with fcntl(2) and lockf(2))
+
.IP "SIZE"
Size of the locked file.
@@ -71,6 +74,8 @@ Davidlohr Bueso <dave@gnu.org>
.SH "SEE ALSO"
.BR flock (1)
+.BR fcntl (2)
+.BR lockf (2)
.SH AVAILABILITY
The lslocks command is part of the util-linux package and is available from
diff --git a/misc-utils/lslocks.c b/misc-utils/lslocks.c
index 39ab18d..aed94c4 100644
--- a/misc-utils/lslocks.c
+++ b/misc-utils/lslocks.c
@@ -45,6 +45,7 @@
enum {
COL_SRC = 0,
COL_PID,
+ COL_PERSONALITY,
COL_SIZE,
COL_ACCESS,
COL_M,
@@ -63,14 +64,15 @@ struct colinfo {
/* columns descriptions */
static struct colinfo infos[] = {
- [COL_SRC] = { "COMMAND", 15, 0, N_("command of the process holding the lock") },
- [COL_PID] = { "PID", 5, TT_FL_RIGHT, N_("PID of the process holding the lock") },
- [COL_SIZE] = { "SIZE", 4, TT_FL_RIGHT, N_("size of the lock") },
- [COL_ACCESS] = { "ACCESS", 5, 0, N_("lock access type") },
- [COL_M] = { "M", 1, 0, N_("mandatory state of the lock: 0 (none), 1 (set)")},
- [COL_START] = { "START", 10, TT_FL_RIGHT, N_("relative byte offset of the lock")},
- [COL_END] = { "END", 10, TT_FL_RIGHT, N_("ending offset of the lock")},
- [COL_PATH] = { "PATH", 0, TT_FL_TRUNC, N_("path of the locked file")},
+ [COL_SRC] = { "COMMAND", 15, 0, N_("command of the process holding the lock") },
+ [COL_PID] = { "PID", 5, TT_FL_RIGHT, N_("PID of the process holding the lock") },
+ [COL_PERSONALITY] = { "PERSONALITY", 5, TT_FL_RIGHT, N_("kind of lock: FL_FLOCK or FL_POSIX.") },
+ [COL_SIZE] = { "SIZE", 4, TT_FL_RIGHT, N_("size of the lock") },
+ [COL_ACCESS] = { "ACCESS", 5, 0, N_("lock access type") },
+ [COL_M] = { "M", 1, 0, N_("mandatory state of the lock: 0 (none), 1 (set)")},
+ [COL_START] = { "START", 10, TT_FL_RIGHT, N_("relative byte offset of the lock")},
+ [COL_END] = { "END", 10, TT_FL_RIGHT, N_("ending offset of the lock")},
+ [COL_PATH] = { "PATH", 0, TT_FL_TRUNC, N_("path of the locked file")},
};
#define NCOLS ARRAY_SIZE(infos)
static int columns[NCOLS], ncolumns;
@@ -84,6 +86,7 @@ struct lock {
char *cmdname;
pid_t pid;
char *path;
+ char *personality;
char *type;
off_t start;
off_t end;
@@ -248,8 +251,9 @@ static int get_local_locks(struct list_head *locks)
* separated by ' ' - check <kernel>/fs/locks.c
*/
switch (i) {
- case 0:
- case 1: /* not intereted! */
+ case 0: /* not intereted! */
+ case 1: /* posix, flock, etc */
+ l->personality = xstrdup(tok);
break;
case 2: /* is this a mandatory lock? other values are advisory or noinode */
@@ -310,6 +314,7 @@ static int get_local_locks(struct list_head *locks)
free(l->size);
free(l->type);
free(l->cmdname);
+ free(l->personality);
free(l);
continue;
@@ -362,6 +367,7 @@ static void rem_lock(struct lock *lock)
free(lock->size);
free(lock->type);
free(lock->cmdname);
+ free(lock->personality);
list_del(&lock->locks);
free(lock);
}
@@ -397,6 +403,9 @@ static void add_tt_line(struct tt *tt, struct lock *l)
case COL_PID:
rc = asprintf(&str, "%d", l->pid);
break;
+ case COL_PERSONALITY:
+ rc = asprintf(&str, "%s", l->personality);
+ break;
case COL_SIZE:
rc = asprintf(&str, "%s", l->size);
break;
@@ -546,6 +555,7 @@ int main(int argc, char *argv[])
/* default columns */
columns[ncolumns++] = COL_SRC;
columns[ncolumns++] = COL_PID;
+ columns[ncolumns++] = COL_PERSONALITY;
columns[ncolumns++] = COL_SIZE;
columns[ncolumns++] = COL_ACCESS;
columns[ncolumns++] = COL_M;
--
1.7.8.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] lslocks: add personality column
2012-03-02 13:00 [PATCH] lslocks: add personality column Davidlohr Bueso
@ 2012-03-02 13:09 ` Peter Breitenlohner
2012-03-02 13:22 ` Voelker, Bernhard
2012-03-06 16:16 ` Karel Zak
2 siblings, 0 replies; 4+ messages in thread
From: Peter Breitenlohner @ 2012-03-02 13:09 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: Karel Zak, util-linux
On Fri, 2 Mar 2012, Davidlohr Bueso wrote:
> @@ -248,8 +251,9 @@ static int get_local_locks(struct list_head *locks)
> * separated by ' ' - check <kernel>/fs/locks.c
> */
> switch (i) {
> - case 0:
> - case 1: /* not intereted! */
> + case 0: /* not intereted! */
should this be 'intereted' or 'interpreted'?
Regards
Peter Breitenlohner <peb@mppmu.mpg.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] lslocks: add personality column
2012-03-02 13:00 [PATCH] lslocks: add personality column Davidlohr Bueso
2012-03-02 13:09 ` Peter Breitenlohner
@ 2012-03-02 13:22 ` Voelker, Bernhard
2012-03-06 16:16 ` Karel Zak
2 siblings, 0 replies; 4+ messages in thread
From: Voelker, Bernhard @ 2012-03-02 13:22 UTC (permalink / raw)
To: Davidlohr Bueso, Karel Zak; +Cc: util-linux
Davidlohr Bueso wrote:
> @@ -248,8 +251,9 @@ static int get_local_locks(struct list_head *locks)
> * separated by ' ' - check <kernel>/fs/locks.c
> */
> switch (i) {
> - case 0:
> - case 1: /* not intereted! */
> + case 0: /* not intereted! */
> + case 1: /* posix, flock, etc */
> + l->personality =3D xstrdup(tok);
> break;
Forgot a break for case 0?
btw: s/intereted/interested/
and a few lines above:
- * /proc/locks as *exactly* 8 "blocks" of text
+ * /proc/locks has *exactly* 8 "blocks" of text
Have a nice day,
Berny
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lslocks: add personality column
2012-03-02 13:00 [PATCH] lslocks: add personality column Davidlohr Bueso
2012-03-02 13:09 ` Peter Breitenlohner
2012-03-02 13:22 ` Voelker, Bernhard
@ 2012-03-06 16:16 ` Karel Zak
2 siblings, 0 replies; 4+ messages in thread
From: Karel Zak @ 2012-03-06 16:16 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: util-linux
On Fri, Mar 02, 2012 at 02:00:06PM +0100, Davidlohr Bueso wrote:
> From: Davidlohr Bueso <dave@gnu.org>
>
> By knowing the lock's personality (flock or posix), the user can have more information
> about the lock and how it was created.
>
> Signed-off-by: Davidlohr Bueso <dave@gnu.org>
> ---
> misc-utils/lslocks.8 | 5 +++++
> misc-utils/lslocks.c | 30 ++++++++++++++++++++----------
> 2 files changed, 25 insertions(+), 10 deletions(-)
Applied with some changes:
- rename ACCESS to MODE
- rename PERSONALITY to TYPE (the column name was too long)
- fix the typos and missing break
- rename struct lock members to match with column names
See below. Thanks!
Karel
$ lslocks
COMMAND PID TYPE SIZE MODE M START END PATH
libvirtd 1243 POSIX 0B WRITE 0 0 0 /run
(unknown) 1283 FLOCK 0B WRITE 0 0 0 /run
tracker-store 1974 POSIX 5.3M READ 0 1073741826 1073742335 /home/kz
tracker-store 1974 POSIX 32K READ 0 128 128 /home/kz
tracker-miner-f 1975 POSIX 5.3M READ 0 1073741826 1073742335 /home/kz
tracker-miner-f 1975 POSIX 32K READ 0 128 128 /home/kz
java 11500 POSIX 0B WRITE 0 0 9223372036854775806 /home/kz
firefox 8976 POSIX 0B WRITE 0 0 0 /home/kz
firefox 8976 POSIX 384K WRITE 0 1073741824 1073742335 /home/kz
firefox 8976 POSIX 1.5M READ 0 1073741826 1073742335 /home/kz
firefox 8976 POSIX 32K READ 0 128 128 /home/kz
firefox 8976 POSIX 416K WRITE 0 1073741824 1073742335 /home/kz
firefox 8976 POSIX 20M READ 0 1073741826 1073742335 /home/kz
firefox 8976 POSIX 32K READ 0 128 128 /home/kz
crond 17793 POSIX 0B WRITE 0 0 0 /run
atd 24371 POSIX 0B WRITE 0 0 0 /run
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-03-06 16:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-02 13:00 [PATCH] lslocks: add personality column Davidlohr Bueso
2012-03-02 13:09 ` Peter Breitenlohner
2012-03-02 13:22 ` Voelker, Bernhard
2012-03-06 16:16 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox