Line data Source code
1 : #define _GNU_SOURCE
2 : #include "../platform/fd_sys_util.h"
3 : #include "../shared/commands/configure/configure.h"
4 : #include "../shared/commands/run/run.h"
5 : #include "../shared_dev/commands/dev.h"
6 :
7 : #include <errno.h>
8 : #include <unistd.h>
9 : #include <sched.h>
10 : #include <sys/wait.h>
11 :
12 : extern fd_topo_run_tile_t * TILES[];
13 :
14 : void
15 : update_config_for_dev( fd_config_t * config );
16 :
17 : int
18 : agave_main( void * args );
19 :
20 : extern char fd_log_private_path[ 1024 ]; /* empty string on start */
21 :
22 0 : #define FD_LOG_ERR_NOEXIT(a) do { long _fd_log_msg_now = fd_log_wallclock(); fd_log_private_1( 4, _fd_log_msg_now, __FILE__, __LINE__, __func__, fd_log_private_0 a ); } while(0)
23 :
24 : static void
25 0 : parent_signal( int sig ) {
26 0 : if( -1!=fd_log_private_logfile_fd() ) FD_LOG_ERR_NOEXIT(( "Received signal %s\nLog at \"%s\"", fd_io_strsignal( sig ), fd_log_private_path ));
27 0 : else FD_LOG_ERR_NOEXIT(( "Received signal %s", fd_io_strsignal( sig ) ));
28 :
29 0 : if( FD_LIKELY( sig==SIGINT ) ) fd_sys_util_exit_group( 128+SIGINT );
30 0 : else fd_sys_util_exit_group( 0 );
31 0 : }
32 :
33 : static void
34 0 : install_parent_signals( void ) {
35 0 : struct sigaction sa = {
36 0 : .sa_handler = parent_signal,
37 0 : .sa_flags = 0,
38 0 : };
39 0 : if( FD_UNLIKELY( sigaction( SIGTERM, &sa, NULL ) ) )
40 0 : FD_LOG_ERR(( "sigaction(SIGTERM) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
41 0 : if( FD_UNLIKELY( sigaction( SIGINT, &sa, NULL ) ) )
42 0 : FD_LOG_ERR(( "sigaction(SIGINT) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
43 0 : }
44 :
45 : void
46 : dev1_cmd_args( int * pargc,
47 : char *** pargv,
48 0 : args_t * args) {
49 0 : char * usage = "usage: dev1 <tile>";
50 0 : if( FD_UNLIKELY( *pargc < 1 ) ) FD_LOG_ERR(( "%s", usage ));
51 :
52 0 : fd_cstr_ncpy( args->dev1.tile_name, *pargv[ 0 ], sizeof( args->dev1.tile_name ) );
53 :
54 0 : (*pargc)--;
55 0 : (*pargv)++;
56 :
57 0 : args->dev1.no_configure = fd_env_strip_cmdline_contains( pargc, pargv, "--no-configure" );
58 0 : }
59 :
60 : void
61 : dev1_cmd_perm( args_t * args,
62 : fd_cap_chk_t * chk,
63 0 : config_t const * config ) {
64 0 : dev_cmd_perm( args, chk, config );
65 0 : }
66 :
67 : void
68 : dev1_cmd_fn( args_t * args,
69 0 : config_t * config ) {
70 0 : if( FD_LIKELY( !args->dev1.no_configure ) ) {
71 0 : args_t configure_args = {
72 0 : .configure.command = CONFIGURE_CMD_INIT,
73 0 : };
74 0 : for( ulong i=0UL; STAGES[i]; i++ )
75 0 : configure_args.configure.stages[ i ] = STAGES[ i ];
76 0 : configure_cmd_fn( &configure_args, config );
77 0 : }
78 :
79 0 : update_config_for_dev( config );
80 0 : run_firedancer_init( config, 1, 0 );
81 :
82 0 : install_parent_signals();
83 :
84 0 : if( FD_UNLIKELY( close( 0 ) ) ) FD_LOG_ERR(( "close(0) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
85 0 : if( FD_UNLIKELY( close( 1 ) ) ) FD_LOG_ERR(( "close(1) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
86 :
87 0 : int result = 0;
88 0 : if( !strcmp( args->dev1.tile_name, "agave" ) ) {
89 0 : result = agave_main( config );
90 0 : } else {
91 0 : ulong tile_id = fd_topo_find_tile( &config->topo, args->dev1.tile_name, 0UL );
92 0 : if( FD_UNLIKELY( tile_id==ULONG_MAX ) ) FD_LOG_ERR(( "tile %s not found in topology", args->dev1.tile_name ));
93 :
94 0 : fd_topo_tile_t * tile = &config->topo.tiles[ tile_id ];
95 :
96 0 : fd_topo_run_tile_t * runner = NULL;
97 0 : for( ulong i=0UL; TILES[ i ]; i++ ) {
98 0 : if( FD_UNLIKELY( !strcmp( TILES[ i ]->name, tile->name ) ) ) {
99 0 : runner = TILES[ i ];
100 0 : break;
101 0 : }
102 0 : }
103 0 : FD_TEST( runner );
104 :
105 0 : fd_topo_run_tile( &config->topo, tile, config->development.sandbox, 1, config->development.core_dump_level, config->uid, config->gid, -1, runner );
106 0 : }
107 :
108 0 : fd_sys_util_exit_group( result );
109 0 : }
110 :
111 : action_t fd_action_dev1 = {
112 : .name = "dev1",
113 : .args = dev1_cmd_args,
114 : .fn = dev1_cmd_fn,
115 : .perm = dev_cmd_perm,
116 : .is_local_cluster = 1,
117 : .description = "Start up a single tile"
118 : };
|