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