]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: cleanup fdinfo handling
authorKarel Zak <kzak@redhat.com>
Mon, 20 Sep 2021 11:16:06 +0000 (13:16 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Oct 2021 09:01:54 +0000 (11:01 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsfd-file.c
misc-utils/lsfd.c
misc-utils/lsfd.h

index 8165b3ada21c4473caa2fafdb1ca10bad20d0167..dab7edca119241066e54d4e8f80777ace03c3821 100644 (file)
@@ -28,6 +28,7 @@
 #include "nls.h"
 #include "buffer.h"
 #include "idcache.h"
+#include "strutils.h"
 
 #include "libsmartcols.h"
 
@@ -305,7 +306,7 @@ static bool file_fill_column(struct proc *proc,
                        xasprintf(&str, "---");
                break;
        case COL_POS:
-               xasprintf(&str, "%llu",
+               xasprintf(&str, "%" PRIu64,
                          (does_file_has_fdinfo_alike(file))? file->pos: 0);
                break;
        case COL_FLAGS: {
@@ -343,13 +344,14 @@ static bool file_fill_column(struct proc *proc,
 static int file_handle_fdinfo(struct file *file, const char *key, const char* value)
 {
        if (strcmp(key, "pos") == 0) {
-               file->pos = strtoull(value, NULL, 10);
+               ul_strtou64(value, &file->pos, 10);
                return 1;
        } else if (strcmp(key, "flags") == 0) {
-               file->sys_flags = (int)strtol(value, NULL, 8);
+               ul_strtou32(value, &file->sys_flags, 8);
+
                return 1;
        } else if (strcmp(key, "mnt_id") == 0) {
-               file->mnt_id = (int)strtol(value, NULL, 10);
+               ul_strtou32(value, &file->mnt_id, 10);
                return 1;
        }
        return 0;
index 7de7ee73d3798a67429626099dc21f76f62cf23b..9e9fc0940adc0c7716599719bd3a3424a581696b 100644 (file)
@@ -316,17 +316,18 @@ static void free_proc(struct proc *proc)
 
 static void read_fdinfo(struct file *file, FILE *fdinfo)
 {
-       const struct file_class *class;
        char buf[1024];
-       char *val;
 
        while (fgets(buf, sizeof(buf), fdinfo)) {
-               val = strchr(buf, ':');
+               const struct file_class *class;
+               char *val = strchr(buf, ':');
+
                if (!val)
                        continue;
-               *val++ = '\0';
-               while (*val == '\t' || *val == ' ')
-                       val++;
+               *val++ = '\0';  /* terminate key */
+
+               val = (char *) skip_space(val);
+               rtrim_whitespace((unsigned char *) val);
 
                class = file->class;
                while (class) {
index f03f12d5b29ae3e0033f9c24c53c72fbcfcc47d7..31783d71f78942be7bb61ae84634c52100004d83 100644 (file)
@@ -111,13 +111,13 @@ struct file {
        struct stat stat;
        mode_t mode;
        struct proc *proc;
-       unsigned long long pos;
+       uint64_t pos;
 
        unsigned long map_start;
        unsigned long map_end;
 
-       int sys_flags;
-       int mnt_id;
+       unsigned int sys_flags;
+       unsigned int mnt_id;
 };
 
 #define is_association(_f, a)  ((_f)->association < 0 && (_f)->association == -ASSOC_ ## a)