LCOV - code coverage report
Current view: top level - app/shared/commands - ps.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 25 0.0 %
Date: 2026-08-14 04:54:57 Functions: 0 3 0.0 %

          Line data    Source code
       1             : #define _GNU_SOURCE
       2             : #include "../fd_config.h"
       3             : #include "../fd_action.h"
       4             : #include "../fd_bootinfo.h"
       5             : 
       6             : #include <errno.h>
       7             : #include <stdio.h>
       8             : #include <unistd.h>
       9             : 
      10             : 
      11             : void
      12             : ps_cmd_args( int *    pargc,
      13             :              char *** pargv,
      14           0 :              args_t * args ) {
      15           0 :   args->ps.clean = fd_env_strip_cmdline_contains( pargc, pargv, "--clean" );
      16           0 : }
      17             : 
      18             : void
      19             : ps_cmd_fn( args_t *   args,
      20           0 :            config_t * config FD_PARAM_UNUSED ) {
      21           0 :   fd_bootinfo_instance_t instances[ FD_BOOTINFO_INSTANCE_MAX ];
      22           0 :   ulong cnt = fd_bootinfo_discover( instances, FD_BOOTINFO_INSTANCE_MAX );
      23             : 
      24           0 :   fd_bootinfo_print( instances, cnt );
      25             : 
      26           0 :   if( FD_UNLIKELY( args->ps.clean ) ) {
      27           0 :     for( ulong i=0UL; i<cnt; i++ ) {
      28           0 :       if( FD_LIKELY( instances[ i ].live ) ) continue;
      29           0 :       char const * suffix[ 2 ] = { "bootinfo", "config" };
      30           0 :       for( ulong j=0UL; j<2UL; j++ ) {
      31           0 :         char path[ PATH_MAX ];
      32           0 :         FD_TEST( fd_cstr_printf_check( path, sizeof(path), NULL, "%s/%s.%s", instances[ i ].mount_path, instances[ i ].info.name, suffix[ j ] ) );
      33           0 :         if( FD_UNLIKELY( -1==unlink( path ) ) ) {
      34           0 :           if( FD_UNLIKELY( errno!=ENOENT ) ) FD_LOG_WARNING(( "unlink(%s) failed (%i-%s)", path, errno, fd_io_strerror( errno ) ));
      35           0 :         }
      36           0 :         else FD_LOG_STDOUT(( "removed %s\n", path ));
      37           0 :       }
      38           0 :     }
      39           0 :   }
      40           0 : }
      41             : 
      42             : static void
      43           0 : ps_args_help( fd_action_help_t * help ) {
      44             :   fd_action_help_arg( help, "--clean", NULL, "Remove descriptors of validators that are no longer running.  Only\n"
      45           0 :                                              "provably stale descriptors are removed, never live ones" );
      46           0 : }
      47             : 
      48             : action_t fd_action_ps = {
      49             :   .name           = "ps",
      50             :   .args           = ps_cmd_args,
      51             :   .fn             = ps_cmd_fn,
      52             :   .require_config = 0,
      53             :   .perm           = NULL,
      54             :   .is_diagnostic  = 1,
      55             :   .description    = "List validators running on this host",
      56             :   .detail         = "Lists validator instances discovered on this host, live or stale.  A\n"
      57             :                     "stale entry means a validator was stopped or crashed without cleaning up.\n",
      58             :   .usage          = "ps [--clean]",
      59             :   .args_help      = ps_args_help,
      60             : };

Generated by: LCOV version 1.14