]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: purge fd layer
authorMasatake YAMATO <yamato@redhat.com>
Fri, 16 Apr 2021 20:49:58 +0000 (05:49 +0900)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Oct 2021 09:01:53 +0000 (11:01 +0200)
misc-utils/Makemodule.am
misc-utils/lsfd-bdev-file.c [moved from misc-utils/lsfd-bdev-fd-file.c with 75% similarity]
misc-utils/lsfd-cdev-file.c [moved from misc-utils/lsfd-cdev-fd-file.c with 72% similarity]
misc-utils/lsfd-fd-file.c [deleted file]
misc-utils/lsfd-file.c
misc-utils/lsfd-regular-file.c [moved from misc-utils/lsfd-regular-fd-file.c with 69% similarity]
misc-utils/lsfd.c
misc-utils/lsfd.h

index 91e550e8abf12886cfb327576d04d314c47fcc2b..64be038a79d7a87fd11ad6436c241bf578765a91 100644 (file)
@@ -253,10 +253,9 @@ lsfd_SOURCES = \
        misc-utils/lsfd.c \
        misc-utils/lsfd.h \
        misc-utils/lsfd-file.c \
-       misc-utils/lsfd-fd-file.c \
-       misc-utils/lsfd-regular-fd-file.c \
-       misc-utils/lsfd-cdev-fd-file.c \
-       misc-utils/lsfd-bdev-fd-file.c
+       misc-utils/lsfd-regular-file.c \
+       misc-utils/lsfd-cdev-file.c \
+       misc-utils/lsfd-bdev-file.c
 lsfd_LDADD = $(LDADD) libsmartcols.la libcommon.la
 lsfd_LDFLAGS =  -pthread
 lsfd_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir) -pthread
similarity index 75%
rename from misc-utils/lsfd-bdev-fd-file.c
rename to misc-utils/lsfd-bdev-file.c
index 6046f2701df045c361375908fdcf607a0f57a9bb..0c4393df168bca397c36217877ea9dba79088e2e 100644 (file)
 
 #include "lsfd.h"
 
