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
#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) {
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);
}
#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) {
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);
}
+++ /dev/null
-/*
- * 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;
-}
(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;
}
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;
const struct file_class file_class = {
.super = NULL,
- .size = 0,
+ .size = sizeof (struct file),
.fill_column = file_fill_column,
.free_content = file_free_content,
};
#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:
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: ®ular_fd_file_class,
- sb, name, fd);
+ return make_file(class? class: ®ular_file_class,
+ sb, name, fd);
}
/*
* 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;
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)
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;
};
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;