]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - misc-utils/lsfd-fifo.c
2 * lsfd-fifo.c - handle associations opening fifo objects
4 * Copyright (C) 2021 Red Hat, Inc. All rights reserved.
5 * Written by Masatake YAMATO <yamato@redhat.com>
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.
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.
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
26 struct ipc_endpoint endpoint
;
34 static inline char *fifo_xstrendpoint(struct file
*file
)
37 xasprintf(&str
, "%d,%s,%d%c%c",
38 file
->proc
->pid
, file
->proc
->command
, file
->association
,
39 (file
->mode
& S_IRUSR
)? 'r': '-',
40 (file
->mode
& S_IWUSR
)? 'w': '-');
44 static bool fifo_fill_column(struct proc
*proc
__attribute__((__unused__
)),
46 struct libscols_line
*ln
,
54 if (scols_line_set_data(ln
, column_index
, "FIFO"))
55 err(EXIT_FAILURE
, _("failed to add output data"));
58 if (major(file
->stat
.st_dev
) == 0
59 && strncmp(file
->name
, "pipe:", 5) == 0) {
60 str
= xstrdup("pipefs");
65 struct fifo
*this = (struct fifo
*)file
;
67 foreach_endpoint(e
, this->endpoint
) {
69 struct fifo
*other
= list_entry(e
, struct fifo
, endpoint
.endpoints
);
74 estr
= fifo_xstrendpoint(&other
->file
);
75 xstrappend(&str
, estr
);
87 err(EXIT_FAILURE
, _("failed to add output data"));
88 if (scols_line_refer_data(ln
, column_index
, str
))
89 err(EXIT_FAILURE
, _("failed to add output data"));
93 static unsigned int fifo_get_hash(struct file
*file
)
95 return (unsigned int)(file
->stat
.st_ino
% UINT_MAX
);
98 static bool fifo_is_suitable_ipc(struct ipc
*ipc
, struct file
*file
)
100 return ((struct fifo_ipc
*)ipc
)->ino
== file
->stat
.st_ino
;
103 static const struct ipc_class
*fifo_get_ipc_class(struct file
*file
__attribute__((__unused__
)))
105 static const struct ipc_class fifo_ipc_class
= {
106 .size
= sizeof(struct fifo_ipc
),
107 .get_hash
= fifo_get_hash
,
108 .is_suitable_ipc
= fifo_is_suitable_ipc
,
111 return &fifo_ipc_class
;
114 static void fifo_initialize_content(struct file
*file
)
116 struct fifo
*fifo
= (struct fifo
*)file
;
120 init_endpoint(&fifo
->endpoint
);
125 ipc
= new_ipc(fifo_get_ipc_class(file
));
126 ((struct fifo_ipc
*)ipc
)->ino
= file
->stat
.st_ino
;
128 hash
= fifo_get_hash(file
);
131 add_endpoint(&fifo
->endpoint
, ipc
);
134 const struct file_class fifo_class
= {
135 .super
= &file_class
,
136 .size
= sizeof(struct fifo
),
137 .fill_column
= fifo_fill_column
,
138 .initialize_content
= fifo_initialize_content
,
139 .free_content
= NULL
,
140 .get_ipc_class
= fifo_get_ipc_class
,