]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: initialize pagesize in an earlier stage
authorMasatake YAMATO <yamato@redhat.com>
Tue, 21 Mar 2023 16:03:22 +0000 (01:03 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Tue, 23 May 2023 16:02:08 +0000 (01:02 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-file.c

index daf9cb3c5fda33da0812d7be67570afc8867d70e..99cff5992c4aa4bb511314d19d64543d4a46d7c1 100644 (file)
@@ -45,6 +45,8 @@
 
 static struct idcache *username_cache;
 
+static size_t pagesize;
+
 static const char *assocstr[N_ASSOCS] = {
        [ASSOC_CWD]       = "cwd",
        [ASSOC_EXE]       = "exe",
@@ -102,14 +104,8 @@ static uint64_t get_map_length(struct file *file)
 {
        uint64_t res = 0;
 
-       if (is_association(file, SHM) || is_association(file, MEM)) {
-               static size_t pagesize = 0;
-
-               if (!pagesize)
-                       pagesize = getpagesize();
-
+       if (is_association(file, SHM) || is_association(file, MEM))
                res = (file->map_end - file->map_start) / pagesize;
-       }
 
        return res;
 }
@@ -306,6 +302,9 @@ static void file_free_content(struct file *file)
 
 static void file_class_initialize(void)
 {
+       if (!pagesize)
+               pagesize = getpagesize();
+
        username_cache = new_idcache();
        if (!username_cache)
                err(EXIT_FAILURE, _("failed to allocate UID cache"));