if (scols_line_set_data(ln, column_index, strftype(ftype)))
err(EXIT_FAILURE, _("failed to add output data"));
return true;
+ case COL_USER:
+ add_uid(username_cache, (int)file->stat.st_uid);
+ if (scols_line_set_data(ln, column_index,
+ get_id(username_cache,
+ (int)file->stat.st_uid)->name))
+ err(EXIT_FAILURE, _("failed to add output data"));
+ return true;
case COL_PID:
xasprintf(&str, "%d", (int)proc->pid);
break;
#include "strutils.h"
#include "procutils.h"
#include "fileutils.h"
+#include "idcache.h"
#include "libsmartcols.h"
static void *fill_procs(void *arg);
+/*
+ * idcaches
+ */
+struct idcache *username_cache;
+
/*
* Column related stuffs
*/
[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_USER] = { "USER", 0, SCOLS_FL_RIGHT, N_("user of the process") },
[COL_UID] = { "UID", 0, SCOLS_FL_RIGHT, N_("user ID number") },
/* DEVICE */
/* SIZE/OFF */
if (!ncolumns) {
columns[ncolumns++] = COL_COMMAND;
columns[ncolumns++] = COL_PID;
- columns[ncolumns++] = COL_UID; /* This should be COL_USER. */
+ columns[ncolumns++] = COL_USER;
columns[ncolumns++] = COL_FD;
columns[ncolumns++] = COL_TYPE;
columns[ncolumns++] = COL_NAME;
&ncolumns, column_name_to_id) < 0)
return EXIT_FAILURE;
+ username_cache = new_idcache();
+ if (!username_cache)
+ err(EXIT_FAILURE, _("failed to allocate UID cache"));
+
scols_init_debug(0);
ctl.tb = scols_new_table();
case COL_NAME:
case COL_COMMAND:
case COL_TYPE:
+ case COL_USER:
scols_column_set_json_type(cl, SCOLS_JSON_STRING);
break;
case COL_PID:
emit(&ctl);
delete(&procs, &ctl);
+ free_idcache(username_cache);
+
return 0;
}
#include <sys/stat.h>
#include <dirent.h>
+#include "idcache.h"
#include "list.h"
/*
COL_COMMAND,
COL_TYPE,
COL_UID,
+ COL_USER,
};
/*
struct file *make_regular_fd_file(const struct file_class *class,
struct stat *sb, const char *name, int fd);
+extern struct idcache *username_cache;
+
#endif /* UTIL_LINUX_LSFD_H */