]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: print the owner of process as USER
authorMasatake YAMATO <yamato@redhat.com>
Tue, 4 May 2021 18:36:09 +0000 (03:36 +0900)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Oct 2021 09:01:53 +0000 (11:01 +0200)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-file.c
misc-utils/lsfd.c
misc-utils/lsfd.h

index e350dfd5c62e5d81edd6eb5627622e941a29acbe..8fbf8252519bb44b824fa4ad0a824aece53a062b 100644 (file)
@@ -96,10 +96,10 @@ static bool file_fill_column(struct proc *proc,
                        err(EXIT_FAILURE, _("failed to add output data"));
                return true;
        case COL_USER:
-               add_uid(username_cache, (int)file->stat.st_uid);
+               add_uid(username_cache, (int)proc->uid);
                if (scols_line_set_data(ln, column_index,
                                        get_id(username_cache,
-                                              (int)file->stat.st_uid)->name))
+                                              (int)proc->uid)->name))
                        err(EXIT_FAILURE, _("failed to add output data"));
                return true;
        case COL_FD:
@@ -134,7 +134,7 @@ static bool file_fill_column(struct proc *proc,
                xasprintf(&str, "%d", (int)proc->pid);
                break;
        case COL_UID:
-               xasprintf(&str, "%d", (int)file->stat.st_uid);
+               xasprintf(&str, "%d", (int)proc->uid);
                break;
        case COL_SIZE:
                xasprintf(&str, "%ju", file->stat.st_size);
index c9952d73e6565835d737a957b6f4f312f630a45e..f3c997bdc81fe40631df95210539390272254878 100644 (file)
@@ -369,6 +369,13 @@ static struct file *collect_outofbox_file(int dd, const char *name, int associat
        return collect_file(&sb, sym, association);
 }
 
+static void collect_proc_uid(struct proc *proc, int dd)
+{
+       struct stat sb;
+       if (fstat(dd, &sb) == 0)
+               proc->uid = sb.st_uid;
+}
+
 static void collect_outofbox_files(struct proc *proc,
                                   const char *proc_template,
                                   enum association assocs[],
@@ -388,6 +395,9 @@ static void collect_outofbox_files(struct proc *proc,
        for (unsigned int i = 0; i < count; i++) {
                struct file *file;
 
+               if (assocs[i] == ASSOC_EXE)
+                       collect_proc_uid(proc, dd);
+
                if ((file = collect_outofbox_file(dd,
                                                  assoc_names[assocs[i]],
                                                  assocs[i] * -1)) == NULL)
index 17c0a377396ec8e08e19bff1e2adb5a845177e52..9927ed0c672c1144d8cbf53caf833e55a480c404 100644 (file)
@@ -92,6 +92,7 @@ enum association {
 struct proc {
        pid_t pid;
        char *command;
+       uid_t uid;
        struct list_head procs;
        struct list_head files;
 };