]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: add EVENTFD.ID column
authorMasatake YAMATO <yamato@redhat.com>
Fri, 3 Mar 2023 17:28:04 +0000 (02:28 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Thu, 18 May 2023 18:27:24 +0000 (03:27 +0900)
The files under of /proc/$pid/fdinfo/* provide IDs for eventfd files.
With this change, lsfd extacts the IDs. All eventfd files share the
same inode. So the IDs are useful to distinguish two different
envetfds.

An example output:

  $ ./lsfd -Q '(TYPE == "eventfd")' -o+EVENTFD.ID | head
  COMMAND             PID USER ASSOC MODE    TYPE       SOURCE MNTID INODE NAME   EVENTFD.ID
  gnome-session-b   17113  jet     3  rw- eventfd anon_inodefs    15  1060 id=43          43
  gnome-session-b   17113  jet     4  rw- eventfd anon_inodefs    15  1060 id=44          44
  gnome-session-b   17113  jet     6  rw- eventfd anon_inodefs    15  1060 id=158        158
  gnome-session-b   17113  jet     8  rw- eventfd anon_inodefs    15  1060 id=167        167
  at-spi-bus-laun   17160  jet     3  rw- eventfd anon_inodefs    15  1060 id=341        341
  at-spi-bus-laun   17160  jet     4  rw- eventfd anon_inodefs    15  1060 id=342        342
  at-spi-bus-laun   17160  jet     5  rw- eventfd anon_inodefs    15  1060 id=343        343
  at-spi-bus-laun   17160  jet     9  rw- eventfd anon_inodefs    15  1060 id=344        344
  gvfsd             17169  jet     3  rw- eventfd anon_inodefs    15  1060 id=369        369

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-unkn.c
misc-utils/lsfd.1.adoc
misc-utils/lsfd.c
misc-utils/lsfd.h

index b1e0323c7c55a50713a1b2a042a93ce55f910c20..1e4bf360219c2d4136d305994ca9ff85b93acafd 100644 (file)
@@ -263,6 +263,79 @@ static const struct anon_ops anon_pidfd_ops = {
        .handle_fdinfo = anon_pidfd_handle_fdinfo,
 };
 
+/*
+ * eventfd
+ */
+struct anon_eventfd_data {
+       int id;
+};
+
+static bool anon_eventfd_probe(const char *str)
+{
+       return (strncmp(str, "[eventfd]", 9) == 0);
+}
+
+static char *anon_eventfd_get_name(struct unkn *unkn)
+{
+       char *str = NULL;
+       struct anon_eventfd_data *data = (struct anon_eventfd_data *)unkn->anon_data;
+
+       xasprintf(&str, "id=%d", data->id);
+       return str;
+}
+
+static void anon_eventfd_init(struct unkn *unkn)
+{
+       unkn->anon_data = xcalloc(1, sizeof(struct anon_eventfd_data));
+}
+
+static void anon_eventfd_free(struct unkn *unkn)
+{
+       free(unkn->anon_data);
+}
+
+static int anon_eventfd_handle_fdinfo(struct unkn *unkn, const char *key, const char *value)
+{
+       if (strcmp(key, "eventfd-id") == 0) {
+               int64_t id;
+
+               int rc = ul_strtos64(value, &id, 10);
+               if (rc < 0)
+                       return 0;
+               ((struct anon_eventfd_data *)unkn->anon_data)->id = (int)id;
+               return 1;
+       }
+       return 0;
+}
+
+static bool anon_eventfd_fill_column(struct proc *proc  __attribute__((__unused__)),
+                                    struct unkn *unkn,
+                                    struct libscols_line *ln __attribute__((__unused__)),
+                                    int column_id,
+                                    size_t column_index __attribute__((__unused__)),
+                                    char **str)
+{
+       struct anon_eventfd_data *data = (struct anon_eventfd_data *)unkn->anon_data;
+
+       switch(column_id) {
+       case COL_EVENTFD_ID:
+               xasprintf(str, "%d", data->id);
+               return true;
+       default:
+               return false;
+       }
+}
+
+static const struct anon_ops anon_eventfd_ops = {
+       .class = "eventfd",
+       .probe = anon_eventfd_probe,
+       .get_name = anon_eventfd_get_name,
+       .fill_column = anon_eventfd_fill_column,
+       .init = anon_eventfd_init,
+       .free = anon_eventfd_free,
+       .handle_fdinfo = anon_eventfd_handle_fdinfo,
+};
+
 /*
  * generic (fallback implementation)
  */
@@ -277,6 +350,7 @@ static const struct anon_ops anon_generic_ops = {
 
 static const struct anon_ops *anon_ops[] = {
        &anon_pidfd_ops,
+       &anon_eventfd_ops,
 };
 
 static const struct anon_ops *anon_probe(const char *str)
index cbf50f0dd3c367a3e52ffb9f568db32013c4a778..d389b2876a327ca15b9529cf39afee184b84cc15 100644 (file)
@@ -160,6 +160,9 @@ write mode of the endpoint.
 *lsfd* scans; *lsfd* may miss some endpoints
 if you limits the processes with *-p* option.
 
+EVENTFD.ID <``number``>::
+Eventfd ID.
+
 FD <``number``>::
 File descriptor for the file.
 
@@ -219,6 +222,9 @@ Cooked version of KNAME. It is mostly same as KNAME.
 +
 Some files have special formats and information sources:
 +
+eventfd:::
+id=_EVENTFD.ID_
++
 NETLINK:::
 protocol=_NETLINK.PROTOCOL_[ lport=_NETLINK.LPORT_[ group=_NETLINK.GROUPS_]]
 +
index 5a5e37db6a2f03dbc3e409d1c94aff4fa6c5ec28..6d7fd13f3ce82e28f98b3a42025ebf517daffcfd 100644 (file)
@@ -147,6 +147,9 @@ static const struct colinfo infos[] = {
        [COL_ENDPOINTS]        = { "ENDPOINTS",
                                   0,   SCOLS_FL_WRAP,  SCOLS_JSON_STRING,
                                   N_("IPC endpoints information communicated with the fd") },
+       [COL_EVENTFD_ID]       = {"EVENTFD.ID",
+                                  0,   SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER,
+                                  N_("eventfd ID") },
        [COL_FLAGS]            = { "FLAGS",
                                   0,   SCOLS_FL_RIGHT, SCOLS_JSON_STRING,
                                   N_("flags specified when opening the file") },
index ea1c34242f64683ba88f833403da842add7656d0..aec2c7a57ed932fe57efae292cba019fb7130523 100644 (file)
@@ -46,6 +46,7 @@ enum {
        COL_DEV,
        COL_DEVTYPE,
        COL_ENDPOINTS,
+       COL_EVENTFD_ID,
        COL_FD,
        COL_FLAGS,
        COL_INODE,