]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: fill POS and MODE columns for SHM and MEM associated files
authorMasatake YAMATO <yamato@redhat.com>
Thu, 6 May 2021 13:26:48 +0000 (22:26 +0900)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Oct 2021 09:01:53 +0000 (11:01 +0200)
/proc/$pid/maps files are used as the data sourecs.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-file.c
misc-utils/lsfd.c
misc-utils/lsfd.h

index 16f6ab9145d8b3544c6e63c82cd8bb2c7d9bdddf..c79b7a5e19ae8a1346fba6c72d1be169e30a690e 100644 (file)
@@ -164,6 +164,11 @@ static void file_fill_flags_buf(struct ul_buffer *buf, int flags)
 
 }
 
+#define does_file_has_fdinfo_alike(file)       \
+       ((file)->association >= 0               \
+        || (file)->association == -ASSOC_SHM   \
+        || (file)->association == -ASSOC_MEM)
+
 static bool file_fill_column(struct proc *proc,
                             struct file *file,
                             struct libscols_line *ln,
@@ -246,16 +251,19 @@ static bool file_fill_column(struct proc *proc,
                xasprintf(&str, "%d", file->association < 0? 0: file->mnt_id);
                break;
        case COL_MODE:
-               if (file->association < 0)
-                       xasprintf(&str, "---");
-               else
-                       xasprintf(&str, "%c%c-",
+               if (does_file_has_fdinfo_alike(file))
+                       xasprintf(&str, "%c%c%c",
                                  file->mode & S_IRUSR? 'r': '-',
-                                 file->mode & S_IWUSR? 'w': '-');
+                                 file->mode & S_IWUSR? 'w': '-',
+                                 ((file->association == -ASSOC_SHM
+                                  || file->association == -ASSOC_MEM)
+                                  && file->mode & S_IXUSR)? 'x': '-');
+               else
+                       xasprintf(&str, "---");
                break;
        case COL_POS:
                xasprintf(&str, "%llu",
-                         file->association < 0? 0: file->pos);
+                         (does_file_has_fdinfo_alike(file))? file->pos: 0);
                break;
        case COL_FLAGS: {
                struct ul_buffer buf = UL_INIT_BUFFER;
index 0a76066143c37ba91841c77a25a189872bead65e..42528a20892eacbda21e6b7ea6f6c6fbbfad5ca5 100644 (file)
@@ -460,6 +460,12 @@ static struct file *collect_mem_file(int dd, struct dirent *dp,
        f = collect_file(&sb, sym, -assoc);
        if (!f)
                return NULL;
+
+       if (map) {
+               f->mode = (map->read? S_IRUSR: 0) | (map->write? S_IWUSR: 0) | (map->exec? S_IXUSR: 0);
+               f->pos = map->file_offset;
+       }
+
        return f;
 }
 
index d6a35f660c1c4b32715084296b8c4bb5d13f4576..c7a81df960092470fca7694bbb6e43769de16d25 100644 (file)
@@ -116,8 +116,8 @@ struct file {
        struct stat stat;
        mode_t mode;
        unsigned long long pos;
-       int flags;
-       int mnt_id;
+       int flags;              /* in fdinfo */
+       int mnt_id;             /* in fdinfo */
 };
 
 struct file_class {