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

Generated by: LCOV version 1.14