]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: simplify class hierarchy
authorMasatake YAMATO <yamato@redhat.com>
Thu, 6 May 2021 05:54:27 +0000 (14:54 +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/Makemodule.am
misc-utils/lsfd-bdev.c [moved from misc-utils/lsfd-bdev-file.c with 77% similarity]
misc-utils/lsfd-cdev.c [moved from misc-utils/lsfd-cdev-file.c with 77% similarity]
misc-utils/lsfd-regular-file.c [deleted file]
misc-utils/lsfd.c
misc-utils/lsfd.h

index 64be038a79d7a87fd11ad6436c241bf578765a91..7ed02a70672b4239e2d05c5fe547b98abc5e82ef 100644 (file)
@@ -253,9 +253,8 @@ lsfd_SOURCES = \
        misc-utils/lsfd.c \
        misc-utils/lsfd.h \
        misc-utils/lsfd-file.c \
-       misc-utils/lsfd-regular-file.c \
-       misc-utils/lsfd-cdev-file.c \
-       misc-utils/lsfd-bdev-file.c
+       misc-utils/lsfd-cdev.c \
+       misc-utils/lsfd-bdev.c
 lsfd_LDADD = $(LDADD) libsmartcols.la libcommon.la
 lsfd_LDFLAGS =  -pthread
 lsfd_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir) -pthread
similarity index 77%
rename from misc-utils/lsfd-bdev-file.c
rename to misc-utils/lsfd-bdev.c
index 0c4393df168bca397c36217877ea9dba79088e2e..ce900dd5e05b5463af091453123fcad9fd3ea899 100644 (file)
 
 #include "lsfd.h"
 
