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 <stdio.h>
9 : #include <unistd.h>
10 : #include <sched.h>
11 : #include <sys/wait.h>
12 :
13 : extern fd_topo_run_tile_t * TILES[];
14 :
15 : void
16 : update_config_for_dev( fd_config_t * config );
17 :
18 : int
19 : agave_main( void * args );
20 :
21 : extern char fd_log_private_path[ 1024 ]; /* empty string on start */
22 :
23 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)
24 :
25 : extern int * fd_log_private_shared_lock;
26 :
27 : static void
28 0 : parent_signal( int sig ) {
29 : /* Same hack as in run.c, see comments there. */
30 0 : int lock = 0;
31 0 : fd_log_private_shared_lock = &lock;
32 :
33 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 ));
34 0 : else FD_LOG_ERR_NOEXIT(( "Received signal %s", fd_io_strsignal( sig ) ));
35 :
36 0 : if( FD_LIKELY( sig==SIGINT ) ) fd_sys_util_exit_group( 128+SIGINT );
37 0 : else fd_sys_util_exit_group( 0 );
38 0 : }
39 :
40 : static void
41 0 : install_parent_signals( void ) {
42 0 : struct sigaction sa = {
43 0 : .sa_handler = parent_signal,
44 0 : .sa_flags = 0,
45 0 : };
46 0 : if( FD_UNLIKELY( sigaction( SIGTERM, &sa, NULL ) ) )
47 0 : FD_LOG_ERR(( "sigaction(SIGTERM) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
48 0 : if( FD_UNLIKELY( sigaction( SIGINT, &sa, NULL ) ) )
49 0 : FD_LOG_ERR(( "sigaction(SIGINT) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
50 0 : }
51 :
52 : void
53 : dev1_cmd_args( int * pargc,
54 : char *** pargv,
55 0 : args_t * args) {
56 0 : char * usage = "usage: dev1 <tile>";
57 0 : if( FD_UNLIKELY( *pargc < 1 ) ) FD_LOG_ERR(( "%s", usage ));
58 :
59 0 : strncpy( args->dev1.tile_name, *pargv[ 0 ], sizeof( args->dev1.tile_name ) - 1 );
60 :
61 0 : (*pargc)--;
62 0 : (*pargv)++;
63 :
64 0 : args->dev1.no_configure = fd_env_strip_cmdline_contains( pargc, pargv, "--no-configure" );
65 0 : }
66 :
67 : void
68 : dev1_cmd_perm( args_t * args,
69 : fd_cap_chk_t * chk,
70 0 : config_t const * config ) {
71 0 : dev_cmd_perm( args, chk, config );
72 0 : }
73 :
74 : void
75 : dev1_cmd_fn( args_t * args,
76 0 : config_t * config ) {
77 0 : if( FD_LIKELY( !args->dev1.no_configure ) ) {
78 0 : args_t configure_args = {
79 0 : .configure.command = CONFIGURE_CMD_INIT,
80 0 : };
81 0 : for( ulong i=0UL; STAGES[i]; i++ )
82 0 : configure_args.configure.stages[ i ] = STAGES[ i ];
83 0 : configure_cmd_fn( &configure_args, config );
84 0 : }
85 :
86 0 : update_config_for_dev( config );
87 0 : run_firedancer_init( config, 1 );
88 :
89 0 : install_parent_signals();
90 :
91 0 : if( FD_UNLIKELY( close( 0 ) ) ) FD_LOG_ERR(( "close(0) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
92 0 : if( FD_UNLIKELY( close( 1 ) ) ) FD_LOG_ERR(( "close(1) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
93 0 : if( FD_UNLIKELY( close( config->log.lock_fd ) ) ) FD_LOG_ERR(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
94 :
95 0 : int result = 0;
96 0 : if( !strcmp( args->dev1.tile_name, "agave" ) ) {
97 0 : result = agave_main( config );
98 0 : } else {
99 0 : ulong tile_id = fd_topo_find_tile( &config->topo, args->dev1.tile_name, 0UL );
100 0 : if( FD_UNLIKELY( tile_id==ULONG_MAX ) ) FD_LOG_ERR(( "tile %s not found in topology", args->dev1.tile_name ));
101 :
102 0 : fd_topo_tile_t * tile = &config->topo.tiles[ tile_id ];
103 :
104 0 : fd_topo_run_tile_t * runner = NULL;
105 0 : for( ulong i=0UL; TILES[ i ]; i++ ) {
106 0 : if( FD_UNLIKELY( !strcmp( TILES[ i ]->name, tile->name ) ) ) {
107 0 : runner = TILES[ i ];
108 0 : break;
109 0 : }
110 0 : }
111 0 : FD_TEST( runner );
112 :
113 0 : fd_topo_run_tile( &config->topo, tile, config->development.sandbox, 1, config->development.core_dump, config->uid, config->gid, -1, NULL, NULL, runner );
114 0 : }
115 :
116 : /* main functions should exit_group and never return, but just in case */
117 0 : fd_sys_util_exit_group( result );
118 0 : }
119 :
120 : action_t fd_action_dev1 = {
121 : .name = "dev1",
122 : .args = dev1_cmd_args,
123 : .fn = dev1_cmd_fn,
124 : .perm = dev_cmd_perm,
125 : .is_local_cluster = 1,
126 : .description = "Start up a single tile"
127 : };
|