Line data Source code
1 : #ifndef HEADER_fd_src_app_shared_commands_configure_configure_h 2 : #define HEADER_fd_src_app_shared_commands_configure_configure_h 3 : 4 : #include "../../../platform/fd_cap_chk.h" 5 : #include "../../fd_config.h" 6 : #include "../../fd_action.h" 7 : 8 : #include <stdarg.h> 9 : 10 0 : #define CONFIGURE_NR_OPEN_FILES (1024000U) 11 : 12 : enum { 13 : CONFIGURE_NOT_CONFIGURED, 14 : CONFIGURE_PARTIALLY_CONFIGURED, 15 : CONFIGURE_OK, 16 : }; 17 : 18 : typedef struct { 19 : int result; 20 : char message[ 256 ]; 21 : } configure_result_t; 22 : 23 0 : #define CHECK(x) do { \ 24 0 : configure_result_t result = (x); \ 25 0 : if( FD_UNLIKELY( result.result != CONFIGURE_OK ) ) { \ 26 0 : return result; \ 27 0 : } \ 28 0 : } while( 0 ) 29 : 30 0 : #define NOT_CONFIGURED(...) do { \ 31 0 : configure_result_t result; \ 32 0 : result.result = CONFIGURE_NOT_CONFIGURED; \ 33 0 : FD_TEST( fd_cstr_printf_check( result.message, \ 34 0 : sizeof( result.message ), \ 35 0 : NULL, \ 36 0 : __VA_ARGS__ ) ); \ 37 0 : return result; \ 38 0 : } while( 0 ) 39 : 40 0 : #define PARTIALLY_CONFIGURED(...) do { \ 41 0 : configure_result_t result; \ 42 0 : result.result = CONFIGURE_PARTIALLY_CONFIGURED; \ 43 0 : FD_TEST( fd_cstr_printf_check( result.message, \ 44 0 : sizeof( result.message ), \ 45 0 : NULL, \ 46 0 : __VA_ARGS__ ) ); \ 47 0 : return result; \ 48 0 : } while( 0 ) 49 : 50 0 : #define CONFIGURE_OK() do { \ 51 0 : configure_result_t result; \ 52 0 : result.result = CONFIGURE_OK; \ 53 0 : result.message[ 0 ] = '\0'; \ 54 0 : return result; \ 55 0 : } while( 0 ) 56 : 57 : typedef struct configure_stage { 58 : const char * name; 59 : int always_recreate; 60 : int (*enabled) ( config_t const * config ); 61 : void (*init_perm)( fd_cap_chk_t * chk, config_t const * config ); 62 : void (*fini_perm)( fd_cap_chk_t * chk, config_t const * config ); 63 : void (*init) ( config_t const * config ); 64 : void (*fini) ( config_t const * config, int pre_init ); 65 : configure_result_t (*check) ( config_t const * config ); 66 : } configure_stage_t; 67 : 68 : extern configure_stage_t fd_cfg_stage_hugetlbfs; 69 : extern configure_stage_t fd_cfg_stage_sysctl; 70 : extern configure_stage_t fd_cfg_stage_hyperthreads; 71 : extern configure_stage_t fd_cfg_stage_ethtool_channels; 72 : extern configure_stage_t fd_cfg_stage_ethtool_gro; 73 : extern configure_stage_t fd_cfg_stage_ethtool_loopback; 74 : 75 : extern configure_stage_t * STAGES[]; 76 : 77 : typedef enum { 78 : CONFIGURE_CMD_INIT, 79 : CONFIGURE_CMD_CHECK, 80 : CONFIGURE_CMD_FINI, 81 : } configure_cmd_t; 82 : 83 : typedef struct { 84 : configure_cmd_t command; 85 : configure_stage_t ** stages; 86 : } configure_args_t; 87 : 88 : /* Checks if a directory exists and is configured with the given uid, 89 : gid, and access mode. */ 90 : configure_result_t 91 : check_dir( const char * path, 92 : uint uid, 93 : uint gid, 94 : uint mode ); 95 : 96 : /* Checks if a file exists and is configured with the given uid, gid, 97 : and access mode. */ 98 : configure_result_t 99 : check_file( const char * path, 100 : uint uid, 101 : uint gid, 102 : uint mode ); 103 : 104 : int 105 : configure_stage( configure_stage_t * stage, 106 : configure_cmd_t command, 107 : config_t const * config ); 108 : 109 : void configure_cmd_args( int * pargc, char *** pargv, args_t * args ); 110 : void configure_cmd_perm( args_t * args, fd_cap_chk_t * chk, config_t const * config ); 111 : void configure_cmd_fn ( args_t * args, config_t * config ); 112 : 113 : extern action_t fd_action_configure; 114 : 115 : #endif /* HEADER_fd_src_app_shared_commands_configure_configure_h */