From: Masatake YAMATO Date: Thu, 6 May 2021 13:26:48 +0000 (+0900) Subject: lsfd: fill POS and MODE columns for SHM and MEM associated files X-Git-Tag: v2.38-rc1~144^2~149 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5701c643386055c9aecb8442f2e5f2ea6ca30951;p=thirdparty%2Futil-linux.git lsfd: fill POS and MODE columns for SHM and MEM associated files /proc/$pid/maps files are used as the data sourecs. Signed-off-by: Masatake YAMATO --- diff --git a/misc-utils/lsfd-file.c b/misc-utils/lsfd-file.c index 16f6ab9145..c79b7a5e19 100644 --- a/misc-utils/lsfd-file.c +++ b/misc-utils/lsfd-file.c @@ -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; diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index 0a76066143..42528a2089 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -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; } diff --git a/misc-utils/lsfd.h b/misc-utils/lsfd.h index d6a35f660c..c7a81df960 100644 --- a/misc-utils/lsfd.h +++ b/misc-utils/lsfd.h @@ -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 {