]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: (refactor) remove redundant is_error member from struct file
authorMasatake YAMATO <yamato@redhat.com>
Mon, 19 Jan 2026 20:22:20 +0000 (05:22 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Mon, 19 Jan 2026 20:56:08 +0000 (05:56 +0900)
It is possible to detect whether a file object is an error object
or not from its class information.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
lsfd-cmd/file.c
lsfd-cmd/lsfd.c
lsfd-cmd/lsfd.h

index a28be3f373e7fb00a0cf09a967cb78583e3f2a3b..54c06382a56bdb82fb68354ef684b586610a6935 100644 (file)
@@ -298,11 +298,6 @@ static const struct file_class error_class = {
        .fill_column = error_fill_column,
 };
 
-static void init_error_content(struct file *file)
-{
-       file->is_error = 1;
-}
-
 static bool readlink_error_fill_column(struct proc *proc __attribute__((__unused__)),
                                       struct file *file __attribute__((__unused__)),
                                       struct libscols_line *ln __attribute__((__unused__)),
@@ -321,16 +316,30 @@ static bool readlink_error_fill_column(struct proc *proc __attribute__((__unused
 const struct file_class readlink_error_class = {
        .super = &error_class,
        .size = sizeof(struct file),
-       .initialize_content = init_error_content,
        .fill_column = readlink_error_fill_column,
 };
 
 const struct file_class stat_error_class = {
        .super = &error_class,
        .size = sizeof(struct file),
-       .initialize_content = init_error_content,
 };
 
+bool is_error_object(struct file *f)
+{
+       const struct file_class *c;
+
+       assert(f);
+       c = f->class;
+
+       while (c) {
+               if (c == &error_class)
+                       return true;
+               c = c->super;
+       }
+
+       return false;
+}
+
 /*
  * Concrete file class
  */
index bf631ee9b2ad20c70c897eec9e1a06567ad31656..0776ecfbc4d3797010a89daf7f1e9816c727c721 100644 (file)
@@ -895,7 +895,7 @@ static struct file *collect_file_symlink(struct path_cxt *pc,
         * path is the same to save stat() call.
         */
        else if ((prev = list_last_entry(&proc->files, struct file, files))
-                && (!prev->is_error)
+                && (!is_error_object(prev))
                 && prev->name && strcmp(prev->name, sym) == 0) {
                f = copy_file(prev, assoc);
                sb = prev->stat;
@@ -917,7 +917,7 @@ static struct file *collect_file_symlink(struct path_cxt *pc,
 
        file_init_content(f);
 
-       if (f->is_error)
+       if (is_error_object(f))
                return f;
 
        if (is_association(f, NS_MNT)) {
@@ -1007,7 +1007,7 @@ static void parse_maps_line(struct path_cxt *pc, char *buf, struct proc *proc)
         */
        prev = list_last_entry(&proc->files, struct file, files);
 
-       if (prev && (!prev->is_error)
+       if (prev && (!is_error_object(prev))
            && prev->stat.st_dev == devno && prev->stat.st_ino == ino)
                f = copy_file(prev, -assoc);
        else if ((path = strchr(buf, '/'))) {
index daebb9d5626fa99eb426167283f0696b54c37d31..a98bcbe3ebe006cb5bb781c59b6f9359ac57e54b 100644 (file)
@@ -219,8 +219,7 @@ struct file {
 
        bool    locked_read,
                locked_write,
-               multiplexed,
-               is_error;
+               multiplexed;
 };
 
 #define is_opened_file(_f) ((_f)->association >= 0)
@@ -250,6 +249,8 @@ extern const struct file_class abst_class, readlink_error_class, stat_error_clas
        file_class, cdev_class, bdev_class, sock_class, unkn_class, fifo_class,
        nsfs_file_class, mqueue_file_class, pidfs_file_class;
 
+bool is_error_object(struct file *f);
+
 /*
  * IPC
  */