LCOV - code coverage report
Current view: top level - app/shared/commands/run - run1.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 55 0.0 %
Date: 2025-03-20 12:08:36 Functions: 0 3 0.0 %

          Line data    Source code
       1             : #define _GNU_SOURCE
       2             : #include "run.h"
       3             : 
       4             : #include "../../../../util/tile/fd_tile_private.h"
       5             : 
       6             : #include <sched.h>
       7             : #include <stdlib.h> /* strtoul */
       8             : #include <errno.h>
       9             : #include <unistd.h>
      10             : #include <sys/wait.h>
      11             : 
      12             : #define NAME "run1"
      13             : 
      14             : fd_topo_run_tile_t
      15             : fdctl_tile_run( fd_topo_tile_t const * tile );
      16             : 
      17             : void
      18             : run1_cmd_args( int *    pargc,
      19             :                char *** pargv,
      20           0 :                args_t * args) {
      21           0 :   char * usage = "usage: run1 <tile-name> <kind-id>";
      22           0 :   if( FD_UNLIKELY( *pargc < 2 ) ) FD_LOG_ERR(( "%s", usage ));
      23             : 
      24           0 :   args->run1.pipe_fd  = fd_env_strip_cmdline_int( pargc, pargv, "--pipe-fd", NULL, -1 );
      25           0 :   strncpy( args->run1.tile_name, **pargv, sizeof( args->run1.tile_name ) - 1 );
      26             : 
      27           0 :   (*pargc)--;
      28           0 :   (*pargv)++;
      29             : 
      30           0 :   char * endptr;
      31           0 :   ulong kind_id = strtoul( **pargv, &endptr, 10 );
      32           0 :   if( FD_UNLIKELY( *endptr!='\0' || kind_id==ULONG_MAX ) ) FD_LOG_ERR(( "invalid tile-id provided `%s`", **pargv ));
      33           0 :   args->run1.kind_id = kind_id;
      34             : 
      35           0 :   (*pargc)--;
      36           0 :   (*pargv)++;
      37           0 : }
      38             : 
      39             : extern int * fd_log_private_shared_lock;
      40             : 
      41             : typedef struct {
      42             :   config_t *       config;
      43             :   fd_topo_tile_t * tile;
      44             :   int              pipefd;
      45             : } tile_main_args_t;
      46             : 
      47             : static int
      48           0 : tile_main( void * _args ) {
      49           0 :   tile_main_args_t * args = (tile_main_args_t *)_args;
      50             : 
      51           0 :   volatile int * wait = NULL;
      52           0 :   volatile int * debug = NULL;
      53           0 :   if( FD_UNLIKELY( args->config->development.debug_tile ) ) {
      54           0 :     if( FD_UNLIKELY( args->tile->id==args->config->development.debug_tile-1 ) ) *debug = fd_log_private_shared_lock[1];
      55           0 :     else *wait = fd_log_private_shared_lock[1];
      56           0 :   }
      57             : 
      58           0 :   fd_topo_run_tile_t run_tile = fdctl_tile_run( args->tile );
      59           0 :   fd_topo_run_tile( &args->config->topo, args->tile, args->config->development.sandbox, 0, args->config->development.core_dump, args->config->uid, args->config->gid, args->pipefd, wait, debug, &run_tile );
      60           0 :   return 0;
      61           0 : }
      62             : 
      63             : void
      64             : run1_cmd_fn( args_t *   args,
      65           0 :              config_t * config ) {
      66           0 :   ulong pid = fd_sandbox_getpid(); /* Need to read /proc again.. we got a new PID from clone */
      67           0 :   fd_log_private_tid_set( pid );
      68             : 
      69           0 :   ulong tile_id = fd_topo_find_tile( &config->topo, args->run1.tile_name, args->run1.kind_id );
      70           0 :   if( FD_UNLIKELY( tile_id==ULONG_MAX ) ) FD_LOG_ERR(( "tile %s:%lu not found", args->run1.tile_name, args->run1.kind_id ));
      71           0 :   fd_topo_tile_t * tile = &config->topo.tiles[ tile_id ];
      72             : 
      73           0 :   char thread_name[ FD_LOG_NAME_MAX ] = {0};
      74           0 :   FD_TEST( fd_cstr_printf_check( thread_name, FD_LOG_NAME_MAX-1UL, NULL, "%s:%lu", tile->name, tile->kind_id ) );
      75           0 :   fd_log_thread_set( thread_name );
      76             : 
      77           0 :   if( FD_UNLIKELY( -1==close( config->log.lock_fd ) ) ) FD_LOG_ERR(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
      78             : 
      79           0 :   FD_CPUSET_DECL( affinity );
      80           0 :   if( FD_UNLIKELY( -1==fd_cpuset_getaffinity( 0, affinity ) ) )
      81           0 :     FD_LOG_ERR(( "fd_cpuset_getaffinity() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
      82           0 :   ulong cpu_idx = fd_cpuset_first( affinity );
      83           0 :         cpu_idx = fd_ulong_if( cpu_idx<FD_TILE_MAX, cpu_idx, ULONG_MAX );
      84             : 
      85           0 :   if( FD_UNLIKELY( cpu_idx==ULONG_MAX ) ) {
      86           0 :     FD_LOG_WARNING(( "unable to find a CPU to run on, using CPU 0" ));
      87           0 :     cpu_idx = 0UL;
      88           0 :   }
      89             : 
      90           0 :   void * stack = fd_topo_tile_stack_join( config->name, tile->name, tile->kind_id );
      91             : 
      92           0 :   tile_main_args_t clone_args = {
      93           0 :     .config      = config,
      94           0 :     .tile        = tile,
      95           0 :     .pipefd      = args->run1.pipe_fd,
      96           0 :   };
      97             : 
      98             :   /* Also clone tiles into PID namespaces so they cannot signal each
      99             :      other or the parent. */
     100           0 :   int flags = config->development.sandbox ? CLONE_NEWPID : 0;
     101           0 :   pid_t clone_pid = clone( tile_main, (uchar *)stack + FD_TILE_PRIVATE_STACK_SZ, flags, &clone_args );
     102           0 :   if( FD_UNLIKELY( clone_pid<0 ) ) FD_LOG_ERR(( "clone() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
     103           0 : }

Generated by: LCOV version 1.14