From: Masatake YAMATO Date: Mon, 19 Jan 2026 20:22:20 +0000 (+0900) Subject: lsfd: (refactor) remove redundant is_error member from struct file X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5558469bcf546765a1b769b1547cd71e662021c7;p=thirdparty%2Futil-linux.git lsfd: (refactor) remove redundant is_error member from struct file It is possible to detect whether a file object is an error object or not from its class information. Signed-off-by: Masatake YAMATO --- diff --git a/lsfd-cmd/file.c b/lsfd-cmd/file.c index a28be3f37..54c06382a 100644 --- a/lsfd-cmd/file.c +++ b/lsfd-cmd/file.c @@ -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 */ diff --git a/lsfd-cmd/lsfd.c b/lsfd-cmd/lsfd.c index bf631ee9b..0776ecfbc 100644 --- a/lsfd-cmd/lsfd.c +++ b/lsfd-cmd/lsfd.c @@ -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, '/'))) { diff --git a/lsfd-cmd/lsfd.h b/lsfd-cmd/lsfd.h index daebb9d56..a98bcbe3e 100644 --- a/lsfd-cmd/lsfd.h +++ b/lsfd-cmd/lsfd.h @@ -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 */