]>
Commit | Line | Data |
---|---|---|
5bced64c MY |
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 __attribute__((__unused__)), | |
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 | default: | |
42 | return false; | |
43 | } | |
44 | ||
45 | if (!str) | |
46 | err(EXIT_FAILURE, _("failed to add output data")); | |
47 | if (scols_line_refer_data(ln, column_index, str)) | |
48 | err(EXIT_FAILURE, _("failed to add output data")); | |
49 | return true; | |
50 | } | |
51 | ||
52 | struct file *make_fifo(const struct file_class *class, | |
53 | struct stat *sb, const char *name, int fd) | |
54 | { | |
55 | return make_file(class? class: &fifo_class, | |
56 | sb, name, fd); | |
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 | }; |