-static bool bdev_fd_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_file_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_fd_file_fill_column(struct proc *proc __attribute__((__unused__
        return true;
 }
 
-const struct file_class bdev_fd_file_class = {
-       .super = &fd_file_class,
-       .size = sizeof(struct fd_file),
-       .fill_column = bdev_fd_file_fill_column,
+const struct file_class bdev_file_class = {
+       .super = &file_class,
+       .size = sizeof(struct file),
+       .fill_column = bdev_file_fill_column,
        .free_content = NULL,
 };
 
-struct file *make_bdev_fd_file(const struct file_class *class,
+struct file *make_bdev_file(const struct file_class *class,
                               struct stat *sb, const char *name, int fd)
 {
-       return make_fd_file(class? class: &bdev_fd_file_class,
-                           sb, name, fd);
+       return make_file(class? class: &bdev_file_class,
+                        sb, name, fd);
 }
similarity index 72%
rename from misc-utils/lsfd-cdev-fd-file.c
rename to misc-utils/lsfd-cdev-file.c
index db8ccd57d6a51bfbb63ceb048b96129ad5ceedb5..1d05dcff4bb461150d3af592b854cc27110fcef4 100644 (file)
 
 #include "lsfd.h"
 
-static bool cdev_fd_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_file_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_fd_file_fill_column(struct proc *proc __attribute__((__unused__
        return true;
 }
 
-const struct file_class cdev_fd_file_class = {
-       .super = &fd_file_class,
-       .size = sizeof (struct fd_file),
-       .fill_column = cdev_fd_file_fill_column,
+const struct file_class cdev_file_class = {
+       .super = &file_class,
+       .size = sizeof (struct file),
+       .fill_column = cdev_file_fill_column,
        .free_content = NULL,
 };
 
-struct file *make_cdev_fd_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)
 {
-       return make_fd_file(class? class: &cdev_fd_file_class,
-                           sb, name, fd);
+       return make_file(class? class: &cdev_file_class,
+                        sb, name, fd);
 }
diff --git a/misc-utils/lsfd-fd-file.c b/misc-utils/lsfd-fd-file.c
deleted file mode 100644 (file)
index eee0ffd..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * lsfd-file.c - handle associations opening file objects
- *
- * Copyright (C) 2021 Red Hat, Inc. All rights reserved.
- * Written by Masatake YAMATO <yamato@redhat.com>
- *
- * 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 fd_file_fill_column(struct proc *proc __attribute__((__unused__)),
-                               struct file *file,
-                               struct libscols_line *ln,
-                               int column_id,
-                               size_t column_index)
-{
-       char *str = NULL;
-       struct fd_file * fd_file =  (struct fd_file *)file;
-
-       switch(column_id) {
-       case COL_FD:
-       case COL_ASSOC:
-               xasprintf(&str, "%d", fd_file->fd);
-               break;
-       default:
-               return false;
-       };
-
-       if (!str)
-               err(EXIT_FAILURE, _("failed to add output data"));
-       if (scols_line_refer_data(ln, column_index, str))
-               err(EXIT_FAILURE, _("failed to add output data"));
-
-       return true;
-}
-
-const struct file_class fd_file_class = {
-       .super = &file_class,
-       .size = sizeof(struct fd_file),
-       .fill_column = fd_file_fill_column,
-       .free_content = NULL,
-};
-
-struct file *make_fd_file(const struct file_class *class,
-                         struct stat *sb, const char *name, int fd)
-{
-       struct file *file = make_file(class? class: &fd_file_class,
-                                     sb, name);
-
-       ((struct fd_file *)(file))->fd = fd;
-
-       return file;
-}
index 82ffa8d317e0a9e88d4e978169d7719407aceea0..d554030210ad687ce026c0505d594287d83a303d 100644 (file)
@@ -83,6 +83,13 @@ static bool file_fill_column(struct proc *proc,
                                               (int)file->stat.st_uid)->name))
                        err(EXIT_FAILURE, _("failed to add output data"));
                return true;
+       case COL_FD:
+               if (file->association < 0)
+                       return false;
+               /* FALL THROUGH */
+       case COL_ASSOC:
+               xasprintf(&str, "%d", file->association);
+               break;
        case COL_INODE:
                xasprintf(&str, "%llu", (unsigned long long)file->stat.st_ino);
                break;
@@ -114,11 +121,15 @@ static void file_free_content(struct file *file)
 }
 
 struct file *make_file(const struct file_class *class,
-                      struct stat *sb, const char *name)
+                      struct stat *sb, const char *name, int association)
 {
-       struct file *file = xcalloc(1, class->size);
+       struct file *file;
+
+       class = class? class: &file_class;
+       file = xcalloc(1, class->size);
 
        file->class = class;
+       file->association = association;
        file->name = xstrdup(name);
        file->stat = *sb;
        return file;
@@ -126,7 +137,7 @@ struct file *make_file(const struct file_class *class,
 
 const struct file_class file_class = {
        .super = NULL,
-       .size = 0,
+       .size = sizeof (struct file),
        .fill_column = file_fill_column,
        .free_content = file_free_content,
 };
similarity index 69%
rename from misc-utils/lsfd-regular-fd-file.c
rename to misc-utils/lsfd-regular-file.c
index 1bcf8962cb07a2c73d48dd54d8b7af70ad0ffe28..0a7cd79904f7d90b346929fd9f5f66d5b317dec3 100644 (file)
 
 #include "lsfd.h"
 
-static bool regular_fd_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 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:
@@ -44,16 +44,16 @@ static bool regular_fd_file_fill_column(struct proc *proc __attribute__((__unuse
        return false;
 }
 
-const struct file_class regular_fd_file_class = {
-       .super = &fd_file_class,
-       .size = sizeof(struct fd_file),
-       .fill_column = regular_fd_file_fill_column,
+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_fd_file(const struct file_class *class,
-                                 struct stat *sb, const char *name, int fd)
+struct file *make_regular_file(const struct file_class *class,
+                              struct stat *sb, const char *name, int fd)
 {
-       return make_fd_file(class? class: &regular_fd_file_class,
-                           sb, name, fd);
+       return make_file(class? class: &regular_file_class,
+                        sb, name, fd);
 }
index c37de3dc6a5e884b0f836ade13f9e8614e1f346f..4c53224e28fb50d07ea79ba242d5413b5a36461d 100644 (file)
@@ -47,7 +47,7 @@
 /*
  * Multi-threading related stuffs
  */
-#define NUM_COLLECTORS 2
+#define NUM_COLLECTORS 1
 static pthread_cond_t  procs_ready = PTHREAD_COND_INITIALIZER;
 static pthread_mutex_t procs_ready_lock = PTHREAD_MUTEX_INITIALIZER;
 
@@ -247,14 +247,14 @@ static struct file *collect_file(int dd, struct dirent *dp)
 
        switch (sb.st_mode & S_IFMT) {
        case S_IFREG:
-               return make_regular_fd_file(NULL, &sb, sym, (int)num);
+               return make_regular_file(NULL, &sb, sym, (int)num);
        case S_IFCHR:
-               return make_cdev_fd_file(NULL, &sb, sym, (int)num);
+               return make_cdev_file(NULL, &sb, sym, (int)num);
        case S_IFBLK:
-               return make_bdev_fd_file(NULL, &sb, sym, (int)num);
+               return make_bdev_file(NULL, &sb, sym, (int)num);
        }
 
-       return make_fd_file(NULL, &sb, sym, (int)num);
+       return make_file(NULL, &sb, sym, (int)num);
 }
 
 static void enqueue_file(struct proc *proc, struct file * file)
index 77363b73f88100296c756b9d38525222c79009d7..896bbf58afda436299987ef3608572e74acda3d5 100644 (file)
@@ -79,15 +79,11 @@ struct proc {
 struct file {
        struct list_head files;
        const struct file_class *class;
+       int association;
        char *name;
        struct stat stat;
 };
 
-struct fd_file {
-       struct file file;
-       int fd;
-};
-
 struct file_class {
        const struct file_class *super;
        size_t size;
@@ -100,20 +96,18 @@ struct file_class {
 };
 
 extern const struct file_class
-file_class, fd_file_class, regular_fd_file_class,
-       cdev_fd_file_class, bdev_fd_file_class
+file_class, regular_file_class,
+       cdev_file_class, bdev_file_class
        ;
 
 struct file *make_file(const struct file_class *class,
-                      struct stat *sb, const char *name);
-struct file *make_fd_file(const struct file_class *class,
-                         struct stat *sb, const char *name, int fd);
-struct file *make_regular_fd_file(const struct file_class *class,
-                                 struct stat *sb, const char *name, int fd);
-struct file *make_cdev_fd_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_bdev_fd_file(const struct file_class *class,
+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);
 
 extern struct idcache *username_cache;