From: Masatake YAMATO Date: Thu, 6 May 2021 15:00:05 +0000 (+0900) Subject: lsfd: make username_cache lsfd-file privaite X-Git-Tag: v2.38-rc1~144^2~146 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=602dbcd9a801a63ad15d00d62b4a53fe5e479b69;p=thirdparty%2Futil-linux.git lsfd: make username_cache lsfd-file privaite Signed-off-by: Masatake YAMATO --- diff --git a/misc-utils/lsfd-file.c b/misc-utils/lsfd-file.c index c79b7a5e19..2bc0ee5157 100644 --- a/misc-utils/lsfd-file.c +++ b/misc-utils/lsfd-file.c @@ -25,11 +25,14 @@ #include "xalloc.h" #include "nls.h" #include "buffer.h" +#include "idcache.h" #include "libsmartcols.h" #include "lsfd.h" +static struct idcache *username_cache; + static const char *assocstr[N_ASSOCS] = { [ASSOC_CWD] = "cwd", [ASSOC_EXE] = "exe", @@ -326,9 +329,23 @@ struct file *make_file(const struct file_class *class, return file; } +static void file_class_initialize(void) +{ + username_cache = new_idcache(); + if (!username_cache) + err(EXIT_FAILURE, _("failed to allocate UID cache")); +} + +static void file_class_finalize(void) +{ + free_idcache(username_cache); +} + const struct file_class file_class = { .super = NULL, .size = sizeof(struct file), + .initialize_class = file_class_initialize, + .finalize_class = file_class_finalize, .fill_column = file_fill_column, .handle_fdinfo = file_handle_fdinfo, .free_content = file_free_content, diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index dea7b32306..8dce55274a 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -74,11 +74,6 @@ struct map { unsigned int read:1, write:1, exec:1, shared:1; }; -/* - * idcaches - */ -struct idcache *username_cache; - /* * Column related stuffs */ @@ -966,10 +961,6 @@ int main(int argc, char *argv[]) &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(); @@ -1003,8 +994,6 @@ int main(int argc, char *argv[]) emit(&ctl); delete(&procs, &ctl); - free_idcache(username_cache); - finalize_classes(); return 0; diff --git a/misc-utils/lsfd.h b/misc-utils/lsfd.h index 754df17126..02929be349 100644 --- a/misc-utils/lsfd.h +++ b/misc-utils/lsfd.h @@ -28,7 +28,6 @@ #include #include -#include "idcache.h" #include "list.h" /* @@ -147,6 +146,4 @@ struct file *make_sock(const struct file_class *class, struct file *make_unkn(const struct file_class *class, struct stat *sb, const char *name, int fd); -extern struct idcache *username_cache; - #endif /* UTIL_LINUX_LSFD_H */