};
struct anon_ops {
+ const char *class;
char * (*get_name)(struct unkn *);
void (*init)(struct unkn *);
void (*free)(struct unkn *);
static struct anon_ops anon_generic_ops;
static struct anon_ops anon_pidfd_ops;
+static char * anon_get_class(struct unkn *unkn)
+{
+ char *name;
+
+ if (unkn->anon_ops->class)
+ return strdup(unkn->anon_ops->class);
+
+ /* See unkn_init_content() */
+ name = ((struct file *)unkn)->name + 11;
+ /* Does it have the form anon_inode:[class]? */
+ if (*name == '[') {
+ size_t len = strlen(name + 1);
+ if (*(name + 1 + len - 1) == ']')
+ return strndup(name + 1, len - 1);
+ }
+
+ return strdup(name);
+}
+
static bool unkn_fill_column(struct proc *proc __attribute__((__unused__)),
struct file *file,
struct libscols_line *ln,
if (scols_line_set_data(ln, column_index, "UNKN"))
err(EXIT_FAILURE, _("failed to add output data"));
return true;
+ case COL_AINODECLASS:
+ if (unkn->anon_ops) {
+ str = anon_get_class(unkn);
+ break;
+ }
+ return false;
case COL_SOURCE:
if (unkn->anon_ops) {
str = strdup("anon_inodefs");
}
static struct anon_ops anon_pidfd_ops = {
+ .class = "pidfd",
.get_name = anon_pidfd_get_name,
.init = anon_pidfd_init,
.free = anon_pidfd_free,
* generic (fallback implementation)
*/
static struct anon_ops anon_generic_ops = {
+ .class = NULL,
.get_name = NULL,
.init = NULL,
.free = NULL,
CAUTION{colon} The names and types of columns are not stable yet.
They may be changed in the future releases.
+AINODECLASS <``string``>::
+Class of anonymous inode.
+
ASSOC <``string``>::
Association between file and process.
/* columns descriptions */
static struct colinfo infos[] = {
+ [COL_AINODECLASS]
+ = { "AINODECLASS",0,SCOLS_FL_RIGHT,SCOLS_JSON_STRING,
+ N_("class of anonymous inode") },
[COL_ASSOC] = { "ASSOC", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING,
N_("association between file and process") },
[COL_BLKDRV] = { "BLKDRV", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING,
* column IDs
*/
enum {
+ COL_AINODECLASS,
COL_ASSOC,
COL_BLKDRV,
COL_CHRDRV,
--- /dev/null
+ 3 UNKN pidfd
+pidfd:ASSOC,TYPE,AINODECLASS: 0
+ 3 UNKN inotify
+inotify:ASSOC,TYPE,AINODECLASS: 0
--- /dev/null
+#!/bin/bash
+#
+# Copyright (C) 2022 Masatake YAMATO <yamato@redhat.com>
+#
+# This file is part of util-linux.
+#
+# This file 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 file is distributed in the hope that it will 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.
+#
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="ainodeclass column"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_LSFD"
+ts_check_test_command "$TS_HELPER_MKFDS"
+
+ts_cd "$TS_OUTDIR"
+
+PID=
+FD=3
+EXPR="(FD == 3)"
+
+{
+ for C in pidfd inotify; do
+ coproc MKFDS { "$TS_HELPER_MKFDS" $C $FD ; }
+ if read -u ${MKFDS[0]} PID; then
+ ${TS_CMD_LSFD} -n -o ASSOC,TYPE,AINODECLASS -p "${PID}" -Q "${EXPR}"
+ echo "$C"':ASSOC,TYPE,AINODECLASS': $?
+
+ kill -CONT ${PID}
+ wait ${MKFDS_PID}
+ fi
+ done
+} > $TS_OUTPUT 2>&1
+
+ts_finalize