From: Masatake YAMATO Date: Thu, 25 Mar 2021 17:56:28 +0000 (+0900) Subject: lsfd: fill UID field X-Git-Tag: v2.38-rc1~144^2~179 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0472946175f845060d2170b3288dde29dbe61c66;p=thirdparty%2Futil-linux.git lsfd: fill UID field --- diff --git a/misc-utils/lsfd-file.c b/misc-utils/lsfd-file.c index 8efd1b0007..f3c4a95ccf 100644 --- a/misc-utils/lsfd-file.c +++ b/misc-utils/lsfd-file.c @@ -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; diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index 0a2f466685..9b42d151a6 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -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); diff --git a/misc-utils/lsfd.h b/misc-utils/lsfd.h index 18485186fa..0d9c2939c9 100644 --- a/misc-utils/lsfd.h +++ b/misc-utils/lsfd.h @@ -55,6 +55,7 @@ enum { COL_NAME, COL_COMMAND, COL_TYPE, + COL_UID, }; /*