]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: fill UID field
authorMasatake YAMATO <yamato@redhat.com>
Thu, 25 Mar 2021 17:56:28 +0000 (02:56 +0900)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Oct 2021 09:01:53 +0000 (11:01 +0200)
misc-utils/lsfd-file.c
misc-utils/lsfd.c
misc-utils/lsfd.h

index 8efd1b000765b8e696ee53fc04e82c5176a07104..f3c4a95ccf3d740aff71e9ed28a87e765b23024d 100644 (file)
@@ -81,6 +81,13 @@ static bool file_fill_column(struct proc *proc,
                if (scols_line_refer_data(ln, column_index, str))
                        err(EXIT_FAILURE, _("failed to add output data"));
                return true;
+       case COL_UID:
+               xasprintf(&str, "%d", (int)file->stat.st_uid);
+               if (!str)
+                       err(EXIT_FAILURE, _("failed to add output data"));
+               if (scols_line_refer_data(ln, column_index, str))
+                       err(EXIT_FAILURE, _("failed to add output data"));
+               return true;
        };
 
        return false;
index 0a2f46668577c5c3a9cd8b3e8730c1f19255534c..9b42d151a6e5feb8c5332262fe66c3c3e76fbc94 100644 (file)
@@ -69,11 +69,15 @@ struct colinfo {
 
 /* columns descriptions */
 static struct colinfo infos[] = {
-       [COL_PID]     = { "PID",      7, SCOLS_FL_RIGHT, N_("PID of the process opening the file") },
-       [COL_FD]      = { "FD",       5, SCOLS_FL_RIGHT, N_("file descriptor for the file") },
-       [COL_NAME]    = { "NAME",    30, 0,              N_("name of the file") },
-       [COL_COMMAND] = { "COMMAND", 10, 0,              N_("command of the process opening the file") },
-       [COL_TYPE]    = { "TYPE",     7, 0,              N_("file type") },
+       [COL_PID]     = { "PID",      0, SCOLS_FL_RIGHT, N_("PID of the process opening the file") },
+       [COL_FD]      = { "FD",       0, SCOLS_FL_RIGHT, N_("file descriptor for the file") },
+       [COL_NAME]    = { "NAME",     0, 0,              N_("name of the file") },
+       [COL_COMMAND] = { "COMMAND",  0, 0,              N_("command of the process opening the file") },
+       [COL_TYPE]    = { "TYPE",     0, SCOLS_FL_RIGHT, N_("file type") },
+       [COL_UID]     = { "UID",      0, SCOLS_FL_RIGHT, N_("user ID number") },
+       /* DEVICE */
+       /* SIZE/OFF */
+       /* NODE */
 };
 
 static int columns[ARRAY_SIZE(infos) * 2] = {-1};
@@ -459,6 +463,7 @@ int main(int argc, char *argv[])
        if (!ncolumns) {
                columns[ncolumns++] = COL_COMMAND;
                columns[ncolumns++] = COL_PID;
+               columns[ncolumns++] = COL_UID; /* This should be COL_USER. */
                columns[ncolumns++] = COL_FD;
                columns[ncolumns++] = COL_TYPE;
                columns[ncolumns++] = COL_NAME;
@@ -494,10 +499,12 @@ int main(int argc, char *argv[])
                        switch (id) {
                        case COL_NAME:
                        case COL_COMMAND:
+                       case COL_TYPE:
                                scols_column_set_json_type(cl, SCOLS_JSON_STRING);
                                break;
                        case COL_PID:
                        case COL_FD:
+                       case COL_UID:
                                /* fallthrough */
                        default:
                                scols_column_set_json_type(cl, SCOLS_JSON_NUMBER);
index 18485186fad0081037f71493fe7a4ac3d5da2ff1..0d9c2939c91730ee802e233542a29c9c9d097808 100644 (file)
@@ -55,6 +55,7 @@ enum {
        COL_NAME,
        COL_COMMAND,
        COL_TYPE,
+       COL_UID,
 };
 
 /*