+/** CLI command to display a list of CLI sessions. */
+static clib_error_t *
+unix_cli_show_cli_sessions (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ unix_cli_main_t *cm = &unix_cli_main;
+ clib_file_main_t *fm = &file_main;
+ unix_cli_file_t *cf;
+ clib_file_t *uf;
+ vlib_node_t *n;
+
+ vlib_cli_output (vm, "%-5s %-5s %-20s %s", "PNI", "FD", "Name", "Flags");
+
+#define fl(x, y) ( (x) ? toupper((y)) : tolower((y)) )
+ /* *INDENT-OFF* */
+ pool_foreach (cf, cm->cli_file_pool, ({
+ uf = pool_elt_at_index (fm->file_pool, cf->clib_file_index);
+ n = vlib_get_node (vm, cf->process_node_index);
+ vlib_cli_output (vm,
+ "%-5d %-5d %-20v %c%c%c%c%c\n",
+ cf->process_node_index,
+ uf->file_descriptor,
+ n->name,
+ fl (cf->is_interactive, 'i'),
+ fl (cf->is_socket, 's'),
+ fl (cf->line_mode, 'l'),
+ fl (cf->has_epipe, 'p'),
+ fl (cf->ansi_capable, 'a'));
+ }));
+ /* *INDENT-ON* */
+#undef fl
+
+ return 0;
+}
+
+/*?
+ * Displays a summary of all the current CLI sessions.
+ *
+ * Typically used to diagnose connection issues with the CLI
+ * socket.
+ *
+ * @cliexpar
+ * @cliexstart{show cli-sessions}
+ * PNI FD Name Flags
+ * 343 0 unix-cli-stdin IslpA
+ * 344 7 unix-cli-local:20 ISlpA
+ * 346 8 unix-cli-local:21 iSLpa
+ * @cliexend
+
+ * In this example we have the debug console of the running process
+ * on stdin/out, we have an interactive socket session and we also
+ * have a non-interactive socket session.
+ *
+ * Fields:
+ *
+ * - @em PNI: Process node index.
+ * - @em FD: Unix file descriptor.
+ * - @em Name: Name of the session.
+ * - @em Flags: Various flags that describe the state of the session.
+ *
+ * @em Flags have the following meanings; lower-case typically negates
+ * upper-case:
+ *
+ * - @em I Interactive session.
+ * - @em S Connected by socket.
+ * - @em s Not a socket, likely stdin.
+ * - @em L Line-by-line mode.
+ * - @em l Char-by-char mode.
+ * - @em P EPIPE detected on connection; it will close soon.
+ * - @em A ANSI-capable terminal.
+?*/
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (cli_unix_cli_show_cli_sessions, static) = {
+ .path = "show cli-sessions",
+ .short_help = "Show current CLI sessions",
+ .function = unix_cli_show_cli_sessions,
+};
+/* *INDENT-ON* */
+