]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: add stubs for sockets and files of unknown type
authorMasatake YAMATO <yamato@redhat.com>
Thu, 6 May 2021 06:10:49 +0000 (15:10 +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-sock.c [new file with mode: 0644]
misc-utils/lsfd-unkn.c [new file with mode: 0644]
misc-utils/lsfd.c
misc-utils/lsfd.h

index 7ed02a70672b4239e2d05c5fe547b98abc5e82ef..4c980cf707b0c0a501bb5bf8e6241805729d2610 100644 (file)
@@ -254,7 +254,9 @@ lsfd_SOURCES = \
        misc-utils/lsfd.h \
        misc-utils/lsfd-file.c \
        misc-utils/lsfd-cdev.c \
-       misc-utils/lsfd-bdev.c
+       misc-utils/lsfd-bdev.c \
+       misc-utils/lsfd-sock.c \
+       misc-utils/lsfd-unkn.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-sock.c b/misc-utils/lsfd-sock.c
new file mode 100644 (file)
index 0000000..28b561b
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * lsfd-sock.c - handle associations opening socket 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 sock_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, "SOCK"))
+                       err(EXIT_FAILURE, _("failed to add output data"));
+               return true;
+       default:
+               return false;
+       }
+}
+
+const struct file_class sock_class = {
+       .super = &file_class,
+       .size = sizeof(struct file),
+       .fill_column = sock_fill_column,
+       .free_content = NULL,
+};
+
+struct file *make_sock(const struct file_class *class,
+                      struct stat *sb, const char *name, int fd)
+{
+       return make_file(class? class: &sock_class,
+                        sb, name, fd);
+}
diff --git a/misc-utils/lsfd-unkn.c b/misc-utils/lsfd-unkn.c
new file mode 100644 (file)
index 0000000..f736324
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * lsfd-unkn.c - handle associations opening unknown 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 unkn_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, "UNKN"))
+                       err(EXIT_FAILURE, _("failed to add output data"));
+               return true;
+       default:
+               return false;
+       }
+}
+
+const struct file_class unkn_class = {
+       .super = &file_class,
+       .size = sizeof(struct file),
+       .fill_column = unkn_fill_column,
+       .free_content = NULL,
+};
+
+struct file *make_unkn(const struct file_class *class,
+                      struct stat *sb, const char *name, int fd)
+{
+       return make_file(class? class: &unkn_class,
+                        sb, name, fd);
+}
index 73fb7c49a93e761874d33cb47ba794722b7ee4e2..5a8b222bd63f7689e077fd0ba813c23e9ec5675d 100644 (file)
@@ -332,9 +332,16 @@ static struct file *collect_file(struct stat *sb, char *name, int assoc)
                return make_cdev(NULL, sb, name, assoc);
        case S_IFBLK:
                return make_bdev(NULL, sb, name, assoc);
+       case S_IFSOCK:
+               return make_sock(NULL, sb, name, assoc);
+       case S_IFLNK:
+       case S_IFREG:
+       case S_IFIFO:
+       case S_IFDIR:
+               return make_file(NULL, sb, name, assoc);
+       default:
+               return make_unkn(NULL, sb, name, assoc);
        }
-
-       return make_file(NULL, sb, name, assoc);
 }
 
 static void read_fdinfo(struct file *file, FILE *fdinfo)
index 7be65e9481a3ab491becadbb31c877a4d226a8d9..88a5fbf5ce477d6bc57e4d98d77262812ced9d28 100644 (file)
@@ -130,7 +130,7 @@ struct file_class {
        void (*free_content)(struct file *file);
 };
 
-extern const struct file_class file_class, cdev_class, bdev_class;
+extern const struct file_class file_class, cdev_class, bdev_class, sock_class, unkn_class;
 
 struct file *make_file(const struct file_class *class,
                       struct stat *sb, const char *name, int association);
@@ -138,6 +138,10 @@ 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);
+struct file *make_sock(const struct file_class *class,
+                      struct stat *sb, const char *name, int fd);
+struct file *make_unkn(const struct file_class *class,
+                      struct stat *sb, const char *name, int fd);
 
 extern struct idcache *username_cache;