]> git.ipfire.org Git - thirdparty/util-linux.git/blob - misc-utils/lsfd-fifo.c
build-sys: release++ (v2.38.1)
[thirdparty/util-linux.git] / misc-utils / lsfd-fifo.c
1 /*
2 * lsfd-fifo.c - handle associations opening fifo objects
3 *
4 * Copyright (C) 2021 Red Hat, Inc. All rights reserved.
5 * Written by Masatake YAMATO <yamato@redhat.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it would be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #include "xalloc.h"
23 #include "nls.h"
24 #include "libsmartcols.h"
25
26 #include "lsfd.h"
27
28 static bool fifo_fill_column(struct proc *proc __attribute__((__unused__)),
29 struct file *file,
30 struct libscols_line *ln,
31 int column_id,
32 size_t column_index)
33 {
34 char *str = NULL;
35
36 switch(column_id) {
37 case COL_TYPE:
38 if (scols_line_set_data(ln, column_index, "FIFO"))
39 err(EXIT_FAILURE, _("failed to add output data"));
40 return true;
41 case COL_SOURCE:
42 if (major(file->stat.st_dev) == 0
43 && strncmp(file->name, "pipe:", 5) == 0) {
44 str = strdup("pipefs");
45 break;
46 }
47 return false;
48 default:
49 return false;
50 }
51
52 if (!str)
53 err(EXIT_FAILURE, _("failed to add output data"));
54 if (scols_line_refer_data(ln, column_index, str))
55 err(EXIT_FAILURE, _("failed to add output data"));
56 return true;
57 }
58
59 const struct file_class fifo_class = {
60 .super = &file_class,
61 .size = sizeof(struct file),
62 .fill_column = fifo_fill_column,
63 .free_content = NULL,
64 };