]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: make username_cache lsfd-file privaite
authorMasatake YAMATO <yamato@redhat.com>
Thu, 6 May 2021 15:00:05 +0000 (00:00 +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 c79b7a5e19ae8a1346fba6c72d1be169e30a690e..2bc0ee51575444c54733b25d8c90e997a90ef440 100644 (file)
 #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,
index dea7b323069df133c494ded859fdeba641f4ebac..8dce55274ab79bd52435bdd4e8c2229680e1abd7 100644 (file)
@@ -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;
index 754df17126274b82f61405fde778c5bc9a8fe037..02929be3497950a22a1bfd029ae40c53ba6632b0 100644 (file)
@@ -28,7 +28,6 @@
 #include <sys/stat.h>
 #include <dirent.h>
 
-#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 */