]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: add a stub for fifo type
authorMasatake YAMATO <yamato@redhat.com>
Sun, 9 May 2021 02:36:07 +0000 (11:36 +0900)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Oct 2021 09:01:53 +0000 (11:01 +0200)
misc-utils/Makemodule.am
misc-utils/lsfd-fifo.c [new file with mode: 0644]
misc-utils/lsfd.c
misc-utils/lsfd.h

index 4c980cf707b0c0a501bb5bf8e6241805729d2610..403782c24dd5137b850663a791122d2e5c93b3dd 100644 (file)
@@ -256,7 +256,8 @@ lsfd_SOURCES = \
        misc-utils/lsfd-cdev.c \
        misc-utils/lsfd-bdev.c \
        misc-utils/lsfd-sock.c \
-       misc-utils/lsfd-unkn.c
+       misc-utils/lsfd-unkn.c \
+       misc-utils/lsfd-fifo.c
 lsfd_LDADD = $(LDADD) libsmartcols.la libcommon.la
 lsfd_LDFLAGS =  -pthread
 lsfd_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir) -pthread
diff --git a/misc-utils/lsfd-fifo.c b/misc-utils/lsfd-fifo.c
new file mode 100644 (file)
index 0000000..2e858e8
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * lsfd-fifo.c - handle associations opening fifo 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 fifo_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) {
+       case COL_TYPE:
+               if (scols_line_set_data(ln, column_index, "FIFO"))
+                       err(EXIT_FAILURE, _("failed to add output data"));
+               return true;
+       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;
+}
+
+struct file *make_fifo(const struct file_class *class,
+                      struct stat *sb, const char *name, int fd)
+{
+       return make_file(class? class: &fifo_class,
+                        sb, name, fd);
+}
+
+const struct file_class fifo_class = {
+       .super = &file_class,
+       .size = sizeof(struct file),
+       .fill_column = fifo_fill_column,
+       .free_content = NULL,
+};
index f0e61b0d449bceb5f9d1136115a6ae85b8d96451..8204ca486b8eab82351b80bb1dd6fe754b00e61e 100644 (file)
@@ -348,9 +348,10 @@ static struct file *collect_file(struct proc *proc,
                return make_bdev(NULL, sb, name, assoc);
        case S_IFSOCK:
                return make_sock(NULL, sb, name, assoc, proc);
+       case S_IFIFO:
+               return make_fifo(NULL, sb, name, assoc);
        case S_IFLNK:
        case S_IFREG:
-       case S_IFIFO:
        case S_IFDIR:
                return make_file(NULL, sb, name, assoc);
        default:
index 24a63c0048067c704b1ae1f5cecdf3507adf23c0..6f4e5d840d4d7f5a0bbc4f4a89c735e3c03c32b0 100644 (file)
@@ -137,7 +137,7 @@ struct file_class {
        void (*free_content)(struct file *file);
 };
 
-extern const struct file_class file_class, cdev_class, bdev_class, sock_class, unkn_class;
+extern const struct file_class file_class, cdev_class, bdev_class, sock_class, unkn_class, fifo_class;
 
 struct file *make_file(const struct file_class *class,
                       struct stat *sb, const char *name, int association);
@@ -150,6 +150,8 @@ struct file *make_sock(const struct file_class *class,
                       struct proc *proc);
 struct file *make_unkn(const struct file_class *class,
                       struct stat *sb, const char *name, int fd);
+struct file *make_fifo(const struct file_class *class,
+                      struct stat *sb, const char *name, int fd);
 
 /*
  * Name managing