Skip to content

Commit

Permalink
config_t config can be too large for the stack
Browse files Browse the repository at this point in the history
zero initialize args_t args in fddev/main.c
  • Loading branch information
llamb-jump committed Jan 31, 2024
1 parent 37ba527 commit 317a8aa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
7 changes: 4 additions & 3 deletions src/app/fdctl/fdctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ typedef struct {
#define ACTIONS_CNT (10UL)
extern action_t ACTIONS[ ACTIONS_CNT ];

config_t fdctl_boot( int * pargc,
char *** pargv,
char const * log_path);
void fdctl_boot( int * pargc,
char *** pargv,
config_t * config,
char const * log_path);

int
main1( int argc,
Expand Down
50 changes: 26 additions & 24 deletions src/app/fdctl/main1.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,73 +78,75 @@ should_colorize( void ) {
return 0;
}

config_t
void
fdctl_boot( int * pargc,
char *** pargv,
config_t * config,
char const * log_path ) {
fd_log_level_core_set( 5 ); /* Don't dump core for FD_LOG_ERR during boot */
fd_log_colorize_set( should_colorize() ); /* Colorize during boot until we can determine from config */

int config_fd = fd_env_strip_cmdline_int( pargc, pargv, "--config-fd", NULL, -1 );

config_t config = {0};
fd_memset( config, 0, sizeof( config_t ) );
char * thread = "";
if( FD_UNLIKELY( config_fd >= 0 ) ) {
copy_config_from_fd( config_fd, &config );
copy_config_from_fd( config_fd, config );
/* tick_per_ns needs to be synchronized across procesess so that they
can coordinate on metrics measurement. */
fd_tempo_set_tick_per_ns( config.tick_per_ns_mu, config.tick_per_ns_sigma );
fd_tempo_set_tick_per_ns( config->tick_per_ns_mu, config->tick_per_ns_sigma );
} else {
config_parse( pargc, pargv, &config );
config.tick_per_ns_mu = fd_tempo_tick_per_ns( &config.tick_per_ns_sigma );
config.log.lock_fd = init_log_memfd();
config.log.log_fd = -1;
config_parse( pargc, pargv, config );
config->tick_per_ns_mu = fd_tempo_tick_per_ns( &config->tick_per_ns_sigma );
config->log.lock_fd = init_log_memfd();
config->log.log_fd = -1;
thread = "main";
if( FD_UNLIKELY( log_path ) )
strncpy( config.log.path, log_path, sizeof( config.log.path ) - 1 );
strncpy( config->log.path, log_path, sizeof( config->log.path ) - 1 );
}

int * log_lock = map_log_memfd( config.log.lock_fd );
int * log_lock = map_log_memfd( config->log.lock_fd );
int pid = getpid1(); /* Need to read /proc since we might be in a PID namespace now */;

log_path = config.log.path;
if( FD_LIKELY( config.log.path[ 0 ]=='\0' ) ) log_path = NULL;
log_path = config->log.path;
if( FD_LIKELY( config->log.path[ 0 ]=='\0' ) ) log_path = NULL;

fd_log_private_boot_custom( log_lock,
0UL,
config.name,
config->name,
0UL, /* Thread ID will be initialized later */
thread, /* Thread will be initialized later */
0UL,
config.hostname,
config->hostname,
fd_log_private_cpu_id_default(),
NULL,
(ulong)pid,
NULL,
(ulong)pid,
config.uid,
config.user,
config->uid,
config->user,
1,
config.log.colorize1,
config.log.level_logfile1,
config.log.level_stderr1,
config.log.level_flush1,
config->log.colorize1,
config->log.level_logfile1,
config->log.level_stderr1,
config->log.level_flush1,
5,
config.log.log_fd,
config->log.log_fd,
log_path );
config.log.log_fd = fd_log_private_logfile_fd();
config->log.log_fd = fd_log_private_logfile_fd();
fd_shmem_private_boot( pargc, pargv );;
fd_tile_private_boot( 0, NULL );
return config;
}

static config_t config;

int
main1( int argc,
char ** _argv ) {
char ** argv = _argv;
argc--; argv++;

config_t config = fdctl_boot( &argc, &argv, NULL );
fdctl_boot( &argc, &argv, &config, NULL );

if( FD_UNLIKELY( !argc ) ) {
help_cmd_fn( NULL, &config );
Expand Down
6 changes: 4 additions & 2 deletions src/app/fddev/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ execve_as_root( int argc,
FD_LOG_ERR(( "execve(sudo) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
}

static config_t config;

int
main( int argc,
char ** _argv ) {
Expand All @@ -92,7 +94,7 @@ main( int argc,

char const * log_path = fd_env_strip_cmdline_cstr( &argc, &argv, "--log-path", NULL, NULL );

config_t config = fdctl_boot( &argc, &argv, log_path );
fdctl_boot( &argc, &argv, &config, log_path );

/* load configuration and command line parsing */
if( FD_UNLIKELY( config.is_live_cluster ) )
Expand Down Expand Up @@ -125,7 +127,7 @@ main( int argc,

if( FD_UNLIKELY( !action ) ) FD_LOG_ERR(( "unknown subcommand `%s`", action_name ));

args_t args;
args_t args = {0};
if( FD_LIKELY( action->args ) ) action->args( &argc, &argv, &args );
if( FD_UNLIKELY( argc ) ) FD_LOG_ERR(( "unknown argument `%s`", argv[ 0 ] ));

Expand Down

0 comments on commit 317a8aa

Please sign in to comment.