-static bool bdev_file_fill_column(struct proc *proc __attribute__((__unused__)),
-                                 struct file *file __attribute__((__unused__)),
-                                 struct libscols_line *ln,
-                                 int column_id,
-                                 size_t column_index)
+static bool bdev_fill_column(struct proc *proc __attribute__((__unused__)),
+                            struct file *file __attribute__((__unused__)),
+                            struct libscols_line *ln,
+                            int column_id,
+                            size_t column_index)
 {
        char *str = NULL;
        switch(column_id) {
@@ -53,16 +53,16 @@ static bool bdev_file_fill_column(struct proc *proc __attribute__((__unused__)),
        return true;
 }
 
-const struct file_class bdev_file_class = {
+const struct file_class bdev_class = {
        .super = &file_class,
        .size = sizeof(struct file),
-       .fill_column = bdev_file_fill_column,
+       .fill_column = bdev_fill_column,
        .free_content = NULL,
 };
 
-struct file *make_bdev_file(const struct file_class *class,
-                              struct stat *sb, const char *name, int fd)
+struct file *make_bdev(const struct file_class *class,
+                      struct stat *sb, const char *name, int fd)
 {
-       return make_file(class? class: &bdev_file_class,
+       return make_file(class? class: &bdev_class,
                         sb, name, fd);
 }
similarity index 77%
rename from misc-utils/lsfd-cdev-file.c
rename to misc-utils/lsfd-cdev.c
index 3bcf1bd911b65467f11d4b1dc2233d8156efdc46..98c83ca337d3d191be871c624ab398eb769f9b5f 100644 (file)
 
 #include "lsfd.h"
 
-static bool cdev_file_fill_column(struct proc *proc __attribute__((__unused__)),
-                                 struct file *file __attribute__((__unused__)),
-                                 struct libscols_line *ln,
-                                 int column_id,
-                                 size_t column_index)
+static bool cdev_fill_column(struct proc *proc __attribute__((__unused__)),
+                            struct file *file __attribute__((__unused__)),
+                            struct libscols_line *ln,
+                            int column_id,
+                            size_t column_index)
 {
        char *str = NULL;
        switch(column_id) {
@@ -53,16 +53,16 @@ static bool cdev_file_fill_column(struct proc *proc __attribute__((__unused__)),
        return true;
 }
 
-const struct file_class cdev_file_class = {
+const struct file_class cdev_class = {
        .super = &file_class,
        .size = sizeof(struct file),
-       .fill_column = cdev_file_fill_column,
+       .fill_column = cdev_fill_column,
        .free_content = NULL,
 };
 
-struct file *make_cdev_file(const struct file_class *class,
-                           struct stat *sb, const char *name, int fd)
+struct file *make_cdev(const struct file_class *class,
+                      struct stat *sb, const char *name, int fd)
 {
-       return make_file(class? class: &cdev_file_class,
+       return make_file(class? class: &cdev_class,
                         sb, name, fd);
 }
diff --git a/misc-utils/lsfd-regular-file.c b/misc-utils/lsfd-regular-file.c
deleted file mode 100644 (file)
index 0a7cd79..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * lsfd(1) - list file descriptors
- *
- * Copyright (C) 2021 Red Hat, Inc. All rights reserved.
- * Written by Masatake YAMATO <yamato@redhat.com>
- *
- * Very generally based on lsof(8) by Victor A. Abell <abe@purdue.edu>
- * It supports multiple OSes. lsfd specializes to Linux.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#include "xalloc.h"
-#include "nls.h"
-#include "libsmartcols.h"
-
-#include "lsfd.h"
-
-static bool regular_file_fill_column(struct proc *proc __attribute__((__unused__)),
-                                    struct file *file __attribute__((__unused__)),
-                                    struct libscols_line *ln,
-                                    int column_id,
-                                    size_t column_index)
-{
-       switch(column_id) {
-       case COL_TYPE:
-               if (scols_line_set_data(ln, column_index, "REG"))
-                       err(EXIT_FAILURE, _("failed to add output data"));
-               return true;
-       }
-
-       return false;
-}
-
-const struct file_class regular_file_class = {
-       .super = &file_class,
-       .size = sizeof(struct file),
-       .fill_column = regular_file_fill_column,
-       .free_content = NULL,
-};
-
-struct file *make_regular_file(const struct file_class *class,
-                              struct stat *sb, const char *name, int fd)
-{
-       return make_file(class? class: &regular_file_class,
-                        sb, name, fd);
-}
index 5c6e10cd6a8d87ad1f417fb1280f8fe2b9ee7de3..73fb7c49a93e761874d33cb47ba794722b7ee4e2 100644 (file)
@@ -328,12 +328,10 @@ static void collect(struct list_head *procs, struct lsfd_control *ctl)
 static struct file *collect_file(struct stat *sb, char *name, int assoc)
 {
        switch (sb->st_mode & S_IFMT) {
-       case S_IFREG:
-               return make_regular_file(NULL, sb, name, assoc);
        case S_IFCHR:
-               return make_cdev_file(NULL, sb, name, assoc);
+               return make_cdev(NULL, sb, name, assoc);
        case S_IFBLK:
-               return make_bdev_file(NULL, sb, name, assoc);
+               return make_bdev(NULL, sb, name, assoc);
        }
 
        return make_file(NULL, sb, name, assoc);
index 45ebed04a68dc5192252d271103e5f614b9ac76f..7be65e9481a3ab491becadbb31c877a4d226a8d9 100644 (file)
@@ -130,19 +130,14 @@ struct file_class {
        void (*free_content)(struct file *file);
 };
 
-extern const struct file_class
-file_class, regular_file_class,
-       cdev_file_class, bdev_file_class
-       ;
+extern const struct file_class file_class, cdev_class, bdev_class;
 
 struct file *make_file(const struct file_class *class,
                       struct stat *sb, const char *name, int association);
-struct file *make_regular_file(const struct file_class *class,
-                              struct stat *sb, const char *name, int fd);
-struct file *make_cdev_file(const struct file_class *class,
-                              struct stat *sb, const char *name, int fd);
-struct file *make_bdev_file(const struct file_class *class,
-                           struct stat *sb, const char *name, int fd);
+struct file *make_cdev(const struct file_class *class,
+                      struct stat *sb, const char *name, int fd);
+struct file *make_bdev(const struct file_class *class,
+                      struct stat *sb, const char *name, int fd);
 
 extern struct idcache *username_cache;